Skip to contents

Extract relevant indirect effects indices from lavaan model through lavaan::parameterEstimates) with standardized = TRUE. In this case, the beta (B) represents the resulting std.all column.

Usage

lavaan_ind(fit, nice_table = FALSE, underscores_to_arrows = TRUE, ...)

Arguments

fit

lavaan fit object to extract fit indices from

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.

underscores_to_arrows

Logical, whether to convert underscorse to arrows in the "Indirect Effect column".

...

Arguments to be passed to rempsyc::nice_table

Value

A dataframe, including the indirect effect, corresponding paths, standardized regression coefficient, and corresponding p-value.

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"
#> 

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

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

HS.model <- write_lavaan(mediation, indirect = indirect,
                         latent = latent, label = TRUE)
cat(HS.model)
#> ##################################################
#> # [-----Latent variables (measurement model)-----]
#> 
#> visual =~ x1 + x2 + x3
#> textual =~ x4 + x5 + x6
#> speed =~ x7 + x8 + x9
#> 
#> ##################################################
#> # [-----------Mediations (named paths)-----------]
#> 
#> speed ~ visual_speed*visual
#> textual ~ visual_textual*visual
#> visual ~ ageyr_visual*ageyr + grade_visual*grade
#> 
#> ##################################################
#> # [--------Mediations (indirect effects)---------]
#> 
#> ageyr_visual_speed := ageyr_visual * visual_speed
#> ageyr_visual_textual := ageyr_visual * visual_textual
#> grade_visual_speed := grade_visual * visual_speed
#> grade_visual_textual := grade_visual * visual_textual
#> 

library(lavaan)
fit <- lavaan(HS.model, data=HolzingerSwineford1939,
              auto.var=TRUE, auto.fix.first=TRUE,
              auto.cov.lv.x=TRUE)
lavaan_ind(fit)
#>             Indirect.Effect                       Paths      B     p
#> 29   ageyr → visual → speed   ageyr_visual*visual_speed -0.152 0.001
#> 30 ageyr → visual → textual ageyr_visual*visual_textual -0.154 0.000
#> 31   grade → visual → speed   grade_visual*visual_speed  0.249 0.000
#> 32 grade → visual → textual grade_visual*visual_textual  0.253 0.000