Los Modelos de Ecuaciones Estructurales (SEM) es una técica de análisis de estadística multivariada, que permite analizar patrones complejos de relaciones entre variables, realizar comparaciones entre e intragrupos, y validar modelos teóricos y empíricos.
Holzinger y Swineford realizaron exámenes de habilidad mental a adolescentes de 7° y 8° de dos escuelas (Pasteur y Grand-White).
La base de datos está incluida como paquete en R, e incluye las
siguientes columnas:
* sex: Género (1= male, 2= female)
* x1: Percepción visual
* x2: Juego con cubos
* x3: Juego con pastillas/ espacial
* x4: Comprensión de párrafos
* x5: Completar oraciones
* x6: Saber significados de palabras
* x7: Sumas aceleradas
* x8: Conteo acelerado de puntos
* x9: Discriminación acelerada de mayúsculas rectas y curvas
Se busca identificar las relaciones entre las habilidades visuales (x1, x2, x3), textuales (x4, x5, x6) y velocidades (x7, x8, x9) de los adolescentes.
#install.packages("lavaan")
#install.packages("lavaanPlot")
library(lavaan)
## This is lavaan 0.6-17
## lavaan is FREE software! Please report any bugs.
library(lavaanPlot)
#Lavaan = Latent variable analysis
#Las variables latentes son las variables que no se observan, se infieren
df1 <- HolzingerSwineford1939
summary(df1)
## id sex ageyr agemo
## Min. : 1.0 Min. :1.000 Min. :11 Min. : 0.000
## 1st Qu.: 82.0 1st Qu.:1.000 1st Qu.:12 1st Qu.: 2.000
## Median :163.0 Median :2.000 Median :13 Median : 5.000
## Mean :176.6 Mean :1.515 Mean :13 Mean : 5.375
## 3rd Qu.:272.0 3rd Qu.:2.000 3rd Qu.:14 3rd Qu.: 8.000
## Max. :351.0 Max. :2.000 Max. :16 Max. :11.000
##
## school grade x1 x2
## Grant-White:145 Min. :7.000 Min. :0.6667 Min. :2.250
## Pasteur :156 1st Qu.:7.000 1st Qu.:4.1667 1st Qu.:5.250
## Median :7.000 Median :5.0000 Median :6.000
## Mean :7.477 Mean :4.9358 Mean :6.088
## 3rd Qu.:8.000 3rd Qu.:5.6667 3rd Qu.:6.750
## Max. :8.000 Max. :8.5000 Max. :9.250
## NA's :1
## x3 x4 x5 x6
## Min. :0.250 Min. :0.000 Min. :1.000 Min. :0.1429
## 1st Qu.:1.375 1st Qu.:2.333 1st Qu.:3.500 1st Qu.:1.4286
## Median :2.125 Median :3.000 Median :4.500 Median :2.0000
## Mean :2.250 Mean :3.061 Mean :4.341 Mean :2.1856
## 3rd Qu.:3.125 3rd Qu.:3.667 3rd Qu.:5.250 3rd Qu.:2.7143
## Max. :4.500 Max. :6.333 Max. :7.000 Max. :6.1429
##
## x7 x8 x9
## Min. :1.304 Min. : 3.050 Min. :2.778
## 1st Qu.:3.478 1st Qu.: 4.850 1st Qu.:4.750
## Median :4.087 Median : 5.500 Median :5.417
## Mean :4.186 Mean : 5.527 Mean :5.374
## 3rd Qu.:4.913 3rd Qu.: 6.100 3rd Qu.:6.083
## Max. :7.435 Max. :10.000 Max. :9.250
##
str(df1)
## 'data.frame': 301 obs. of 15 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 11 ...
## $ sex : int 1 2 2 1 2 2 1 2 2 2 ...
## $ ageyr : int 13 13 13 13 12 14 12 12 13 12 ...
## $ agemo : int 1 7 1 2 2 1 1 2 0 5 ...
## $ school: Factor w/ 2 levels "Grant-White",..: 2 2 2 2 2 2 2 2 2 2 ...
## $ grade : int 7 7 7 7 7 7 7 7 7 7 ...
## $ x1 : num 3.33 5.33 4.5 5.33 4.83 ...
## $ x2 : num 7.75 5.25 5.25 7.75 4.75 5 6 6.25 5.75 5.25 ...
## $ x3 : num 0.375 2.125 1.875 3 0.875 ...
## $ x4 : num 2.33 1.67 1 2.67 2.67 ...
## $ x5 : num 5.75 3 1.75 4.5 4 3 6 4.25 5.75 5 ...
## $ x6 : num 1.286 1.286 0.429 2.429 2.571 ...
## $ x7 : num 3.39 3.78 3.26 3 3.7 ...
## $ x8 : num 5.75 6.25 3.9 5.3 6.3 6.65 6.2 5.15 4.65 4.55 ...
## $ x9 : num 6.36 7.92 4.42 4.86 5.92 ...
modelo1 <- ' # Regresiones
# Variables Latentes
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
velocidad =~ x7 + x8 + x9
# Varianza y Covarianzas
visual ~~ textual
textual ~~ velocidad
velocidad ~~ visual
# Intercepto
'
fit <- cfa(modelo1, df1)
summary(fit)
## lavaan 0.6.17 ended normally after 35 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 21
##
## Number of observations 301
##
## Model Test User Model:
##
## Test statistic 85.306
## Degrees of freedom 24
## P-value (Chi-square) 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## visual =~
## x1 1.000
## x2 0.554 0.100 5.554 0.000
## x3 0.729 0.109 6.685 0.000
## textual =~
## x4 1.000
## x5 1.113 0.065 17.014 0.000
## x6 0.926 0.055 16.703 0.000
## velocidad =~
## x7 1.000
## x8 1.180 0.165 7.152 0.000
## x9 1.082 0.151 7.155 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## visual ~~
## textual 0.408 0.074 5.552 0.000
## textual ~~
## velocidad 0.173 0.049 3.518 0.000
## visual ~~
## velocidad 0.262 0.056 4.660 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .x1 0.549 0.114 4.833 0.000
## .x2 1.134 0.102 11.146 0.000
## .x3 0.844 0.091 9.317 0.000
## .x4 0.371 0.048 7.779 0.000
## .x5 0.446 0.058 7.642 0.000
## .x6 0.356 0.043 8.277 0.000
## .x7 0.799 0.081 9.823 0.000
## .x8 0.488 0.074 6.573 0.000
## .x9 0.566 0.071 8.003 0.000
## visual 0.809 0.145 5.564 0.000
## textual 0.979 0.112 8.737 0.000
## velocidad 0.384 0.086 4.451 0.000
lavaanPlot(fit, coef= TRUE, cov=TRUE)
La base de datos contiene distintas mediciones sobre la democracia política e industralización en países en desarrollo durante 1960 y 1965.
La tabla incluye los siguientes datos:
* y1: Calificaciones sobre libertad de prensa en 1960
* y2: Libertad de la oposición política en 1960
* y3: Imparcialidad de elecciones en 1960
* y4: Eficacia de la legislatura electa en 1960
* y5: Calificaciones sobre libertad de prensa en 1965
* y6: Libertad de la oposición política en 1965
* y7: Imparcialidad de elecciones en 1965
* y8: Eficacia de la legislatura electa en 1965
* x1: PIB per cápita en 1960
* x2: Consumo de energía inanimada per cápita en 1960
* x3: Porcentaje de la fuerza laboral en la industria en 1960
df2<- PoliticalDemocracy
modelo2 <- '# Regresiones
Democracia1965 ~ Democracia1960 + Industrialización
Democracia1960~Industrialización
# Variables Latentes
Democracia1960 =~ y1 + y2 + y3 +y4
Democracia1965 =~ y5 + y6 + y7 + y8
Industrialización =~ x1 + x2 + x3
# Varianzas y Covarianzas
# Intercepto'
fit1 <- cfa(modelo2,df2)
summary(fit1)
## lavaan 0.6.17 ended normally after 42 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 25
##
## Number of observations 75
##
## Model Test User Model:
##
## Test statistic 72.462
## Degrees of freedom 41
## P-value (Chi-square) 0.002
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|)
## Democracia1960 =~
## y1 1.000
## y2 1.354 0.175 7.755 0.000
## y3 1.044 0.150 6.961 0.000
## y4 1.300 0.138 9.412 0.000
## Democracia1965 =~
## y5 1.000
## y6 1.258 0.164 7.651 0.000
## y7 1.282 0.158 8.137 0.000
## y8 1.310 0.154 8.529 0.000
## Industrialización =~
## x1 1.000
## x2 2.182 0.139 15.714 0.000
## x3 1.819 0.152 11.956 0.000
##
## Regressions:
## Estimate Std.Err z-value P(>|z|)
## Democracia1965 ~
## Democracia1960 0.864 0.113 7.671 0.000
## Industrialización 0.453 0.220 2.064 0.039
## Democracia1960 ~
## Industrialización 1.474 0.392 3.763 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .y1 1.942 0.395 4.910 0.000
## .y2 6.490 1.185 5.479 0.000
## .y3 5.340 0.943 5.662 0.000
## .y4 2.887 0.610 4.731 0.000
## .y5 2.390 0.447 5.351 0.000
## .y6 4.343 0.796 5.456 0.000
## .y7 3.510 0.668 5.252 0.000
## .y8 2.940 0.586 5.019 0.000
## .x1 0.082 0.020 4.180 0.000
## .x2 0.118 0.070 1.689 0.091
## .x3 0.467 0.090 5.174 0.000
## .Democracia1960 3.872 0.893 4.338 0.000
## .Democracia1965 0.115 0.200 0.575 0.565
## Industrialización 0.448 0.087 5.169 0.000
lavaanPlot(fit1, coef= TRUE,cov = TRUE)