Figure 8.1 Factor with Unit Variance

Load Simulated Alcohol Data

<a href=“https://docs.google.com/document/d/1SZ44w8P1oq6C_kMhAdBE8WX9z14-u3NNKQDCVkNmNK4/edit?usp=sharing>

require(lavaan)
## Loading required package: lavaan
## This is lavaan 0.6-19
## lavaan is FREE software! Please report any bugs.
AlcUseData <- read.table("singlegroupalc.txt", header = TRUE) ;
Fig8.1Model<-"
! regressions 
   AlcoholUse=~L1*alcf3mw1 + +NA*alcf3mw1 + L2*typqfrw1
   AlcoholUse=~L3*typqsaw1
   AlcoholUse=~L4*typqthw1
   AlcoholUse=~L5*qpls5mw1
! residuals, variances and covariances
   alcf3mw1 ~~ E1*alcf3mw1
   typqfrw1 ~~ E2*typqfrw1
   typqsaw1 ~~ E3*typqsaw1
   typqthw1 ~~ E4*typqthw1
   qpls5mw1 ~~ E5*qpls5mw1
   AlcoholUse ~~ 1.0*AlcoholUse
! observed means
   alcf3mw1~1;
   typqfrw1~1;
   typqsaw1~1;
   typqthw1~1;
   qpls5mw1~1;
"
Fig8.1Result<-lavaan(Fig8.1Model, data=AlcUseData, fixed.x=FALSE, missing="FIML")
summary(Fig8.1Result, fit.measures=TRUE,standardized=TRUE);
## lavaan 0.6-19 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        15
## 
##   Number of observations                          2557
##   Number of missing patterns                         1
## 
## Model Test User Model:
##                                                       
##   Test statistic                               107.700
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              5465.449
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.981
##   Tucker-Lewis Index (TLI)                       0.962
##                                                       
##   Robust Comparative Fit Index (CFI)             0.981
##   Robust Tucker-Lewis Index (TLI)                0.962
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28205.240
##   Loglikelihood unrestricted model (H1)     -28151.390
##                                                       
##   Akaike (AIC)                               56440.480
##   Bayesian (BIC)                             56528.179
##   Sample-size adjusted Bayesian (SABIC)      56480.520
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.090
##   90 Percent confidence interval - lower         0.075
##   90 Percent confidence interval - upper         0.105
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.870
##                                                       
##   Robust RMSEA                                   0.090
##   90 Percent confidence interval - lower         0.075
##   90 Percent confidence interval - upper         0.105
##   P-value H_0: Robust RMSEA <= 0.050             0.000
##   P-value H_0: Robust RMSEA >= 0.080             0.870
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.021
## 
## 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
##   AlcoholUse =~                                                         
##     alcf3mw1  (L1)    2.360    0.052   45.124    0.000    2.360    0.789
##     typqfrw1  (L2)    2.894    0.068   42.509    0.000    2.894    0.757
##     typqsaw1  (L3)    3.209    0.074   43.206    0.000    3.209    0.766
##     typqthw1  (L4)    1.585    0.053   29.821    0.000    1.585    0.576
##     qpls5mw1  (L5)    0.886    0.019   45.923    0.000    0.886    0.801
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1          3.968    0.059   67.051    0.000    3.968    1.326
##    .typqfrw1          2.268    0.076   29.994    0.000    2.268    0.593
##    .typqsaw1          2.654    0.083   32.051    0.000    2.654    0.634
##    .typqthw1          1.077    0.054   19.783    0.000    1.077    0.391
##    .qpls5mw1          0.666    0.022   30.428    0.000    0.666    0.602
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1  (E1)    3.385    0.127   26.649    0.000    3.385    0.378
##    .typqfrw1  (E2)    6.246    0.222   28.187    0.000    6.246    0.427
##    .typqsaw1  (E3)    7.235    0.262   27.612    0.000    7.235    0.413
##    .typqthw1  (E4)    5.071    0.154   32.974    0.000    5.071    0.669
##    .qpls5mw1  (E5)    0.440    0.017   25.470    0.000    0.440    0.359
##     AlcoholUs         1.000                               1.000    1.000
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
# plot_lavaan(Fig8.1result)
Single Factor with Unit Variance
Single Factor with Unit Variance
Standardized Single Factor with Unit Variance
Standardized Single Factor with Unit Variance

