Skip to contents

Extract relevant regression indices from lavaan model through lavaan::parameterEstimates with standardized = TRUE. In this case, the beta (B) represents the resulting std.all column. See "Value" section for more details.

Usage

lavaan_reg(fit, estimate = "B", nice_table = FALSE, ...)

Arguments

fit

lavaan fit object to extract fit indices from

estimate

What estimate to use, either the standardized estimate ("B", default), or unstandardized estimate ("b").

nice_table

Logical, whether to print the table as a rempsyc::nice_table as well as print the reference values at the bottom of the table.

...

Arguments to be passed to rempsyc::nice_table

Value

A dataframe, including the outcome ("lhs"), predictor ("rhs"), standardized regression coefficient ("std.all"), corresponding p-value, as well as the unstandardized regression coefficient ("est") and its confidence interval ("ci.lower", "ci.upper").

Examples

(latent <- list(
  visual = paste0("x", 1:3),
  textual = paste0("x", 4:6),
  speed = paste0("x", 7:9)
))
#> $visual
#> [1] "x1" "x2" "x3"
#> 
#> $textual
#> [1] "x4" "x5" "x6"
#> 
#> $speed
#> [1] "x7" "x8" "x9"
#> 

(regression <- list(
  ageyr = c("visual", "textual", "speed"),
  grade = c("visual", "textual", "speed")
))
#> $ageyr
#> [1] "visual"  "textual" "speed"  
#> 
#> $grade
#> [1] "visual"  "textual" "speed"  
#> 

HS.model <- write_lavaan(latent = latent, regression = regression)
cat(HS.model)
#> ##################################################
#> # [-----Latent variables (measurement model)-----]
#> 
#> visual =~ x1 + x2 + x3
#> textual =~ x4 + x5 + x6
#> speed =~ x7 + x8 + x9
#> 
#> ##################################################
#> # [---------Regressions (Direct effects)---------]
#> 
#> ageyr ~ visual + textual + speed
#> grade ~ visual + textual + speed
#> 

library(lavaan)
fit <- sem(HS.model, data = HolzingerSwineford1939)
lavaan_reg(fit)
#>    Outcome Predictor     p      B CI_lower CI_upper
#> 10   ageyr    visual 0.513 -0.058   -0.230    0.115
#> 11   ageyr   textual 0.000 -0.304   -0.437   -0.171
#> 12   ageyr     speed 0.000  0.354    0.208    0.500
#> 13   grade    visual 0.818  0.020   -0.150    0.189
#> 14   grade   textual 0.148  0.099   -0.035    0.233
#> 15   grade     speed 0.000  0.389    0.248    0.531