library(knitr)
library(semPlot)
library(tidyverse)
#### Dados
# Ative o lavaan
library(lavaan)
# Cria uma matriz de cov
wisc4.cov <- lower2full(c(8.29,5.37,9.06,2.83,4.44,8.35,2.83,3.32,3.36,8.88,5.50,
6.66,4.20,3.43,9.18,6.18,6.73,4.01,3.33,6.77,9.12,3.52,3.77,3.19,2.75,3.88,4.05,
8.88,3.79,4.50,3.72,3.39,4.53,4.70,4.54,8.94,2.30,2.67,2.40,2.38,2.06,2.59,2.65,
2.83,8.76,3.06,4.04,3.70,2.79,3.59,3.67,3.44,4.20,4.53,9.73))
# Cria veter de DP's
wisc4.sd <- c(2.88,3.01,2.89,2.98,3.03,3.02,2.98,2.99,2.96,3.12)
# Nome das variáveos
var_names <- c("Comprehension", "Information", "Matrix.Reasoning", "Picture.Concepts",
"Similarities", "Vocabulary", "Digit.Span", "Letter.Number", "Coding", "Symbol.Search")
# Nomea as colunas e linhas da matriz de cov e vetro de SD's
colnames(wisc4.cov) <- var_names
rownames(wisc4.cov) <- var_names
names(wisc4.sd) <- var_names
# Converte matriz de covariâncias em correlação
wisc4.cov %>% cov2cor() %>% kable(digits = 2)
Comprehension | Information | Matrix.Reasoning | Picture.Concepts | Similarities | Vocabulary | Digit.Span | Letter.Number | Coding | Symbol.Search | |
---|---|---|---|---|---|---|---|---|---|---|
Comprehension | 1.00 | 0.62 | 0.34 | 0.33 | 0.63 | 0.71 | 0.41 | 0.44 | 0.27 | 0.34 |
Information | 0.62 | 1.00 | 0.51 | 0.37 | 0.73 | 0.74 | 0.42 | 0.50 | 0.30 | 0.43 |
Matrix.Reasoning | 0.34 | 0.51 | 1.00 | 0.39 | 0.48 | 0.46 | 0.37 | 0.43 | 0.28 | 0.41 |
Picture.Concepts | 0.33 | 0.37 | 0.39 | 1.00 | 0.38 | 0.37 | 0.31 | 0.38 | 0.27 | 0.30 |
Similarities | 0.63 | 0.73 | 0.48 | 0.38 | 1.00 | 0.74 | 0.43 | 0.50 | 0.23 | 0.38 |
Vocabulary | 0.71 | 0.74 | 0.46 | 0.37 | 0.74 | 1.00 | 0.45 | 0.52 | 0.29 | 0.39 |
Digit.Span | 0.41 | 0.42 | 0.37 | 0.31 | 0.43 | 0.45 | 1.00 | 0.51 | 0.30 | 0.37 |
Letter.Number | 0.44 | 0.50 | 0.43 | 0.38 | 0.50 | 0.52 | 0.51 | 1.00 | 0.32 | 0.45 |
Coding | 0.27 | 0.30 | 0.28 | 0.27 | 0.23 | 0.29 | 0.30 | 0.32 | 1.00 | 0.49 |
Symbol.Search | 0.34 | 0.43 | 0.41 | 0.30 | 0.38 | 0.39 | 0.37 | 0.45 | 0.49 | 1.00 |
#### Modelo Hierárq | uico: estimação | do modelo e re | sultados |
wisc4.fourFactor.model <-'
gc =~ Comprehension + Information + Similarities + Vocabulary
gf =~ Matrix.Reasoning + Picture.Concepts
gsm =~ Digit.Span + Letter.Number
gs =~ Coding + Symbol.Search
'
wisc4.fourFactor.fit<-cfa(model=wisc4.fourFactor.model, sample.cov=wisc4.cov, sample.nobs=550)
summary(wisc4.fourFactor.fit, fit.measure=TRUE, standardized=TRUE)
## lavaan (0.5-23.1097) converged normally after 83 iterations
##
## Number of observations 550
##
## Estimator ML
## Minimum Function Test Statistic 52.226
## Degrees of freedom 29
## P-value (Chi-square) 0.005
##
## Model test baseline model:
##
## Minimum Function Test Statistic 2554.487
## Degrees of freedom 45
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.991
## Tucker-Lewis Index (TLI) 0.986
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -12562.889
## Loglikelihood unrestricted model (H1) -12536.776
##
## Number of free parameters 26
## Akaike (AIC) 25177.778
## Bayesian (BIC) 25289.836
## Sample-size adjusted Bayesian (BIC) 25207.301
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.038
## 90 Percent Confidence Interval 0.021 0.055
## P-value RMSEA <= 0.05 0.876
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.020
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gc =~
## Comprehension 1.000 2.193 0.762
## Information 1.160 0.056 20.802 0.000 2.544 0.846
## Similarities 1.166 0.056 20.772 0.000 2.558 0.845
## Vocabulary 1.218 0.056 21.860 0.000 2.670 0.885
## gf =~
## Matrix.Reasnng 1.000 2.000 0.693
## Picture.Cncpts 0.839 0.078 10.775 0.000 1.677 0.563
## gsm =~
## Digit.Span 1.000 1.967 0.661
## Letter.Number 1.172 0.086 13.560 0.000 2.304 0.771
## gs =~
## Coding 1.000 1.779 0.601
## Symbol.Search 1.429 0.139 10.283 0.000 2.542 0.816
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gc ~~
## gf 3.412 0.337 10.130 0.000 0.778 0.778
## gsm 3.302 0.336 9.826 0.000 0.766 0.766
## gs 2.180 0.290 7.511 0.000 0.559 0.559
## gf ~~
## gsm 3.245 0.352 9.220 0.000 0.825 0.825
## gs 2.507 0.329 7.608 0.000 0.705 0.705
## gsm ~~
## gs 2.474 0.324 7.627 0.000 0.707 0.707
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Comprehension 3.467 0.240 14.452 0.000 3.467 0.419
## .Information 2.571 0.203 12.637 0.000 2.571 0.284
## .Similarities 2.622 0.207 12.672 0.000 2.622 0.286
## .Vocabulary 1.973 0.181 10.920 0.000 1.973 0.217
## .Matrix.Reasnng 4.336 0.424 10.224 0.000 4.336 0.520
## .Picture.Cncpts 6.051 0.434 13.944 0.000 6.051 0.683
## .Digit.Span 4.996 0.377 13.239 0.000 4.996 0.564
## .Letter.Number 3.614 0.381 9.499 0.000 3.614 0.405
## .Coding 5.581 0.428 13.053 0.000 5.581 0.638
## .Symbol.Search 3.249 0.573 5.668 0.000 3.249 0.335
## gc 4.808 0.468 10.270 0.000 1.000 1.000
## gf 3.999 0.544 7.353 0.000 1.000 1.000
## gsm 3.868 0.497 7.790 0.000 1.000 1.000
## gs 3.163 0.484 6.535 0.000 1.000 1.000
fitMeasures(wisc4.fourFactor.fit, fit.measures = c("chisq", "df",
"cfi", "tli", "rmsea", "srmr"))
## chisq df cfi tli rmsea srmr
## 52.226 29.000 0.991 0.986 0.038 0.020
NA*gf
para estimar a carga fatorial de gf em gg~~ 1*g
padroniza a variância de g em 1std.lv=TRUE
lavann iria restringir todas as variáveis latentes. Mas não queremos as variâncias dos fatores específicas iguais a 1. Queremos estimala.g~~ 1*g
.wisc4.higherOrder.model<-'
gc =~ Comprehension + Information + Similarities + Vocabulary
gf =~ Matrix.Reasoning + Picture.Concepts
gsm =~ Digit.Span + Letter.Number
gs =~ Coding + Symbol.Search
g=~ NA*gf + gc + gsm + gs
g~~ 1*g
'
wisc4.higherOrder.fit <- cfa(model=wisc4.higherOrder.model, sample.cov=wisc4.cov, sample.nobs=550)
summary(wisc4.higherOrder.fit , fit.measure=TRUE, standardized=TRUE)
## lavaan (0.5-23.1097) converged normally after 60 iterations
##
## Number of observations 550
##
## Estimator ML
## Minimum Function Test Statistic 58.180
## Degrees of freedom 31
## P-value (Chi-square) 0.002
##
## Model test baseline model:
##
## Minimum Function Test Statistic 2554.487
## Degrees of freedom 45
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.989
## Tucker-Lewis Index (TLI) 0.984
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -12565.866
## Loglikelihood unrestricted model (H1) -12536.776
##
## Number of free parameters 24
## Akaike (AIC) 25179.732
## Bayesian (BIC) 25283.170
## Sample-size adjusted Bayesian (BIC) 25206.984
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.040
## 90 Percent Confidence Interval 0.024 0.056
## P-value RMSEA <= 0.05 0.846
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.023
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gc =~
## Comprehension 1.000 2.194 0.763
## Information 1.160 0.056 20.832 0.000 2.545 0.846
## Similarities 1.164 0.056 20.767 0.000 2.555 0.844
## Vocabulary 1.217 0.056 21.882 0.000 2.670 0.885
## gf =~
## Matrix.Reasnng 1.000 1.991 0.690
## Picture.Cncpts 0.846 0.079 10.758 0.000 1.685 0.566
## gsm =~
## Digit.Span 1.000 1.966 0.660
## Letter.Number 1.173 0.087 13.503 0.000 2.306 0.772
## gs =~
## Coding 1.000 1.771 0.599
## Symbol.Search 1.441 0.142 10.149 0.000 2.553 0.819
## g =~
## gf 1.852 0.122 15.182 0.000 0.930 0.930
## gc 1.793 0.112 16.025 0.000 0.817 0.817
## gsm 1.823 0.130 14.074 0.000 0.927 0.927
## gs 1.293 0.133 9.710 0.000 0.730 0.730
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## g 1.000 1.000 1.000
## .Comprehension 3.460 0.240 14.440 0.000 3.460 0.418
## .Information 2.565 0.203 12.614 0.000 2.565 0.284
## .Similarities 2.635 0.208 12.692 0.000 2.635 0.288
## .Vocabulary 1.973 0.181 10.906 0.000 1.973 0.217
## .Matrix.Reasnng 4.372 0.424 10.306 0.000 4.372 0.525
## .Picture.Cncpts 6.025 0.434 13.871 0.000 6.025 0.680
## .Digit.Span 5.000 0.378 13.219 0.000 5.000 0.564
## .Letter.Number 3.608 0.382 9.441 0.000 3.608 0.404
## .Coding 5.606 0.430 13.040 0.000 5.606 0.641
## .Symbol.Search 3.197 0.584 5.473 0.000 3.197 0.329
## gc 1.599 0.226 7.082 0.000 0.332 0.332
## gf 0.534 0.340 1.569 0.117 0.135 0.135
## gsm 0.540 0.241 2.246 0.025 0.140 0.140
## gs 1.467 0.262 5.590 0.000 0.468 0.468
fitMeasures(wisc4.higherOrder.fit , fit.measures = c("chisq", "df",
"cfi", "tli", "rmsea", "srmr"))
## chisq df cfi tli rmsea srmr
## 58.180 31.000 0.989 0.984 0.040 0.023
wisc4.bifactor.model<-'
gc =~ Comprehension + Information + Similarities + Vocabulary
gf =~ a*Matrix.Reasoning + a*Picture.Concepts
gsm =~ b*Digit.Span + b*Letter.Number
gs =~ c*Coding + c*Symbol.Search
g =~ Information + Comprehension + Matrix.Reasoning + Picture.Concepts + Similarities +
Vocabulary + Digit.Span + Letter.Number + Coding + Symbol.Search
'
wisc4.bifactor.fit<-cfa(model=wisc4.bifactor.model, sample.cov=wisc4.cov, sample.nobs=550, std.lv=TRUE, orthogonal=TRUE)
summary(wisc4.bifactor.fit , fit.measure=TRUE, standardized=TRUE)
## lavaan (0.5-23.1097) converged normally after 50 iterations
##
## Number of observations 550
##
## Estimator ML
## Minimum Function Test Statistic 50.833
## Degrees of freedom 28
## P-value (Chi-square) 0.005
##
## Model test baseline model:
##
## Minimum Function Test Statistic 2554.487
## Degrees of freedom 45
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.991
## Tucker-Lewis Index (TLI) 0.985
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -12562.192
## Loglikelihood unrestricted model (H1) -12536.776
##
## Number of free parameters 27
## Akaike (AIC) 25178.385
## Bayesian (BIC) 25294.753
## Sample-size adjusted Bayesian (BIC) 25209.043
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.039
## 90 Percent Confidence Interval 0.021 0.055
## P-value RMSEA <= 0.05 0.864
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.022
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gc =~
## Comprehnsn 1.426 0.131 10.901 0.000 1.426 0.496
## Informatin 1.259 0.127 9.927 0.000 1.259 0.419
## Similarits 1.375 0.128 10.742 0.000 1.375 0.454
## Vocabulary 1.665 0.122 13.697 0.000 1.665 0.552
## gf =~
## Mtrx.Rsnng (a) 0.634 0.221 2.873 0.004 0.634 0.220
## Pctr.Cncpt (a) 0.634 0.221 2.873 0.004 0.634 0.213
## gsm =~
## Digit.Span (b) 0.863 0.164 5.279 0.000 0.863 0.290
## Lettr.Nmbr (b) 0.863 0.164 5.279 0.000 0.863 0.289
## gs =~
## Coding (c) 1.461 0.114 12.824 0.000 1.461 0.494
## Symbl.Srch (c) 1.461 0.114 12.824 0.000 1.461 0.469
## g =~
## Informatin 2.191 0.124 17.682 0.000 2.191 0.728
## Comprehnsn 1.709 0.127 13.499 0.000 1.709 0.594
## Mtrx.Rsnng 1.883 0.121 15.515 0.000 1.883 0.652
## Pctr.Cncpt 1.568 0.132 11.901 0.000 1.568 0.527
## Similarits 2.130 0.126 16.854 0.000 2.130 0.704
## Vocabulary 2.134 0.126 16.954 0.000 2.134 0.707
## Digit.Span 1.792 0.129 13.847 0.000 1.792 0.602
## Lettr.Nmbr 2.113 0.123 17.116 0.000 2.113 0.707
## Coding 1.280 0.133 9.615 0.000 1.280 0.433
## Symbl.Srch 1.865 0.133 14.065 0.000 1.865 0.598
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## gc ~~
## gf 0.000 0.000 0.000
## gsm 0.000 0.000 0.000
## gs 0.000 0.000 0.000
## g 0.000 0.000 0.000
## gf ~~
## gsm 0.000 0.000 0.000
## gs 0.000 0.000 0.000
## g 0.000 0.000 0.000
## gsm ~~
## gs 0.000 0.000 0.000
## g 0.000 0.000 0.000
## gs ~~
## g 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Comprehension 3.323 0.250 13.275 0.000 3.323 0.402
## .Information 2.660 0.202 13.179 0.000 2.660 0.294
## .Similarities 2.737 0.212 12.914 0.000 2.737 0.299
## .Vocabulary 1.777 0.208 8.560 0.000 1.777 0.195
## .Matrix.Reasnng 4.388 0.383 11.450 0.000 4.388 0.526
## .Picture.Cncpts 6.004 0.444 13.534 0.000 6.004 0.677
## .Digit.Span 4.908 0.381 12.890 0.000 4.908 0.554
## .Letter.Number 3.713 0.345 10.751 0.000 3.713 0.416
## .Coding 4.971 0.408 12.174 0.000 4.971 0.568
## .Symbol.Search 4.100 0.391 10.489 0.000 4.100 0.422
## gc 1.000 1.000 1.000
## gf 1.000 1.000 1.000
## gsm 1.000 1.000 1.000
## gs 1.000 1.000 1.000
## g 1.000 1.000 1.000
fitMeasures(wisc4.bifactor.fit , fit.measures = c("chisq", "df",
"cfi", "tli", "rmsea", "srmr"))
## chisq df cfi tli rmsea srmr
## 50.833 28.000 0.991 0.985 0.039 0.022
Beaujean, A. A. (2014). Latent Variable Modeling Using R: A Step-By-Step Guide (Edição: 1.). New York: Routledge.