Figure 8.3 Single Factor with Referent Indicator

Fig8.3model<-"
! regressions 
   AlcoholUse=~L1*alcf3mw1
   AlcoholUse=~L4*typqfrw1
   AlcoholUse=~1.0*typqsaw1
   AlcoholUse=~L3*typqthw1
   AlcoholUse=~L2*qpls5mw1
! residuals, variances and covariances
   alcf3mw1 ~~ E1*alcf3mw1
   typqfrw1 ~~ E2*typqfrw1
   typqsaw1 ~~ E3*typqsaw1
   typqthw1 ~~ E4*typqthw1
   qpls5mw1 ~~ E5*qpls5mw1
   AlcoholUse ~~ Vf*AlcoholUse
! observed means
   alcf3mw1~1;
   typqfrw1~1;
   typqsaw1~1;
   typqthw1~1;
   qpls5mw1~1;
"

Figure8.3result<-lavaan(Fig8.3model, data=AlcUseData, fixed.x=FALSE, missing="FIML")
summary(Figure8.3result, standardized=TRUE, fit.measures=TRUE)
## lavaan 0.6-19 ended normally after 33 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        15
## 
##   Number of observations                          2557
##   Number of missing patterns                         1
## 
## Model Test User Model:
##                                                       
##   Test statistic                               107.700
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              5465.449
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.981
##   Tucker-Lewis Index (TLI)                       0.962
##                                                       
##   Robust Comparative Fit Index (CFI)             0.981
##   Robust Tucker-Lewis Index (TLI)                0.962
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28205.240
##   Loglikelihood unrestricted model (H1)     -28151.390
##                                                       
##   Akaike (AIC)                               56440.480
##   Bayesian (BIC)                             56528.179
##   Sample-size adjusted Bayesian (SABIC)      56480.520
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.090
##   90 Percent confidence interval - lower         0.075
##   90 Percent confidence interval - upper         0.105
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.870
##                                                       
##   Robust RMSEA                                   0.090
##   90 Percent confidence interval - lower         0.075
##   90 Percent confidence interval - upper         0.105
##   P-value H_0: Robust RMSEA <= 0.050             0.000
##   P-value H_0: Robust RMSEA >= 0.080             0.870
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.021
## 
## 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
##   AlcoholUse =~                                                         
##     alcf3mw1  (L1)    0.735    0.019   39.258    0.000    2.360    0.789
##     typqfrw1  (L4)    0.902    0.024   38.081    0.000    2.894    0.757
##     typqsaw1          1.000                               3.209    0.766
##     typqthw1  (L3)    0.494    0.018   27.690    0.000    1.585    0.576
##     qpls5mw1  (L2)    0.276    0.007   38.687    0.000    0.886    0.801
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1          3.968    0.059   67.051    0.000    3.968    1.326
##    .typqfrw1          2.268    0.076   29.994    0.000    2.268    0.593
##    .typqsaw1          2.654    0.083   32.051    0.000    2.654    0.634
##    .typqthw1          1.077    0.054   19.783    0.000    1.077    0.391
##    .qpls5mw1          0.666    0.022   30.428    0.000    0.666    0.602
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1  (E1)    3.385    0.127   26.649    0.000    3.385    0.378
##    .typqfrw1  (E2)    6.246    0.222   28.187    0.000    6.246    0.427
##    .typqsaw1  (E3)    7.235    0.262   27.612    0.000    7.235    0.413
##    .typqthw1  (E4)    5.071    0.154   32.974    0.000    5.071    0.669
##    .qpls5mw1  (E5)    0.440    0.017   25.470    0.000    0.440    0.359
##     AlcoholUs (Vf)   10.296    0.477   21.603    0.000    1.000    1.000
require(lavaangui)
#plot_lavaan(Figure8.3result)
Single Factor with Referent Indicator
Single Factor with Referent Indicator
Fig8.4Model <- "
  # Latent factor loadings (all freely estimated)
  AlcoholUse =~ L1*alcf3mw1 +
                L2*qpls5mw1 +
                L3*typqthw1 +
                L4*typqfrw1 +
                L5*typqsaw1

  # Residual variances
  alcf3mw1 ~~ E1*alcf3mw1
  qpls5mw1 ~~ E2*qpls5mw1
  typqthw1 ~~ E3*typqthw1
  typqfrw1 ~~ E4*typqfrw1
  typqsaw1 ~~ E5*typqsaw1

  # Latent factor variance
  AlcoholUse ~~ Vf*AlcoholUse

  # Observed means (intercepts, all freely estimated)
  alcf3mw1 ~ I1*1
  qpls5mw1 ~ I2*1
  typqthw1 ~ I3*1
  typqfrw1 ~ I4*1
  typqsaw1 ~ I5*1
 AlcoholUse ~ Malc*1
  # ---- Effects coding constraints ----

  # Sum of loadings = 5 (number of indicators)
  L1 ==5- L2 + L3 + L4 + L5

  # Sum of intercepts = 0
  I1 == -I2 - I3 - I4 - I5
