simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

more probe crap #103

Closed TDJorgensen closed 2 years ago

TDJorgensen commented 3 years ago

Fix this:

dat2wayRC <- orthogonalize(dat2way, 1:3, 4:6)
dat2wayRC$g <- 1:2

model2 <- "
f1  =~ x1 + x2 + x3
f2  =~ x4 + x5 + x6
f12 =~ x1.x4 + x2.x5 + x3.x6
f3  =~ x7 + x8 + x9

f3 ~ f1 + q1*f2 + r1*f12

f12 ~~ 0*f1 + 0*f2

x1 + x4 + x1.x4 + x7 ~ 0*1 # identify latent means
f1 + f2 + f12 ~ NA*1
f3 ~ NA*1 + c(b0.g1, b0.g2)*1
"
fit2 <- sem(model2, data = dat2wayRC, group = "g")

probe2WayRC(fit2, nameX = c("f2", "f1", "f12"), nameY = "f3",
            modVar = "f2", valProbe = c(-1, 0, 1), group = 2)
## error above, not below.  Order should NOT matter
probe2WayRC(fit2, nameX = c("f1", "f2", "f12"), nameY = "f3",
            modVar = "f2", valProbe = c(-1, 0, 1), group = 2)
schoam4 commented 3 years ago

Should we rewrite explicitly asking for names of each variable as separate arguments (focal predictor, moderator, interaction and y)?

TDJorgensen commented 2 years ago

@schoam4 I'd love to, but I'm worried about backwards compatibility, and making our recent tutorial inconsistent within less than a year of publication. Yves reported another related issue (#108). I'm going to try to wrap both of these up next week.

TDJorgensen commented 2 years ago

Oh damn, turns out the problem only exists when labeling one (not both) of the main-effect parameters and the moderator is listed first in nameX=. The problem occurs (also in *MC) when creating labels for parameters that the user didn't label. What happens in the example above is that the first relevant row (regression slopes) of parTable() belongs to f1, which is nameX[2]. Because someone (ahem) designed the loop over integer indices, it made the label using nameX[1] (which is f2, which had its own label from the syntax).

Fixed by replacing nameX[i] with PT$rhs[ newRows[i] ] in all 4 probing functions: 5205cc1