> # principles and practice of sem, 5th ed. > # rex b. kline, guilford press, 2023 > > # chapter 17, table 17.1, analysis 2 > # 2sls estimation with model-implied instruments > # in a small-sample cfa (n = 103) > > # to avoid the problem that some R packages share the same name > # for different functions, all functions are specified next as > > # package::function > > # which prevents masking, or the default hiding of > # a function with a redundant name from a package used next > > date() [1] "Fri Apr 14 08:39:13 2023" > > v <- R.Version() > print(paste0(v$language, " version ", v$major, ".", + v$minor, " (", v$year, "-", v$month, "-", v$day, ")")) [1] "R version 4.2.3 (2023-03-15)" > > library(lavaan) This is lavaan 0.6-15 lavaan is FREE software! Please report any bugs. > library(MIIVsem) This is MIIVsem 0.5.8 MIIVsem is BETA software! Please report any bugs. > > # get citation information > citation("lavaan", auto = TRUE) To cite package ‘lavaan’ in publications use: Rosseel Y, Jorgensen TD, Rockwood N (2023). _lavaan: Latent Variable Analysis_. R package version 0.6-15, . A BibTeX entry for LaTeX users is @Manual{, title = {lavaan: Latent Variable Analysis}, author = {Yves Rosseel and Terrence D. Jorgensen and Nicholas Rockwood}, year = {2023}, note = {R package version 0.6-15}, url = {https://CRAN.R-project.org/package=lavaan}, } > citation("MIIVsem", auto = TRUE) To cite package ‘MIIVsem’ in publications use: Fisher Z, Bollen K, Gates K, Rönkkö M (2021). _MIIVsem: Model Implied Instrumental Variable (MIIV) Estimation of Structural Equation Models_. R package version 0.5.8, . A BibTeX entry for LaTeX users is @Manual{, title = {MIIVsem: Model Implied Instrumental Variable (MIIV) Estimation of Structural Equation Models}, author = {Zachary Fisher and Kenneth Bollen and Kathleen Gates and Mikko Rönkkö}, year = {2021}, note = {R package version 0.5.8}, url = {https://CRAN.R-project.org/package=MIIVsem}, } > > # input the correlations in lower diagnonal form > sabatelliLower.cor <- ' + 1.000 + .740 1.000 + .265 .422 1.000 + .305 .401 .791 1.000 + .315 .351 .662 .587 1.000 ' > > # name the variables and convert to full correlation matrix > sabatelli.cor <- lavaan::getCov(sabatelliLower.cor, names = c("problems", + "intimacy", "father", "mother", "both")) > > # add the standard deviations and convert to covariances > sabatelli.cov <- lavaan::cor2cov(sabatelli.cor, sds = c(32.936,22.749, + 13.390,13.679,14.382)) > > # display correlations and covariances > > sabatelli.cor problems intimacy father mother both problems 1.000 0.740 0.265 0.305 0.315 intimacy 0.740 1.000 0.422 0.401 0.351 father 0.265 0.422 1.000 0.791 0.662 mother 0.305 0.401 0.791 1.000 0.587 both 0.315 0.351 0.662 0.587 1.000 > sabatelli.cov problems intimacy father mother both problems 1084.7801 554.4532 116.8685 137.4121 149.2109 intimacy 554.4532 517.5170 128.5450 124.7846 114.8388 father 116.8685 128.5450 179.2921 144.8810 127.4846 mother 137.4121 124.7846 144.8810 187.1150 115.4813 both 149.2109 114.8388 127.4846 115.4813 206.8419 > > # specify model in lavaan syntax > > sabatelli.model <- ' + Marital =~ problems + intimacy + FOE =~ father + mother + both ' > > # generate list of model-implied instruments > # for each equation > > MIIVsem::miivs(sabatelli.model) Model Equation Information LHS RHS MIIVs intimacy problems father, mother, both mother father problems, intimacy, both both father problems, intimacy, mother > > # 2sls estimates with sargan test > # over multiple instruments > sabatelli <- MIIVsem::miive(sabatelli.model, sample.cov = sabatelli.cov, + sample.nobs = 103, var.cov = TRUE) > lavaan::summary(sabatelli, rsquare = TRUE) MIIVsem (0.5.8) results Number of observations 103 Number of equations 3 Estimator MIIV-2SLS Standard Errors standard Missing listwise Parameter Estimates: STRUCTURAL COEFFICIENTS: Estimate Std.Err z-value P(>|z|) Sargan df P(Chi) FOE =~ father 1.000 mother 0.899 0.089 10.149 0.000 1.763 2 0.414 both 0.787 0.099 7.935 0.000 3.590 2 0.166 Marital =~ problems 1.000 intimacy 0.805 0.155 5.195 0.000 4.980 2 0.083 INTERCEPTS: Estimate Std.Err z-value P(>|z|) both 0.000 father 0.000 intimacy 0.000 mother 0.000 problems 0.000 VARIANCES: Estimate Std.Err z-value P(>|z|) both 103.301 father 20.856 FOE 158.501 intimacy 50.871 Marital 702.393 mother 54.195 problems 422.427 COVARIANCES: Estimate Std.Err z-value P(>|z|) Marital ~~ FOE 157.495 R-SQUARE: Estimate problems 0.624 intimacy 0.900 father 0.884 mother 0.703 both 0.487 > > # generate residuals in lavaan > # all parameters are specified as fixed > # based on 2SLS estimates, > # next the model is fitted to sample data matrix > # the usual global fit statistics in ml estimation > # may have no meaningful interpretation > > sabatelliFixed.model <- ' + # common factors + Marital =~ 1.0*problems + .805*intimacy + FOE =~ 1.0*father + .899*mother + .787*both + # factor variances, covariances + FOE ~~ 158.501*FOE + Marital ~~ 157.495*FOE + Marital ~~ 702.393*Marital + # indicator error variances + father ~~ 20.856*father + mother ~~ 54.195*mother + both ~~ 103.301*both + problems ~~ 422.427*problems + intimacy ~~ 50.781*intimacy ' > > # fit model with fixed parameters to data > sabatelliFixed <- lavaan::sem(sabatelliFixed.model, sample.cov = sabatelli.cov, + sample.nobs = 103) > > # standardized parameter "estimates" listed > # next are fixed to nonzero constants, and > # standard errors are undefined > lavaan::parameterEstimates(sabatelliFixed) lhs op rhs est se z pvalue ci.lower ci.upper 1 Marital =~ problems 1.000 0 NA NA 1.000 1.000 2 Marital =~ intimacy 0.805 0 NA NA 0.805 0.805 3 FOE =~ father 1.000 0 NA NA 1.000 1.000 4 FOE =~ mother 0.899 0 NA NA 0.899 0.899 5 FOE =~ both 0.787 0 NA NA 0.787 0.787 6 FOE ~~ FOE 158.501 0 NA NA 158.501 158.501 7 Marital ~~ FOE 157.495 0 NA NA 157.495 157.495 8 Marital ~~ Marital 702.393 0 NA NA 702.393 702.393 9 father ~~ father 20.856 0 NA NA 20.856 20.856 10 mother ~~ mother 54.195 0 NA NA 54.195 54.195 11 both ~~ both 103.301 0 NA NA 103.301 103.301 12 problems ~~ problems 422.427 0 NA NA 422.427 422.427 13 intimacy ~~ intimacy 50.781 0 NA NA 50.781 50.781 > > # residuals > lavaan::residuals(sabatelliFixed, type = "raw") $type [1] "raw" $cov prblms intmcy father mother both problems -50.572 intimacy -16.356 6.543 father -41.761 0.514 -1.806 mother -5.510 9.595 0.982 3.003 both 23.814 13.945 1.507 2.219 3.362 > lavaan::residuals(sabatelliFixed, type = "standardized.mplus") $type [1] "standardized.mplus" $cov prblms intmcy father mother both problems -0.338 intimacy -0.180 0.092 father -0.938 0.016 -0.073 mother -0.120 0.293 0.043 0.116 both 0.491 0.412 0.067 0.100 0.118 > lavaan::residuals(sabatelliFixed, type = "cor.bollen") $type [1] "cor.bollen" $cov prblms intmcy father mother both problems 0.000 intimacy -0.010 0.000 father -0.086 0.001 0.000 mother -0.008 0.026 0.003 0.000 both 0.055 0.038 0.006 0.002 0.000