"

Figure8.4result<-lavaan(Fig8.4Model, data=AlcUseData, fixed.x=FALSE, missing="FIML")
summary(Figure8.4result, standardized=TRUE, fit.measures=TRUE)
## lavaan 0.6-19 ended normally after 41 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        17
##   Number of equality constraints                     2
## 
##   Number of observations                          2557
##   Number of missing patterns                         1
## 
## Model Test User Model:
##                                                       
##   Test statistic                               107.700
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              5465.449
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.981
##   Tucker-Lewis Index (TLI)                       0.962
##                                                       
##   Robust Comparative Fit Index (CFI)             0.000
##   Robust Tucker-Lewis Index (TLI)               -7.046
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28205.240
##   Loglikelihood unrestricted model (H1)     -28151.390
##                                                       
##   Akaike (AIC)                               56440.480
##   Bayesian (BIC)                             56528.179
##   Sample-size adjusted Bayesian (SABIC)      56480.520
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.090
##   90 Percent confidence interval - lower         0.075
##   90 Percent confidence interval - upper         0.105
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.870
##                                                       
##   Robust RMSEA                                   1.310
##   90 Percent confidence interval - lower         1.296
##   90 Percent confidence interval - upper         1.325
##   P-value H_0: Robust RMSEA <= 0.050             0.000
##   P-value H_0: Robust RMSEA >= 0.080             1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.021
## 
## 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
##   AlcoholUse =~                                                         
##     alcf3mw1  (L1)    1.228    0.043   28.717    0.000    2.360    0.789
##     qpls5mw1  (L2)    0.461    0.015   31.749    0.000    0.886    0.801
##     typqthw1  (L3)    0.825    0.024   34.235    0.000    1.585    0.576
##     typqfrw1  (L4)    1.507    0.031   48.069    0.000    2.894    0.757
##     typqsaw1  (L5)    1.670    0.033   49.878    0.000    3.209    0.766
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3m1   (I1)    1.567    0.052   30.104    0.000    1.567    0.524
##    .qpls5m1   (I2)   -0.235    0.022  -10.784    0.000   -0.235   -0.213
##    .typqth1   (I3)   -0.535    0.060   -8.949    0.000   -0.535   -0.194
##    .typqfr1   (I4)   -0.676    0.063  -10.659    0.000   -0.676   -0.177
##    .typqsw1   (I5)   -0.610    0.066   -9.201    0.000   -0.610   -0.146
##     AlchlUs (Malc)    1.954    0.056   35.059    0.000    1.017    1.017
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1  (E1)    3.385    0.127   26.649    0.000    3.385    0.378
##    .qpls5mw1  (E2)    0.440    0.017   25.470    0.000    0.440    0.359
##    .typqthw1  (E3)    5.071    0.154   32.974    0.000    5.071    0.669
##    .typqfrw1  (E4)    6.246    0.222   28.187    0.000    6.246    0.427
##    .typqsaw1  (E5)    7.235    0.262   27.612    0.000    7.235    0.413
##     AlcoholUs (Vf)    3.691    0.203   18.156    0.000    1.000    1.000
## 
## Constraints:
##                                                |Slack|
##     L1 - (5-L2+L3+L4+L5)                         7.313
##     I1 - (-I2-I3-I4-I5)                          0.490
require(lavaangui)
#plot_lavaan(Figure8.4result)
Single Factor with Effects Coding
Single Factor with Effects Coding

``{r}

