Example of composite in SEM

532 views
Skip to first unread message

Bob Zhang

unread,
Jul 31, 2023, 5:57:09 AM7/31/23
to lavaan
Dear colleagues, 
I am completely new to lavaan and would appreciate any help.
When I copy an example of composite from Dr. Jim Grace, and use function of summary(mod.1.fit, rsq= T, standardized=T) and R give "Error in data.frame(lhs = NAMES, op = rep("r2", nel), rhs = NAMES, block = block,  :Missing value in row name“. I don't know why the same syntax have different answers. 
Thanks for any suggestions!

library(MASS)
mu = c(10, 20)
Sigma <- matrix(c(10, 3, 3, 2), 2, 2)
set.seed(1, kind = NULL, normal.kind = NULL)
xs <- mvrnorm(n = 50, mu, Sigma)
cause1 = xs[,1]
cause2 = xs[,2]
set.seed(3, kind = NULL, normal.kind = NULL)
yerror = rnorm(50, mean=0, sd=2)
response <- 0.812*cause1 + 0.673*cause2 + yerror
sim.dat <- data.frame(cause1, cause2, response)
cor(sim.dat)

### lavaan model
library(lavaan)

## model without composite (typically as a first step)
mod.1 <- 'response ~ cause1 + cause2'
mod.1.fit <- sem(mod.1, data=sim.dat)
summary(mod.1.fit, rsq= T, standardized=T)
 Error in data.frame(lhs = NAMES, op = rep("r2", nel), rhs = NAMES, block = block,  :Missing value in row name

Christian Arnold

unread,
Jul 31, 2023, 6:26:54 AM7/31/23
to lavaan
Interesting. This is what I get:

lavaan 0.6.15 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         3

  Number of observations                            50

Model Test User Model:
                                                     
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  response ~                                                            
    cause1            0.838    0.117    7.163    0.000    0.838    0.684
    cause2            0.590    0.249    2.368    0.018    0.590    0.226

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .response          3.097    0.619    5.000    0.000    3.097    0.301

R-Square:
                   Estimate
    response          0.699


I am using lavaan 0.6.15 and R 4.1.2. Maybe there is a version problem. Maybe it helps to clear your workspace.

Bob Zhang

unread,
Jul 31, 2023, 7:34:17 AM7/31/23
to lavaan
Thank you very much for your reply. I am both new to lavaan and google group. I tried lavaan 0.6.16 and R 4.2.3 and got the same result of error. When I used "summary(mod.1.fit, standardized=T)" without "rsq = T", R gave the same result as yours without "R-Square: Estimate    response  0.699". I am still confused by this result and how to get R-Square.

Christian Arnold

unread,
Jul 31, 2023, 12:58:12 PM7/31/23
to lav...@googlegroups.com
Honestly, I never use the summary function. Maybe it is a version conflict between your and my lavaan version. If you want to get R^2, you can do something like this: lavInspect(mod.1.fit, "rsquare"). See also: https://rdrr.io/cran/lavaan/man/lavInspect.html

HTH

Christian 


Von: lav...@googlegroups.com <lav...@googlegroups.com> im Auftrag von Bob Zhang <zhangb...@gmail.com>
Gesendet: Montag, Juli 31, 2023 1:34:25 PM
An: lavaan <lav...@googlegroups.com>
Betreff: Re: Example of composite in SEM
--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/hN1y1J9fV6M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/04c63fa3-df41-4dae-adab-fa1dd2959797n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages