## Load simulated Widaman dataset
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
library(lavaan)
## This is lavaan 0.6-19
## lavaan is FREE software! Please report any bugs.
ModelData <-
read.table("widmantryingdontmindlast30days.txt", header = TRUE) ;
RegModel<-"
! regression
Lst30Dys ~ B*DontMind + A*Trying
! Residuals, Variances and Covariances
Lst30Dys ~~ E*Lst30Dys
DontMind ~~ VD*DontMind
Trying ~~ VT*Trying
DontMind ~~ CTD*Trying
! Means & Intercepts
Lst30Dys~I*1
Trying~MT*1
DontMind~MD*1
";
regresult<-lavaan(RegModel, data=ModelData, fixed.x=FALSE, missing="FIML");
summary(regresult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 21 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 661
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 323.461
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -3268.407
## Loglikelihood unrestricted model (H1) -3268.407
##
## Akaike (AIC) 6554.814
## Bayesian (BIC) 6595.258
## Sample-size adjusted Bayesian (SABIC) 6566.683
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Lst30Dys ~
## DontMind (B) 0.311 0.028 11.049 0.000 0.311 0.378
## Trying (A) -0.276 0.031 -8.816 0.000 -0.276 -0.302
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## DontMind ~~
## Trying (CTD) -0.682 0.084 -8.123 0.000 -0.682 -0.333
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Lst30Dys (I) 1.826 0.161 11.351 0.000 1.826 1.471
## Trying (MT) 3.626 0.053 68.751 0.000 3.626 2.674
## DontMind (MD) 2.670 0.059 45.465 0.000 2.670 1.768
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Lst30Dys (E) 1.062 0.058 18.180 0.000 1.062 0.689
## DontMind (VD) 2.280 0.125 18.180 0.000 2.280 1.000
## Trying (VT) 1.839 0.101 18.180 0.000 1.839 1.000
#lavaan Shiny GUI is a graphical user interface (GUI) built with Shiny,
#It allows users to specify and run SEM Models without writing full R code.
#How to Launch lavaan GUI
#1. Install required packages
#Install shinyif you haven't already:
require(lavaangui)
## Loading required package: lavaangui
## This is lavaangui 0.2.4
## lavaangui is BETA software! Please report any bugs at https://github.com/karchjd/lavaangui/issues
#After executing the following line, you will see a windown open. You can then
#move path elements around, save as an SVG or other format and export to the
#graphics package of your choice for further processing
#You'll have to run this interactively. The plot looks as follows:
require(lavaangui)
#Deselect Means
#Select Standardized Estimates to see Figure 4.2
#Select Estimates to see Figure 4.3
#Select means and estimates to see Figure 4.4
#plot_lavaan(regresult)
ModelDataP <-
read.csv("Partialcorrelationsim.csv", header = TRUE) ;
PartialModel<-"
! regressions
EGPA=~s1*GPA
EAlc=~s2*AlcQF
AlcQF ~ b21*ACTEng + b22*HSrank
GPA ~ b11*ACTEng + b12*HSrank
! residuals, variances and covariances
ACTEng ~~ A*ACTEng
HSrank ~~ B*HSrank
ACTEng ~~ r*HSrank
EGPA ~~ 1.0*EGPA
EAlc ~~ 1.0*EAlc
EGPA ~~ rga_er*EAlc
! observed means
GPA~1;
AlcQF~1;
ACTEng~1;
HSrank~1;
";
PartialResult<-lavaan(PartialModel, data=ModelDataP, fixed.x=FALSE, missing="FIML");
summary(PartialResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 85 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 14
##
## Number of observations 444
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 326.923
## Degrees of freedom 6
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -5265.367
## Loglikelihood unrestricted model (H1) -5265.367
##
## Akaike (AIC) 10558.734
## Bayesian (BIC) 10616.076
## Sample-size adjusted Bayesian (SABIC) 10571.646
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## EGPA =~
## GPA (s1) 0.591 0.020 29.799 0.000 0.591 0.837
## EAlc =~
## AlcQF (s2) 11.498 0.386 29.799 0.000 11.498 0.965
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## AlcQF ~
## ACTEng (b21) 0.094 0.162 0.581 0.561 0.094 0.031
## HSrank (b22) -0.153 0.029 -5.275 0.000 -0.153 -0.277
## GPA ~
## ACTEng (b11) 0.035 0.008 4.142 0.000 0.035 0.189
## HSrank (b12) 0.014 0.001 9.425 0.000 0.014 0.430
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## ACTEng ~~
## HSrank (r) 40.879 4.398 9.295 0.000 40.879 0.492
## EGPA ~~
## EAlc (rg_r) -0.174 0.046 -3.790 0.000 -0.174 -0.174
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .GPA 0.927 0.164 5.646 0.000 0.927 1.313
## .AlcQF 17.526 3.195 5.485 0.000 17.526 1.470
## ACTEng 22.074 0.183 120.609 0.000 22.074 5.724
## HSrank 74.270 1.023 72.574 0.000 74.270 3.444
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## ACTEng (A) 14.873 0.998 14.900 0.000 14.873 1.000
## HSrank (B) 465.003 31.209 14.900 0.000 465.003 1.000
## EGPA 1.000 1.000 1.000
## EAlc 1.000 1.000 1.000
## .GPA 0.000 0.000 0.000
## .AlcQF 0.000 0.000 0.000
##Path Diagram
#plot_lavaan(PartialResult)
SemiPartialModel<-"
! regressions
EGPA=~s1*GPA
EAlc=~s2*AlcQF
AlcQF ~ b21*ACTEng + b22*HSrank
! residuals, variances and covariances
ACTEng ~~ A*ACTEng
HSrank ~~ B*HSrank
ACTEng ~~ r*HSrank
HSrank ~~ cHSGPA*EGPA
ACTEng ~~ cACTEng*EGPA
EGPA ~~ 1.0*EGPA
EAlc ~~ 1.0*EAlc
EGPA ~~ rga_er*EAlc
! observed means
GPA~1;
AlcQF~1;
ACTEng~1;
HSrank~1;
";
SemiPartialResult<-lavaan(SemiPartialModel, data=ModelDataP, fixed.x=FALSE, missing="FIML");
summary(SemiPartialResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 92 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 14
##
## Number of observations 444
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 326.923
## Degrees of freedom 6
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -5265.367
## Loglikelihood unrestricted model (H1) -5265.367
##
## Akaike (AIC) 10558.734
## Bayesian (BIC) 10616.076
## Sample-size adjusted Bayesian (SABIC) 10571.646
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## EGPA =~
## GPA (s1) 0.706 0.024 29.799 0.000 0.706 1.000
## EAlc =~
## AlcQF (s2) 11.498 0.386 29.799 0.000 11.498 0.965
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## AlcQF ~
## ACTEng (b21) 0.094 0.162 0.581 0.561 0.094 0.031
## HSrank (b22) -0.153 0.029 -5.275 0.000 -0.153 -0.277
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## ACTEng ~~
## HSrank (r) 40.879 4.398 9.295 0.000 40.879 0.492
## EGPA ~~
## HSrank (cHSG) 11.268 0.951 11.849 0.000 11.268 0.523
## ACTEng (cACT) 1.543 0.176 8.789 0.000 1.543 0.400
## EAlc (rg_r) -0.146 0.039 -3.754 0.000 -0.146 -0.146
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .GPA 2.736 0.034 81.618 0.000 2.736 3.873
## .AlcQF 17.526 3.195 5.485 0.000 17.526 1.470
## ACTEng 22.074 0.183 120.609 0.000 22.074 5.724
## HSrank 74.270 1.023 72.574 0.000 74.270 3.444
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## ACTEng (A) 14.873 0.998 14.900 0.000 14.873 1.000
## HSrank (B) 465.003 31.209 14.900 0.000 465.003 1.000
## EGPA 1.000 1.000 1.000
## EAlc 1.000 1.000 1.000
## .GPA 0.000 0.000 0.000
## .AlcQF 0.000 0.000 0.000
#plot_lavaan(PartialResult)
FactorModel<-"
! regressions
F=~A*DontMind
F=~B*Lst30Dys
F=~C*Trying
! residuals, variances and covariances
Lst30Dys ~~ E*Lst30Dys
DontMind ~~ D*DontMind
Trying ~~ F*Trying
F ~~ 1.0*F
! means
Lst30Dys~MLst30Dys*1
Trying~MMature*1
DontMind~MDontMind*1
F~0*1;
";
FactorResult<-lavaan(FactorModel, data=ModelData, fixed.x=FALSE, missing="FIML");
summary(FactorResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 23 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 661
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 323.461
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -3268.407
## Loglikelihood unrestricted model (H1) -3268.407
##
## Akaike (AIC) 6554.814
## Bayesian (BIC) 6595.258
## Sample-size adjusted Bayesian (SABIC) 6566.683
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## F =~
## DontMind (A) 0.922 0.070 13.175 0.000 0.922 0.610
## Lst30Dys (B) 0.974 0.063 15.507 0.000 0.974 0.785
## Trying (C) -0.740 0.061 -12.139 0.000 -0.740 -0.545
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Lst30Dy (ML30) 1.654 0.048 34.264 0.000 1.654 1.333
## .Trying (MMtr) 3.626 0.053 68.751 0.000 3.626 2.674
## .DontMnd (MDnM) 2.670 0.059 45.465 0.000 2.670 1.768
## F 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Lst30Dys (E) 0.592 0.100 5.950 0.000 0.592 0.384
## .DontMind (D) 1.430 0.115 12.408 0.000 1.430 0.627
## .Trying (F) 1.292 0.089 14.449 0.000 1.292 0.702
## F 1.000 1.000 1.000
#plot_lavaan(FactorResult)
# Load required libraries
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(svglite) # Ensures SVG saving works
# Fit quadratic Model
Model <- lm(mpg ~ Speed + speed2, data = mpgData)
# Create new data for prediction
new_data <- data.frame(Speed = seq(20, 60, by = 1))
new_data$speed2 <- new_data$Speed^2
new_data$mpg <- predict(Model, newdata = new_data)
# Plot
p <- ggplot(new_data, aes(x = Speed, y = mpg)) +
geom_point(color = "blue") +
geom_line(data = new_data, aes(x = Speed, y = mpg), color = "red", size = 1.2) +
scale_x_continuous(name = "Speed", breaks = seq(20, 60, by = 10), limits = c(20, 60)) +
scale_y_continuous(name = "Miles per gallon") +
theme_minimal(base_size = 18) + # increase base font size by 50%
theme(
aspect.ratio = 1,
axis.line = element_line(color = "black", size = 0.8),
panel.grid = element_blank()
) +
theme(
axis.line.x = element_line(color = "black"),
axis.line.y = element_line(color = "black")
)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Save as SVG with square dimensions
# ggsave("square_scatterplot.svg", plot = p, width = 6, height = 6, dpi = 300)
#(Not in the book) #First of all, if running the Model based on raw scores, #squared and raw versions of the variable are highly collinear.
mpgRModel<-"
! regressions
mpg ~ bQ*speed2
mpg ~ bL*Speed
! residuals, variances and covariances
mpg ~~ e*mpg
Speed ~~ S1*Speed
speed2 ~~ S2*speed2
Speed ~~ s12*speed2
! means
Speed~mL*1
speed2~mQ*1
mpg~b0*1
"
mpgRresult<-lavaan(mpgRModel, data=mpgData, fixed.x=FALSE, missing="FIML")
## Warning: lavaan->lav_data_full():
## some observed variances are (at least) a factor 1000 times larger than
## others; use varTable(fit) to investigate
## Warning: lavaan->lav_model_vcov():
## Could not compute standard errors! The information matrix could not be
## inverted. This may be a symptom that the model is not identified.
summary(mpgRresult, fit.measures=TRUE,standardized=TRUE);
## Warning: lavaan->lav_fit_cfi_lavobject():
## computation of robust CFI failed.
## Warning: lavaan->lav_fit_rmsea_lavobject():
## computation of robust RMSEA failed.
## lavaan 0.6-19 ended normally after 74 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 8
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 64.042
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) NA
## Robust Tucker-Lewis Index (TLI) NA
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -83.175
## Loglikelihood unrestricted model (H1) -83.175
##
## Akaike (AIC) 184.350
## Bayesian (BIC) 185.065
## Sample-size adjusted Bayesian (SABIC) 158.471
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA NA
## 90 Percent confidence interval - lower NA
## 90 Percent confidence interval - upper NA
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## mpg ~
## speed2 (bQ) -0.019 NA -0.019 -6.406
## Speed (bL) 1.533 NA 1.533 6.864
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## speed2 ~~
## Speed (s12) 9843.750 NA 9843.750 0.991
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Speed (mL) 37.500 NA 37.500 3.273
## speed2 (mQ) 1537.500 NA 1537.500 1.774
## .mpg (b0) 2.868 NA 2.868 1.121
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .mpg (e) 0.125 NA 0.125 0.019
## Speed (S1) 131.250 NA 131.250 1.000
## speed2 (S2) 751406.242 NA 751406.242 1.000
# plot_lavaan(mpgRresult)
mpgCModel<-"
! regressions
mpg ~ bQ*cspeed2
mpg ~ bL*cspeed
! residuals, variances and covariances
mpg ~~ e*mpg
cspeed ~~ S1*cspeed
cspeed2 ~~ S2*cspeed2
cspeed ~~ s12*cspeed2
! means
cspeed~mL*1
cspeed2~mQ*1
mpg~b0*1
"
mpgCresult<-lavaan(mpgCModel, data=mpgData, fixed.x=FALSE, missing="FIML")
## Warning: lavaan->lav_data_full():
## some observed variances are (at least) a factor 1000 times larger than
## others; use varTable(fit) to investigate
summary(mpgCresult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 23 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 8
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 31.662
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -83.175
## Loglikelihood unrestricted model (H1) -83.175
##
## Akaike (AIC) 184.350
## Bayesian (BIC) 185.065
## Sample-size adjusted Bayesian (SABIC) 158.471
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## mpg ~
## cspeed2 (bQ) -0.019 0.001 -17.324 0.000 -0.019 -0.847
## cspeed (bL) 0.115 0.011 10.517 0.000 0.115 0.514
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## cspeed2 ~~
## cspeed (s12) 0.000 464.039 0.000 1.000 0.000 0.000
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## cspeed (mL) -0.000 4.050 -0.000 1.000 -0.000 -0.000
## cspeed2 (mQ) 131.250 40.505 3.240 0.001 131.250 1.146
## .mpg (b0) 33.756 0.190 177.563 0.000 33.756 13.195
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .mpg (e) 0.125 0.063 2.000 0.046 0.125 0.019
## cspeed (S1) 131.250 65.625 2.000 0.046 131.250 1.000
## cspeed2 (S2) 13125.000 6562.499 2.000 0.046 13125.000 1.000
#plot_lavaan(mpgCresult)
MediationModel<-"
! regressions
Mature ~ C*Cool
Lst30Dys ~ B*Mature
Lst30Dys ~ A*Cool
! residuals, variances and covariances
Lst30Dys ~~ E*Lst30Dys
Cool ~~ Vc*Cool
Mature ~~ Vd*Mature
! means
Cool~MT*1
Mature~MD*1
Lst30Dys~I*1
# indirect effect (Cool*Mature)
Cool2Mature := C*B
# total
total := A+(C*B)
";
Mediationresult<-lavaan(MediationModel, data=MediationData, fixed.x=FALSE, missing="FIML",se = "bootstrap",bootstrap = 1000)
summary(Mediationresult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 7 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 661
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 510.984
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -2701.384
## Loglikelihood unrestricted model (H1) -2701.384
##
## Akaike (AIC) 5420.768
## Bayesian (BIC) 5461.212
## Sample-size adjusted Bayesian (SABIC) 5432.636
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Bootstrap
## Number of requested bootstrap draws 1000
## Number of successful bootstrap draws 1000
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Mature ~
## Cool (C) 0.638 0.029 22.233 0.000 0.638 0.678
## Lst30Dys ~
## Mature (B) 0.302 0.063 4.795 0.000 0.302 0.236
## Cool (A) 0.217 0.059 3.703 0.000 0.217 0.180
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Cool (MT) 1.702 0.041 41.874 0.000 1.702 1.650
## .Mature (MD) 0.622 0.056 11.115 0.000 0.622 0.641
## .Lst30Dys (I) 0.770 0.098 7.882 0.000 0.770 0.620
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Lst30Dys (E) 1.316 0.069 19.181 0.000 1.316 0.854
## Cool (Vc) 1.063 0.060 17.774 0.000 1.063 1.000
## .Mature (Vd) 0.509 0.029 17.733 0.000 0.509 0.540
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Cool2Mature 0.193 0.041 4.701 0.000 0.193 0.160
## total 0.409 0.046 8.914 0.000 0.409 0.340
#plot_lavaan(Mediationresult)
AnovaModel<-"
! regressions
y ~ MG3*d3
y ~ MG2*d2
y ~ MG1*d1
! residuals, variances and covariances
y ~~ Ve*y
d1 ~~ Vd1*d1
d2 ~~ Vd2*d2
d3 ~~ Vd3*d3
d1 ~~ C12*d2
d2 ~~ c23*d3
d3 ~~ C13*d1
! means
d1~Md1*1
d2~Md2*1
d3~Md3*1
y~0*1;
"
summary(ThreeGroupData)
## Obs y group d1 d2
## Min. : 1.0 Min. : 1 Min. :1 Min. :0.0000 Min. :0.0000
## 1st Qu.: 4.5 1st Qu.: 4 1st Qu.:1 1st Qu.:0.0000 1st Qu.:0.0000
## Median : 8.0 Median : 6 Median :2 Median :0.0000 Median :0.0000
## Mean : 8.0 Mean : 6 Mean :2 Mean :0.3333 Mean :0.3333
## 3rd Qu.:11.5 3rd Qu.: 8 3rd Qu.:3 3rd Qu.:1.0000 3rd Qu.:1.0000
## Max. :15.0 Max. :11 Max. :3 Max. :1.0000 Max. :1.0000
## d3 e1 e2 O1 O2
## Min. :0.0000 Min. :-1 Min. :-1 Min. :-1.0 Min. :-1
## 1st Qu.:0.0000 1st Qu.:-1 1st Qu.:-1 1st Qu.:-1.0 1st Qu.:-1
## Median :0.0000 Median : 0 Median : 0 Median : 0.5 Median : 0
## Mean :0.3333 Mean : 0 Mean : 0 Mean : 0.0 Mean : 0
## 3rd Qu.:1.0000 3rd Qu.: 1 3rd Qu.: 1 3rd Qu.: 0.5 3rd Qu.: 1
## Max. :1.0000 Max. : 1 Max. : 1 Max. : 0.5 Max. : 1
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
## The following object is masked from 'package:lavaan':
##
## cor2cov
describeBy(ThreeGroupData$y, group = ThreeGroupData$group)
##
## Descriptive statistics by group
## group: 1
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 5 3 1.58 3 3 1.48 1 5 4 0 -1.91 0.71
## ------------------------------------------------------------
## group: 2
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 5 6 1.58 6 6 1.48 4 8 4 0 -1.91 0.71
## ------------------------------------------------------------
## group: 3
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 5 9 1.58 9 9 1.48 7 11 4 0 -1.91 0.71
AnovaResult<-lavaan(AnovaModel, data=ThreeGroupData, fixed.x=FALSE, estimator = "ULS")
summary(AnovaResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 141 iterations
##
## Estimator ULS
## Optimization method NLMINB
## Number of model parameters 13
##
## Number of observations 15
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 1
## P-value (Unknown) NA
##
## Model Test Baseline Model:
##
## Test statistic 32.738
## Degrees of freedom 6
## P-value NA
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.224
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 1.000
## P-value H_0: RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Unstructured
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## y ~
## d3 (MG3) 9.000 6.193 1.453 0.146 9.000 1.500
## d2 (MG2) 6.000 6.472 0.927 0.354 6.000 1.000
## d1 (MG1) 3.000 7.182 0.418 0.676 3.000 0.500
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## d2 ~~
## d1 (C12) -0.119 0.248 -0.480 0.631 -0.119 -0.500
## d3 ~~
## d2 (c23) -0.119 0.209 -0.570 0.569 -0.119 -0.500
## d1 (C13) -0.119 0.232 -0.514 0.607 -0.119 -0.500
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## d1 (Md1) 0.333 0.267 1.247 0.212 0.333 0.683
## d2 (Md2) 0.333 0.267 1.247 0.212 0.333 0.683
## d3 (Md3) 0.333 0.267 1.247 0.212 0.333 0.683
## .y 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .y (Ve) 2.143 11.758 0.182 0.855 2.143 0.250
## d1 (Vd1) 0.238 0.265 0.898 0.369 0.238 1.000
## d2 (Vd2) 0.238 0.259 0.920 0.358 0.238 1.000
## d3 (Vd3) 0.238 0.248 0.961 0.337 0.238 1.000
##Plot Model Figure 4.12a
#plot_lavaan(AnovaResult)
DummyModel<-"
! regressions
y ~ b2*d2
y ~ b1*d1
! residuals, variances and covariances
y ~~ VAR_y*y
d1 ~~ Vd1*d1
d2 ~~ Vd2*d2
d1 ~~ Cd1d2*d2
! means
d1~Md1*1
d2~Md2*1
y~Mc*1
"
DummyResult<-lavaan(DummyModel, data=ThreeGroupData, fixed.x=FALSE, estimator = "ULS")
summary(DummyResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 35 iterations
##
## Estimator ULS
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 15
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 16.270
## Degrees of freedom 3
## P-value NA
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Unstructured
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## y ~
## d2 (b2) -3.000 13.005 -0.231 0.818 -3.000 -0.500
## d1 (b1) -6.000 13.005 -0.461 0.645 -6.000 -1.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## d2 ~~
## d1 (Cd12) -0.119 0.267 -0.445 0.656 -0.119 -0.500
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## d1 (Md1) 0.333 0.267 1.247 0.212 0.333 0.683
## d2 (Md2) 0.333 0.267 1.247 0.212 0.333 0.683
## .y (Mc) 9.000 8.658 1.039 0.299 9.000 3.074
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .y (VAR_) 2.143 14.278 0.150 0.881 2.143 0.250
## d1 (Vd1) 0.238 0.267 0.891 0.373 0.238 1.000
## d2 (Vd2) 0.238 0.267 0.891 0.373 0.238 1.000
#plot_lavaan(DummyResult)
OrthModel<-"
! regressions
y ~ b1*O1
y ~ b2*O2
! residuals, variances and covariances
y ~~ Ve*y
O1 ~~ VO1*O1
O2 ~~ VO2*O2
O1 ~~ C*O2
! means
y~b0*1
O1~MO1*1
O2~MO2*1
"
OrthResult<-lavaan(OrthModel, data=ThreeGroupData, fixed.x=FALSE)
summary(OrthResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 9 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 15
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 20.794
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -60.811
## Loglikelihood unrestricted model (H1) -60.811
##
## Akaike (AIC) 139.622
## Bayesian (BIC) 145.995
## Sample-size adjusted Bayesian (SABIC) 118.519
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## y ~
## O1 (b1) 3.000 0.516 5.809 0.000 3.000 0.750
## O2 (b2) -1.500 0.447 -3.354 0.001 -1.500 -0.433
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## O1 ~~
## O2 (C) 0.000 0.149 0.000 1.000 0.000 0.000
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .y (b0) 6.000 0.365 16.432 0.000 6.000 2.121
## O1 (MO1) 0.000 0.183 0.000 1.000 0.000 0.000
## O2 (MO2) 0.000 0.211 0.000 1.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .y (Ve) 2.000 0.730 2.739 0.006 2.000 0.250
## O1 (VO1) 0.500 0.183 2.739 0.006 0.500 1.000
## O2 (VO2) 0.667 0.243 2.739 0.006 0.667 1.000
#plot_lavaan(OrthResult)
EffectModel<-"
! regressions
y ~ b2*e2
y ~ b1*e1
! residuals, variances and covariances
e1 ~~ Ve1*e1
e2 ~~ Ve2*e2
y ~~ Ve*y
e1 ~~ C*e2
! means
y~b0*1
e2~ME2*1
e1~ME1*1
"
EffectResult<-lavaan(EffectModel, data=ThreeGroupData, fixed.x=TRUE,estimator="ULS")
summary(EffectResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 27 iterations
##
## Estimator ULS
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 15
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 82.143
## Degrees of freedom 3
## P-value NA
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Unstructured
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## y ~
## e2 (b2) -0.000 1.764 -0.000 1.000 -0.000 -0.000
## e1 (b1) -3.000 1.764 -1.701 0.089 -3.000 -0.866
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## e2 ~~
## e1 (C) 0.357 0.267 1.336 0.181 0.357 0.500
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .y (b0) 6.000 0.845 7.099 0.000 6.000 2.049
## e2 (ME2) 0.000 0.267 0.000 1.000 0.000 0.000
## e1 (ME1) 0.000 0.267 0.000 1.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## e1 (Ve1) 0.714 0.267 2.673 0.008 0.714 1.000
## e2 (Ve2) 0.714 0.267 2.673 0.008 0.714 1.000
## .y (Ve) 2.143 2.903 0.738 0.460 2.143 0.250
#plot_lavaan(EffectResult)
DepTModel<-"
! regressions
height=~1.0*Self
height=~1.0*Cross
gain=~1.0*Cross
zheight=~SdH*height
zgain=~SdG*gain
! residuals, variances and covariances
zheight ~~ 1.0*zheight
zgain ~~ 1.0*zgain
zheight ~~ Corr*zgain
height~~0*height
gain~~0*gain
height ~~ 0.0*gain
height ~~ 0.0*zgain
gain ~~ 0.0*zheight
! means
height~Mh*1
gain~Mg*1
Cross~0*1;
Self~0*1;
zheight~0*1;
zgain~0*1;
"
DepTResult<-lavaan(DepTModel, data=DarwinData, fixed.x=TRUE,estimator="ULS")
summary(DepTResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 35 iterations
##
## Estimator ULS
## Optimization method NLMINB
## Number of model parameters 5
##
## Number of observations 15
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 433664.000
## Degrees of freedom 1
## P-value NA
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Unstructured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## height =~
## Self 1.000 16.639 1.000
## Cross 1.000 16.639 0.575
## gain =~
## Cross 1.000 38.290 1.323
## zheight =~
## height (SdH) -16.639 0.008 -2071.809 0.000 -1.000 -1.000
## zgain =~
## gain (SdG) 38.290 0.009 4479.082 0.000 1.000 1.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## zheight ~~
## zgain (Corr) 0.711 0.000 2390.884 0.000 0.711 0.711
## .height ~~
## .gain 0.000 NaN NaN
## zgain 0.000 NaN NaN
## .gain ~~
## zheight 0.000 NaN NaN
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .height (Mh) 140.000 0.267 523.832 0.000 8.414 8.414
## .gain (Mg) 21.533 0.378 56.972 0.000 0.562 0.562
## .Cross 0.000 0.000 0.000
## .Self 0.000 0.000 0.000
## zheight 0.000 0.000 0.000
## zgain 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## zheight 1.000 1.000 1.000
## zgain 1.000 1.000 1.000
## .height 0.000 0.000 0.000
## .gain 0.000 0.000 0.000
## .Self 0.000 0.000 0.000
## .Cross 0.000 0.000 0.000
#plot_lavaan(DepTResult)
library(ggplot2)
library(svglite)
library(cowplot)
# Convert Sex to a factor with meaningful labels
WeightLoss$SexC <- factor(WeightLoss$Sex, levels = c(0, 1), labels = c("Female", "Male"))
ggplot(WeightLoss, aes(x = Glucagon, y = Weight)) +
geom_point(aes(shape = SexC), color = "black", size = 3) +
geom_smooth(method = "lm", se = FALSE, color = "black", linewidth = 1) +
scale_shape_manual(values = c(15, 16)) + # Square and circle
labs(x = "Glucagon", y = "Weight", title = "Weight vs Glucagon") +
theme_minimal(base_size = 16) +
theme(
legend.title = element_blank(),
legend.position = "top"
)
## `geom_smooth()` using formula = 'y ~ x'
AncovaModel<-"
! regressions
Weight ~ b1*Glucagon
Weight ~ b2*Sex
! residuals, variances and covariances
Glucagon ~~ VG*Glucagon
Weight ~~ V*Weight
Sex ~~ VS*Sex
Glucagon ~~ C*Sex
! means
Glucagon~MG*1
Sex~MS*1
Weight~b0*1
"
AncovaResult<-lavaan(AncovaModel, data=WeightLoss, fixed.x=TRUE,estimator="ULS")
summary(AncovaResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 41 iterations
##
## Estimator ULS
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 10
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 1045.005
## Degrees of freedom 3
## P-value NA
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Unstructured
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Weight ~
## Glucagon (b1) 1.051 0.404 2.604 0.009 1.051 0.886
## Sex (b2) 5.414 7.563 0.716 0.474 5.414 0.658
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Glucagon ~~
## Sex (C) -0.617 0.333 -1.850 0.064 -0.617 -0.320
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Glucagon (MG) 15.710 0.333 47.130 0.000 15.710 4.295
## Sex (MS) 0.500 0.333 1.500 0.134 0.500 0.949
## .Weight (b0) -10.162 10.158 -1.000 0.317 -10.162 -2.343
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Glucagon (VG) 13.377 0.333 40.130 0.000 13.377 1.000
## .Weight (V) 2.913 11.118 0.262 0.793 2.913 0.155
## Sex (VS) 0.278 0.333 0.833 0.405 0.278 1.000
#plot_lavaan(AncovaResult)
LDiffModel<-"
! regressions
Diff=~1.0*wisc_2
wisc_2 ~ 1.0*wisc_1
! residuals, variances and covariances
wisc_1 ~~ Vwisc_1*wisc_1
Diff ~~ VDiff*Diff
wisc_1 ~~ Cov*Diff
! means
wisc_1~MWisc1*1
Diff~MDiff*1
wisc_2~0*1;
"
LDiffResult<-lavaan(LDiffModel, data=WiscData, fixed.x=FALSE, missing="FIML")
summary(LDiffResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 40 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 5
##
## Number of observations 204
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 220.996
## Degrees of freedom 1
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1249.639
## Loglikelihood unrestricted model (H1) -1249.639
##
## Akaike (AIC) 2509.278
## Bayesian (BIC) 2525.868
## Sample-size adjusted Bayesian (SABIC) 2510.027
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Diff =~
## wisc_2 1.000 4.237 0.585
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_2 ~
## wisc_1 1.000 1.000 0.879
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## Diff ~~
## wisc_1 (Cov) -3.014 1.899 -1.587 0.112 -0.711 -0.112
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_1 (MWs1) 18.781 0.445 42.173 0.000 18.781 2.953
## Diff (MDff) 7.772 0.297 26.196 0.000 1.834 1.834
## .wisc_2 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_1 (Vw_1) 40.458 4.006 10.100 0.000 40.458 1.000
## Diff (VDff) 17.956 1.778 10.100 0.000 1.000 1.000
## .wisc_2 0.000 0.000 0.000
#plot_lavaan(LDiffResult)
LDiff3WModel<-"
! regressions
diff1=~0.88*wisc_2
diff2=~1.85*wisc_3
wisc_2 ~ 1.0*wisc_1
wisc_3 ~ 1.0*wisc_2
! residuals, variances and covariances
wisc_1 ~~ VWisc_1*wisc_1
diff1 ~~ VDiff1*diff1
diff2 ~~ VDiff2*diff2
wisc_1 ~~ CW1D1*diff1
diff1 ~~ CD1D2*diff2
wisc_1 ~~ CW1D2*diff2
! means
wisc_1~MWisc1*1
diff1~MD1*1
diff2~MD2*1
wisc_2~0*1;
wisc_3~0*1;
"
LDiff3WResult<-lavaan(LDiff3WModel, data=WiscData, fixed.x=FALSE, missing="FIML")
summary(LDiff3WResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 61 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 204
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 515.143
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1809.605
## Loglikelihood unrestricted model (H1) -1809.605
##
## Akaike (AIC) 3637.209
## Bayesian (BIC) 3667.072
## Sample-size adjusted Bayesian (SABIC) 3638.558
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## diff1 =~
## wisc_2 0.880 4.237 0.585
## diff2 =~
## wisc_3 1.850 4.113 0.531
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_2 ~
## wisc_1 1.000 1.000 0.879
## wisc_3 ~
## wisc_2 1.000 1.000 0.935
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## diff1 ~~
## wisc_1 (CW1D1) -3.425 2.158 -1.587 0.112 -0.711 -0.112
## diff2 (CD1D) -4.278 0.807 -5.300 0.000 -0.400 -0.400
## diff2 ~~
## wisc_1 (CW1D2) 1.243 0.994 1.251 0.211 0.559 0.088
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_1 (MWs1) 18.781 0.445 42.173 0.000 18.781 2.953
## diff1 (MD1) 8.831 0.337 26.196 0.000 1.834 1.834
## diff2 (MD2) 5.097 0.156 32.746 0.000 2.293 2.293
## .wisc_2 0.000 0.000 0.000
## .wisc_3 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_1 (VW_1) 40.458 4.006 10.100 0.000 40.458 1.000
## diff1 (VDf1) 23.187 2.296 10.100 0.000 1.000 1.000
## diff2 (VDf2) 4.942 0.489 10.100 0.000 1.000 1.000
## .wisc_2 0.000 0.000 0.000
## .wisc_3 0.000 0.000 0.000
#plot_lavaan(LDiff3WResult)
AccelModel<-"
! regressions
diff1=~0.88*wisc_2
diff2=~1.85*wisc_3
wisc_2 ~ 1.0*wisc_1
wisc_3 ~ 1.0*wisc_2
Accel=~1.0*diff2
diff1=~1.0*diff2
! residuals, variances and covariances
wisc_1 ~~ VWisc_1*wisc_1
diff1 ~~ VDiff1*diff1
wisc_1 ~~ CW1D1*diff1
Accel ~~ VAccel*Accel
diff1 ~~ CD1Acc*Accel
wisc_1 ~~ CW1Acc*Accel
diff2~~0*diff2
! means
wisc_1~MWisc1*1
diff1~MD1*1
Accel~MAccel*1
wisc_2~0*1;
wisc_3~0*1;
diff2~0*1;
"
AccelResult<-lavaan(AccelModel, data=WiscData, fixed.x=FALSE, missing="FIML")
summary(AccelResult, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 106 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 204
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 515.143
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1809.605
## Loglikelihood unrestricted model (H1) -1809.605
##
## Akaike (AIC) 3637.209
## Bayesian (BIC) 3667.072
## Sample-size adjusted Bayesian (SABIC) 3638.558
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Observed
## Observed information based on Hessian
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## diff1 =~
## wisc_2 0.880 4.237 0.585
## diff2 =~
## wisc_3 1.850 4.113 0.531
## Accel =~
## diff2 1.000 2.724 2.724
## diff1 =~
## diff2 1.000 2.166 2.166
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_2 ~
## wisc_1 1.000 1.000 0.879
## wisc_3 ~
## wisc_2 1.000 1.000 0.935
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## diff1 ~~
## wisc_1 (CW1D) -3.425 2.158 -1.587 0.112 -0.711 -0.112
## Accel (CD1A) -27.465 2.805 -9.792 0.000 -0.942 -0.942
## Accel ~~
## wisc_1 (CW1A) 4.668 2.717 1.718 0.086 0.771 0.121
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_1 (MWs1) 18.781 0.445 42.173 0.000 18.781 2.953
## diff1 (MD1) 8.831 0.337 26.196 0.000 1.834 1.834
## Accel (MAcc) -3.734 0.424 -8.806 0.000 -0.617 -0.617
## .wisc_2 0.000 0.000 0.000
## .wisc_3 0.000 0.000 0.000
## .diff2 0.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## wisc_1 (VW_1) 40.458 4.006 10.100 0.000 40.458 1.000
## diff1 (VDf1) 23.187 2.296 10.100 0.000 1.000 1.000
## Accel (VAcc) 36.685 3.632 10.100 0.000 1.000 1.000
## .diff2 0.000 0.000 0.000
## .wisc_2 0.000 0.000 0.000
## .wisc_3 0.000 0.000 0.000
#plot_lavaan(AccelResult)
ReciprocalData <- read.delim("duncanhallerportesreciprocal.txt", header = TRUE) ;
ReciprocalModel<-"
! regressions
REASP ~ b1*RIQ
FEASP ~ A*REASP
REASP ~ B*FEASP
! residuals, variances and covariances
REASP ~~ VR*REASP
RIQ ~~ VAR_RIQ*RIQ
FEASP ~~ VF*FEASP
! observed means
REASP~1;
RIQ~1;
FEASP~1;
"
ReciprocalResult<-lavaan(ReciprocalModel, data=ReciprocalData, fixed.x=FALSE, estimator="mlr", missing="FIML");
summary(ReciprocalResult, fit.measures=TRUE);
## lavaan 0.6-19 ended normally after 22 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 329
## Number of missing patterns 1
##
## Model Test User Model:
## Standard Scaled
## Test Statistic 0.000 0.000
## Degrees of freedom 0 0
##
## Model Test Baseline Model:
##
## Test statistic 115.576 119.846
## Degrees of freedom 3 3
## P-value 0.000 0.000
## Scaling correction factor 0.964
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000 1.000
## Tucker-Lewis Index (TLI) 1.000 1.000
##
## Robust Comparative Fit Index (CFI) 1.000
## Robust Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1341.202 -1341.202
## Loglikelihood unrestricted model (H1) -1341.202 -1341.202
##
## Akaike (AIC) 2700.404 2700.404
## Bayesian (BIC) 2734.569 2734.569
## Sample-size adjusted Bayesian (SABIC) 2706.021 2706.021
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000 NA
## 90 Percent confidence interval - lower 0.000 NA
## 90 Percent confidence interval - upper 0.000 NA
## P-value H_0: RMSEA <= 0.050 NA NA
## P-value H_0: RMSEA >= 0.080 NA NA
##
## Robust RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: Robust RMSEA <= 0.050 NA
## P-value H_0: Robust RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000 0.000
##
## Parameter Estimates:
##
## Standard errors Sandwich
## Information bread Observed
## Observed information based on Hessian
##
## Regressions:
## Estimate Std.Err z-value P(>|z|)
## REASP ~
## RIQ (b1) 0.543 0.077 7.003 0.000
## FEASP ~
## REASP (A) 0.718 0.122 5.867 0.000
## REASP ~
## FEASP (B) -0.477 0.178 -2.678 0.007
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|)
## .REASP -0.000 0.062 -0.000 1.000
## RIQ -0.000 0.055 -0.000 1.000
## .FEASP 0.000 0.055 0.000 1.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .REASP (VR) 1.279 0.256 4.991 0.000
## RIQ (VAR_) 0.997 0.076 13.044 0.000
## .FEASP (VF) 0.986 0.117 8.435 0.000
#plot_lavaan(ReciprocalResult)