# Data generation:

G = rnorm(200, 90, 25)
x1 = G*0.40 + rnorm(200,0,5)
x2 = G*0.18 + rnorm(200,0,10)

y1 = x1*0.75 + rnorm(200,0,2)
y2 = x1*0.35 + rnorm(200,0,4)
y3 = x1*0.15 + rnorm(200,0,10)

y4 = x2*0.88 + rnorm(200,0,7)
y5 = x2*0.44 + rnorm(200,0,5)
y6 = x2*0.31 + rnorm(200,0,9)

df2 = data.frame("y1" = c(y1),
"y2" = c(y2),
"y3" = c(y3),
"y4" = c(y4),
"y5" = c(y5),
"y6" = c(y6))
# Not measuring the latent variables

# Estimating using CFA

cfa_model = "

x1 =~ b1*y1 + b2*y2 + b3*y3
x2 =~ b4*y4 + b5*y5 + b6*y6

G =~ gamma1*x1 + gamma2*x2

"

cfa_model_fit = cfa(cfa_model, data = df2)
summary(cfa_model_fit)

# I won't evaluate the code but this does not work if you try to run it.

# Why didnâ€™t that work?

The higher order factor does not have a scale. I can give it one, however, by setting its variance to one or constraining one of the lower latent factorsâ€™ factor loading to one.

# Re-estimating:

cfa_model2 = "

x1 =~ b1*y1 + b2*y2 + b3*y3
x2 =~ b4*y4 + b5*y5 + b6*y6

G =~ gamma1*x1 + gamma2*x2

G ~~ 1*G

"

cfa_model_fit2 = cfa(cfa_model2, data = df2)
summary(cfa_model_fit2)
## lavaan (0.5-23.1097) converged normally after 125 iterations
##
##   Number of observations                           200
##
##   Estimator                                         ML
##   Minimum Function Test Statistic                8.421
##   Degrees of freedom                                 8
##   P-value (Chi-square)                           0.393
##
## Parameter Estimates:
##
##   Information                                 Expected
##   Standard Errors                             Standard
##
## Latent Variables:
##                    Estimate   Std.Err  z-value  P(>|z|)
##   x1 =~
##     y1        (b1)     1.000
##     y2        (b2)     0.451    0.077    5.864    0.000
##     y3        (b3)     0.338    0.105    3.229    0.001
##   x2 =~
##     y4        (b4)     1.000
##     y5        (b5)     0.530    0.081    6.536    0.000
##     y6        (b6)     0.445    0.085    5.259    0.000
##   G =~
##     x1      (gmm1)     1.000
##     x2      (gmm2)    34.357    7.572    4.537    0.000
##
## Variances:
##                    Estimate   Std.Err  z-value  P(>|z|)
##     G                  1.000
##    .y1                -1.136   11.147   -0.102    0.919
##    .y2                15.781    2.760    5.717    0.000
##    .y3               119.814   12.040    9.951    0.000
##    .y4                57.984   14.601    3.971    0.000
##    .y5                25.100    4.554    5.511    0.000
##    .y6                74.684    8.156    9.157    0.000
##     x1                71.371   13.228    5.396    0.000
##     x2             -1081.571  510.465   -2.119    0.034