tspa | R Documentation |
Fit a two-stage path analysis (2S-PA) model.
tspa(
model,
data,
reliability = NULL,
se = "standard",
se_fs = NULL,
fsT = NULL,
fsL = NULL,
fsb = NULL,
...
)
model |
A string variable describing the structural path model,
in |
data |
A data frame containing factor scores. |
reliability |
A numeric vector representing the reliability indexes
of each latent factor. Currently |
se |
Deprecated to avoid conflict with the argument of the same name
in |
se_fs |
A numeric vector representing the standard errors of each factor score variable for single-group 2S-PA. A list or data frame storing the standard errors of each group in each latent factor for multigroup 2S-PA. |
fsT |
An error variance-covariance matrix of the factor scores, which
can be obtained from the output of |
fsL |
A matrix of loadings and cross-loadings from the
latent variables to the factor scores |
fsb |
A vector of intercepts for the factor scores |
... |
Additional arguments passed to |
An object of class lavaan
, with an attribute tspaModel
that contains the model syntax.
library(lavaan)
# single-group, two-factor example, factor scores obtained separately
# get factor scores
fs_dat_ind60 <- get_fs(data = PoliticalDemocracy,
model = "ind60 =~ x1 + x2 + x3")
fs_dat_dem60 <- get_fs(data = PoliticalDemocracy,
model = "dem60 =~ y1 + y2 + y3 + y4")
fs_dat <- cbind(fs_dat_ind60, fs_dat_dem60)
# tspa model
tspa(model = "dem60 ~ ind60", data = fs_dat,
se_fs = c(ind60 = fs_dat_ind60[1, "fs_ind60_se"],
dem60 = fs_dat_dem60[1, "fs_dem60_se"]))
# single-group, three-factor example
mod2 <- "
# latent variables
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
"
fs_dat2 <- get_fs(PoliticalDemocracy, model = mod2, std.lv = TRUE)
tspa(model = "dem60 ~ ind60
dem65 ~ ind60 + dem60",
data = fs_dat2,
fsT = attr(fs_dat2, "fsT"),
fsL = attr(fs_dat2, "fsL"))
# multigroup, two-factor example
mod3 <- "
# latent variables
visual =~ x1 + x2 + x3
speed =~ x7 + x8 + x9
"
fs_dat3 <- get_fs(HolzingerSwineford1939, model = mod3, std.lv = TRUE,
group = "school")
tspa(model = "visual ~ speed",
data = fs_dat3,
fsT = attr(fs_dat3, "fsT"),
fsL = attr(fs_dat3, "fsL"),
group = "school")
# multigroup, three-factor example
mod4 <- "
# latent variables
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
"
fs_dat4 <- get_fs(HolzingerSwineford1939, model = mod4, std.lv = TRUE,
group = "school")
tspa(model = "visual ~ speed
textual ~ visual + speed",
data = fs_dat4,
fsT = attr(fs_dat4, "fsT"),
fsL = attr(fs_dat4, "fsL"),
group = "school")
# get factor scores
fs_dat_visual <- get_fs(data = HolzingerSwineford1939,
model = "visual =~ x1 + x2 + x3",
group = "school")
fs_dat_speed <- get_fs(data = HolzingerSwineford1939,
model = "speed =~ x7 + x8 + x9",
group = "school")
fs_hs <- cbind(do.call(rbind, fs_dat_visual),
do.call(rbind, fs_dat_speed))
# tspa model
tspa(model = "visual ~ speed",
data = fs_hs,
se_fs = data.frame(visual = c(0.3391326, 0.311828),
speed = c(0.2786875, 0.2740507)),
group = "school",
group.equal = "regressions")
# manually adding equality constraints on the regression coefficients
tspa(model = "visual ~ c(b1, b1) * speed",
data = fs_hs,
se_fs = list(visual = c(0.3391326, 0.311828),
speed = c(0.2786875, 0.2740507)),
group = "school")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.