Two-Stage Path Analysis
tspa.Rd
Fit a two-stage path analysis (2S-PA) model.
Usage
tspa(
model,
data,
reliability = NULL,
se = "standard",
se_fs = NULL,
fsT = NULL,
fsL = NULL,
fsb = NULL,
...
)
Arguments
- model
A string variable describing the structural path model, in
lavaan
syntax.- data
A data frame containing factor scores.
- reliability
A numeric vector representing the reliability indexes of each latent factor. Currently
tspa()
does not support the reliability argument. Please usese
.- se
Deprecated to avoid conflict with the argument of the same name in
lavaan::lavaan()
.- 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
get_fs()
usingattr()
with the argumentwhich = "fsT"
.- fsL
A matrix of loadings and cross-loadings from the latent variables to the factor scores
fs
, which can be obtained from the output ofget_fs()
usingattr()
with the argumentwhich = "fsL"
. For details see the multiple-factors vignette:vignette("multiple-factors", package = "R2spa")
.- fsb
A vector of intercepts for the factor scores
fs
, which can be obtained from the output ofget_fs()
usingattr()
with the argumentwhich = "fsb"
.- ...
Additional arguments passed to
sem
. SeelavOptions
for a complete list.
Examples
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"]))
#> lavaan 0.6-18 ended normally after 17 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 3
#>
#> Number of observations 75
#>
#> Model Test User Model:
#>
#> Test statistic 0.000
#> Degrees of freedom 0
# 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"))
#> lavaan 0.6-18 ended normally after 21 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 6
#>
#> Number of observations 75
#>
#> Model Test User Model:
#>
#> Test statistic 0.000
#> Degrees of freedom 0
# 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")
#> lavaan 0.6-18 ended normally after 28 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 10
#>
#> Number of observations per group:
#> Pasteur 156
#> Grant-White 145
#>
#> Model Test User Model:
#>
#> Test statistic 0.000
#> Degrees of freedom 0
#> Test statistic for each group:
#> Pasteur 0.000
#> Grant-White 0.000
# 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")
#> lavaan 0.6-18 ended normally after 39 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 18
#>
#> Number of observations per group:
#> Pasteur 156
#> Grant-White 145
#>
#> Model Test User Model:
#>
#> Test statistic 0.000
#> Degrees of freedom 0
#> Test statistic for each group:
#> Pasteur 0.000
#> Grant-White 0.000
# 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")
#> lavaan 0.6-18 ended normally after 19 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 10
#> Number of equality constraints 1
#>
#> Number of observations per group:
#> Pasteur 156
#> Grant-White 145
#>
#> Model Test User Model:
#>
#> Test statistic 0.014
#> Degrees of freedom 1
#> P-value (Chi-square) 0.907
#> Test statistic for each group:
#> Pasteur 0.010
#> Grant-White 0.003
# 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")
#> lavaan 0.6-18 ended normally after 19 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 10
#> Number of equality constraints 1
#>
#> Number of observations per group:
#> Pasteur 156
#> Grant-White 145
#>
#> Model Test User Model:
#>
#> Test statistic 0.014
#> Degrees of freedom 1
#> P-value (Chi-square) 0.907
#> Test statistic for each group:
#> Pasteur 0.010
#> Grant-White 0.003