How can I retrieve the p-value of the overall significance of a simple lavaan model?
Just similar to the p-value for the F-statistic in standard linear regression done with lm().
model <- sem('criterion ~ predictor1 + predictor2', data = data, missing = "FIML", fixed.x = FALSE, se = "BOOTSTRAP", bootstrap = 5000)
summary(model, standardize = FALSE, ci = TRUE, rsquare = T)
EDIT: here's sample data
structure(list(predictor1 = c(1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1,
NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, NA, 0, 0, 1,
0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, NA, 1, 1, 0, 1, 1,
NA, 1, 0, 1, 1, 1, 1, 0, 1), predictor2 = c(23.09, 26.19, 22.77,
19.56, 21.38, NA, 22.55, 21.06, 22.13, 24.05, 21.06, 23.94, 22.78,
21.38, 20.74, 23.52, 23.41, 21.16, 22.34, 23.94, 22.45, 21.06,
21.16, 20.2, 20.52, 23.19, 26.4, 22.34, 25.12, 23.09, 22.34,
23.3, 23.19, 29.07, 23.19, 25.12, 22.66, 23.19, 22.77, 26.19,
21.27, 23.3, 21.48, 23.73, 23.3, 21.48, 21.81, 24.16, 23.19,
22.34, 21.59, 21.27, 25.23, 22.66, 24.05, 26.29, 23.19, 22.77,
23.84, 23.19), criterion = c(1.97, 1.15, 0, -1.18, -0.15, 1.42,
0, 2.19, 2.5, 1.08, 2.15, 0.27, 0.49, -0.15, 0.7, -6.93, 0.13,
1.94, 2.09, -0.26, 0.9, 1.94, 2.26, 0.77, -1.02, 0.48, 0, 0.28,
1.41, 1.17, 0, 0, 2.59, 4.78, 2.59, 1.16, 1.1, 1.07, -1.62, 1.1,
0, 0, 0.35, 1.07, 0.33, -0.29, 2.12, -1.4, 0.9, 0, 5.28, -0.94,
-1.2, 0.67, 0.72, 0, 3.13, 0, 0.62, 0.84)), row.names = c(NA,
60L), class = "data.frame")
There are a couple of options that you can try! Instead of fiddling with accessing elements of an S4 object you can pass it to summary first. The other option is letting purrr::pluck
do the dirty work.
library(lavaan)
#> This is lavaan 0.6-17
#> lavaan is FREE software! Please report any bugs.
library(tidyverse)
data(PoliticalDemocracy, package = 'lavaan')
model <- '
# measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
# residual correlations
y1 ~~ y5
y2 ~~ y4 + y6
y3 ~~ y7
y4 ~~ y8
y6 ~~ y8'
fit = sem(model, data = PoliticalDemocracy, missing = "FIML")
tidyish_way = fit |>
pluck('test', 'standard', 'pvalue')
base_way = summary(fit, standardize = FALSE,
ci = TRUE, rsquare = TRUE)$test$standard$pvalue
print(tidyish_way)
#> [1] 0.3291804
print(base_way)
#> [1] 0.3291804
summary(fit)
#> lavaan 0.6.17 ended normally after 68 iterations
#>
#> Estimator ML
#> Optimization method NLMINB
#> Number of model parameters 31
#>
#> Number of observations 75
#>
#> Model Test User Model:
#>
#> Test statistic 38.125
#> Degrees of freedom 35
#> P-value (Chi-square) 0.329
Created on 2024-05-14 with reprex v2.1.0