Fig8.5Model <- ” # Latent factor loadings (all freely estimated) AlcoholUse =~ L1alcf3mw1 + NAalcf3mw1 + start(.0.475)alcf3mw1 + L2qpls5mw1 + start(.482)qpls5mw1 + L3typqthw1 + start(.347)typqthw1 + L4typqfrw1 + start(.456)typqfrw1 + L5typqsaw1 + start(.462)*typqsaw1

# Residual variances alcf3mw1 ~~ E1alcf3mw1 qpls5mw1 ~~ E2qpls5mw1 typqthw1 ~~ E3typqthw1 typqfrw1 ~~ E4typqfrw1 typqsaw1 ~~ E5*typqsaw1

# Latent factor variance AlcoholUse ~~ Vf*AlcoholUse

# Observed means (intercepts, all freely estimated) alcf3mw1 ~ I11 qpls5mw1 ~ I21 typqthw1 ~ I31 typqfrw1 ~ I41 typqsaw1 ~ I51 AlcoholUse ~ 01 # —- Effects coding constraints —-

# Sum of squared loadings = 1 # or L1 == (1 - (L2L2) - (L3L3) - (L4L4) - (L5L5))##0.5 L1L1+L2L2+L3L3+L4L4+L5*L5==1 ” # (Transformed to z-scores so match discussion of exploratory factor analysis later) AlcUseDataZ <- as.data.frame(scale(AlcUseData)) Figure8.5result<-lavaan(Fig8.5Model, data=AlcUseDataZ, fixed.x=FALSE, missing=“FIML”) summary(Figure8.5result, standardized=TRUE, fit.measures=TRUE) require(lavaangui) #plot_lavaan(Figure8.5result)


![Single Factor with Normalized Indicators](Figure8.5.svg)

* Correlated Two Factor Model


``` r
Fig8.6Model<-"
! regressions 
   LastWeekAlc=~L4*typqfrw1
   LastWeekAlc=~L5*typqsaw1
   LastWeekAlc=~L3*typqthw1
   TypAlcUse=~L1*alcf3mw1
   TypAlcUse=~L2*qpls5mw1
! residuals, variances and covariances
   alcf3mw1 ~~ E1*alcf3mw1
   typqfrw1 ~~ E2*typqfrw1
   typqsaw1 ~~ E3*typqsaw1
   typqthw1 ~~ E4*typqthw1
   qpls5mw1 ~~ E5*qpls5mw1
   LastWeekAlc ~~ 1.0*LastWeekAlc
   TypAlcUse ~~ 1.0*TypAlcUse
   TypAlcUse ~~ r*LastWeekAlc
! observed means
   alcf3mw1~1;
   typqfrw1~1;
   typqsaw1~1;
   typqthw1~1;
   qpls5mw1~1;
"
Figure8.6result<-lavaan(Fig8.6Model, data=AlcUseData, fixed.x=FALSE, missing="FIML")
summary(Figure8.6result, standardized=TRUE, fit.measures=TRUE)
## lavaan 0.6-19 ended normally after 21 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        16
## 
##   Number of observations                          2557
##   Number of missing patterns                         1
## 
## Model Test User Model:
##                                                       
##   Test statistic                                96.646
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              5465.449
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.983
##   Tucker-Lewis Index (TLI)                       0.958
##                                                       
##   Robust Comparative Fit Index (CFI)             0.983
##   Robust Tucker-Lewis Index (TLI)                0.958
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28199.713
##   Loglikelihood unrestricted model (H1)     -28151.390
##                                                       
##   Akaike (AIC)                               56431.426
##   Bayesian (BIC)                             56524.972
##   Sample-size adjusted Bayesian (SABIC)      56474.135
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.095
##   90 Percent confidence interval - lower         0.079
##   90 Percent confidence interval - upper         0.112
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.942
##                                                       
##   Robust RMSEA                                   0.095
##   90 Percent confidence interval - lower         0.079
##   90 Percent confidence interval - upper         0.112
##   P-value H_0: Robust RMSEA <= 0.050             0.000
##   P-value H_0: Robust RMSEA >= 0.080             0.942
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.021
## 
## 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
##   LastWeekAlc =~                                                        
##     typqfrw1  (L4)    2.933    0.069   42.624    0.000    2.933    0.767
##     typqsaw1  (L5)    3.250    0.075   43.303    0.000    3.250    0.776
##     typqthw1  (L3)    1.586    0.054   29.638    0.000    1.586    0.576
##   TypAlcUse =~                                                          
##     alcf3mw1  (L1)    2.386    0.053   45.127    0.000    2.386    0.798
##     qpls5mw1  (L2)    0.895    0.019   45.954    0.000    0.895    0.809
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   LastWeekAlc ~~                                                        
##     TypAlcUse  (r)    0.967    0.010   94.379    0.000    0.967    0.967
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1          3.968    0.059   67.051    0.000    3.968    1.326
##    .typqfrw1          2.268    0.076   29.994    0.000    2.268    0.593
##    .typqsaw1          2.654    0.083   32.051    0.000    2.654    0.634
##    .typqthw1          1.077    0.054   19.783    0.000    1.077    0.391
##    .qpls5mw1          0.666    0.022   30.428    0.000    0.666    0.602
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1  (E1)    3.258    0.133   24.548    0.000    3.258    0.364
##    .typqfrw1  (E2)    6.021    0.229   26.309    0.000    6.021    0.412
##    .typqsaw1  (E3)    6.971    0.271   25.715    0.000    6.971    0.398
##    .typqthw1  (E4)    5.069    0.155   32.712    0.000    5.069    0.668
##    .qpls5mw1  (E5)    0.423    0.018   23.474    0.000    0.423    0.345
##     LastWkAlc         1.000                               1.000    1.000
##     TypAlcUse         1.000                               1.000    1.000
require(lavaangui)
#plot_lavaan(Figure8.6result)

Correlated Factor Model * Three Indicator Factor Model

Fig8.7Model<-"
! regressions 
   LastWeekAlc=~L4*typqfrw1
   LastWeekAlc=~L5*typqsaw1
   LastWeekAlc=~L3*typqthw1
! residuals, variances and covariances
   typqfrw1 ~~ E2*typqfrw1
   typqsaw1 ~~ E3*typqsaw1
   typqthw1 ~~ E4*typqthw1
   LastWeekAlc ~~ 1.0*LastWeekAlc
! observed means
   typqfrw1~1;
   typqsaw1~1;
   typqthw1~1;
"
Figure8.7result<-lavaan(Fig8.7Model, data=AlcUseData, fixed.x=FALSE, missing="FIML")
summary(Figure8.7result, standardized=TRUE, fit.measures=TRUE)
## lavaan 0.6-19 ended normally after 20 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          2557
##   Number of missing patterns                         1
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1855.408
##   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)             -19638.607
##   Loglikelihood unrestricted model (H1)     -19638.607
##                                                       
##   Akaike (AIC)                               39295.214
##   Bayesian (BIC)                             39347.833
##   Sample-size adjusted Bayesian (SABIC)      39319.237
## 
## 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
##   LastWeekAlc =~                                                        
##     typqfrw1  (L4)    3.037    0.084   36.207    0.000    3.037    0.794
##     typqsaw1  (L5)    3.246    0.091   35.495    0.000    3.246    0.775
##     typqthw1  (L3)    1.481    0.057   25.855    0.000    1.481    0.538
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .typqfrw1          2.268    0.076   29.994    0.000    2.268    0.593
##    .typqsaw1          2.654    0.083   32.051    0.000    2.654    0.634
##    .typqthw1          1.077    0.054   19.783    0.000    1.077    0.391
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .typqfrw1  (E2)    5.398    0.371   14.530    0.000    5.398    0.369
##    .typqsaw1  (E3)    6.997    0.434   16.114    0.000    6.997    0.399
##    .typqthw1  (E4)    5.392    0.171   31.530    0.000    5.392    0.711
##     LastWkAlc         1.000                               1.000    1.000
require(lavaangui)
# plot_lavaan(Figure8.7result)
Three Indicator Factor Model
Three Indicator Factor Model

Load Predicted Loss Function Values

<a href=“https://docs.google.com/document/d/1fHcWHY9iRHhYrN3abCKXKfqEPbn-G7IkzxhCv9IaF4o/edit?usp=drive_link

x <- read.table("minimization.txt",header=TRUE)

library(lattice)
library(latticeExtra)
## Warning: package 'latticeExtra' was built under R version 4.5.1
library(akima)
## Warning: package 'akima' was built under R version 4.5.1
trellis.par.set("axis.line", list(col = "transparent"))

# Base wireframe
wf <- wireframe(
  loss ~ l1 * l2, data = x,
  xlab = expression(paste(lambda)),
  ylab = expression(paste(lambda)),
  scales = list(arrows = FALSE, cex = .45, col = "black", font = 6, shade = TRUE),
  light.source = c(0, 20, 10),
  colorkey = FALSE,
  screen = list(z = -50, x = -50),
  shade.colors = function(irr, ref, height, w = 0.4)
    grey(w * irr + (1 - w) * (1 - (1 - ref)^0.4))
)

# Interpolate z value at (0.79, 0.54)
interp_surface <- with(x, interp(l1, l2, loss, duplicate = "mean"))
## Warning in interp(l1, l2, loss, duplicate = "mean"): collinear points, trying
## to add some jitter to avoid colinearities!
## Warning in interp(l1, l2, loss, duplicate = "mean"): success: collinearities
## reduced through jitter
z_val <- interp_surface$z[
  which.min(abs(interp_surface$x - 0.79)),
  which.min(abs(interp_surface$y - 0.54))
]

# Add red dot (no text label or axis tick changes)
dot_layer <- cloud(
  z_val ~ 0.79 * 0.54,
  pch = 16, cex = 1.5, col = "red",
  screen = list(z = -50, x = -50),
  xlab = NULL, ylab = NULL, zlab = NULL
)

# Combine plot and dot
wf_annotated <- wf + as.layer(dot_layer)
library(svglite)

# Open SVG device (3x3 inches)
svglite("Figure8.8svg", width = 3, height = 3)

# Print your combined plot
print(wf_annotated)

# Close device
dev.off()
## png 
##   2
Three Indicator Factor Model
Three Indicator Factor Model
  • Correlated Error Model
CorrErrmodel<-"
! regressions 
   LstWkAlcoholUse=~L1*alcf3mw1
   LstWkAlcoholUse=~L2*typqfrw1
   LstWkAlcoholUse=~L3*typqsaw1
   LstWkAlcoholUse=~L4*typqthw1
   LstWkAlcoholUse=~L5*qpls5mw1
   e1=~sde1*alcf3mw1
   e2=~sde2*qpls5mw1
! residuals, variances and covariances
   typqfrw1 ~~ E2*typqfrw1
   typqsaw1 ~~ E3*typqsaw1
   typqthw1 ~~ E4*typqthw1
   LstWkAlcoholUse ~~ 1.0*LstWkAlcoholUse
   e1 ~~ 1.0*e1
   e2 ~~ 1.0*e2
   e2 ~~ r*e1
   LstWkAlcoholUse ~~ 0.0*e1
   LstWkAlcoholUse ~~ 0.0*e2
! observed means
   alcf3mw1~1;
   typqfrw1~1;
   typqsaw1~1;
   typqthw1~1;
   qpls5mw1~1;
"
Figure8.9result<-lavaan(CorrErrmodel, data=AlcUseData, fixed.x=FALSE, missing="FIML")
summary(Figure8.9result, standardized=TRUE, fit.measures=TRUE)
## lavaan 0.6-19 ended normally after 22 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        16
## 
##   Number of observations                          2557
##   Number of missing patterns                         1
## 
## Model Test User Model:
##                                                       
##   Test statistic                                96.646
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              5465.449
##   Degrees of freedom                                10
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.983
##   Tucker-Lewis Index (TLI)                       0.958
##                                                       
##   Robust Comparative Fit Index (CFI)             0.983
##   Robust Tucker-Lewis Index (TLI)                0.958
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28199.713
##   Loglikelihood unrestricted model (H1)     -28151.390
##                                                       
##   Akaike (AIC)                               56431.426
##   Bayesian (BIC)                             56524.972
##   Sample-size adjusted Bayesian (SABIC)      56474.135
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.095
##   90 Percent confidence interval - lower         0.079
##   90 Percent confidence interval - upper         0.112
##   P-value H_0: RMSEA <= 0.050                    0.000
##   P-value H_0: RMSEA >= 0.080                    0.942
##                                                       
##   Robust RMSEA                                   0.095
##   90 Percent confidence interval - lower         0.079
##   90 Percent confidence interval - upper         0.112
##   P-value H_0: Robust RMSEA <= 0.050             0.000
##   P-value H_0: Robust RMSEA >= 0.080             0.942
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.021
## 
## 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
##   LstWkAlcoholUse =~                                                      
##     alcf3m1   (L1)      2.306    0.055   41.935    0.000    2.306    0.771
##     typqfr1   (L2)      2.933    0.069   42.624    0.000    2.933    0.767
##     typqsw1   (L3)      3.250    0.075   43.303    0.000    3.250    0.776
##     typqth1   (L4)      1.586    0.054   29.638    0.000    1.586    0.576
##     qpls5m1   (L5)      0.865    0.020   42.485    0.000    0.865    0.782
##   e1 =~                                                                   
##     alcf3m1 (sde1)      1.906    0.039   48.631    0.000    1.906    0.637
##   e2 =~                                                                   
##     qpls5m1 (sde2)      0.690    0.015   46.191    0.000    0.690    0.623
## 
## Covariances:
##                      Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   e1 ~~                                                                   
##     e2         (r)      0.107    0.030    3.527    0.000    0.107    0.107
##   LstWkAlcoholUse ~~                                                      
##     e1                  0.000                               0.000    0.000
##     e2                  0.000                               0.000    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .alcf3mw1          3.968    0.059   67.051    0.000    3.968    1.326
##    .typqfrw1          2.268    0.076   29.994    0.000    2.268    0.593
##    .typqsaw1          2.654    0.083   32.051    0.000    2.654    0.634
##    .typqthw1          1.077    0.054   19.783    0.000    1.077    0.391
##    .qpls5mw1          0.666    0.022   30.428    0.000    0.666    0.602
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .typqfrw1  (E2)    6.021    0.229   26.309    0.000    6.021    0.412
##    .typqsaw1  (E3)    6.971    0.271   25.715    0.000    6.971    0.398
##    .typqthw1  (E4)    5.069    0.155   32.712    0.000    5.069    0.668
##     LstWkAlcU         1.000                               1.000    1.000
##     e1                1.000                               1.000    1.000
##     e2                1.000                               1.000    1.000
##    .alcf3mw1          0.000                               0.000    0.000
##    .qpls5mw1          0.000                               0.000    0.000
require(lavaangui)
# plot_lavaan(Figure8.9result)

LS Loss Response Surface * Effect of zero-values

library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following object is masked from 'package:latticeExtra':
## 
##     layer
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(patchwork)
library(svglite)

# Load data
data <- read.table("singlegroupalcSIM.txt", header = TRUE)

# Composite predictor
data <- data %>%
  mutate(AlcoholUse = rowMeans(select(., alcf3mw1, typqfrw1, typqsaw1, typqthw1, qpls5mw1), na.rm = TRUE))

# Split datasets
data_all <- data
data_filtered <- data %>% filter(typqsaw1 != 0)

# Function for square plot
make_plot <- function(df, title) {
  ggplot(df, aes(x = AlcoholUse, y = typqsaw1)) +
    geom_jitter(width = 0.1, height = 0.1, alpha = 0.5) +
    geom_smooth(method = "lm", se = TRUE, color = "blue") +
    geom_smooth(method = "loess", se = TRUE, color = "red", linetype = "dashed") +
    scale_x_continuous(breaks = c(0, 2, 4, 6), limits = c(0, 6)) +
    scale_y_continuous(breaks = c(0, 5, 10, 15, 20, 25), limits = c(0, 25)) +
    labs(title = title, x = "AlcoholUse", y = "typqsaw1") +
    theme_minimal(base_size = 14) +
    coord_fixed(ratio = 1, clip = "on") +
    theme(aspect.ratio=1,
      plot.margin = margin(5, 5, 5, 5),
      plot.title = element_text(hjust = 0.5)
    )
}

# Create plots
p1 <- make_plot(data_all, "All Data")
p2 <- make_plot(data_filtered, "Excluding typqsaw1 = 0")

# Combine vertically
combined_plot <- p1 / p2  # Using patchwork

# Export combined plot as a single SVG (3" wide, 6" tall)
svglite("Figure8.10.svg", width = 6, height = 12)
print(combined_plot)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 201 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 201 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 1060 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 199 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 199 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
dev.off()
## png 
##   2
Effect of Zero Reports
Effect of Zero Reports