检索 lavaan 模型中 R 平方的 p 值

问题描述 投票:0回答:1

如何检索简单 lavaan 模型的 R 平方的 p 值?

model <- sem('criterion ~ predictor1 + predictor2', data = data, missing = "FIML", fixed.x = FALSE, se = "BOOTSTRAP", bootstrap = 5000)
summary(model, standardize = FALSE, ci = TRUE, rsquare = T)
r r-lavaan
1个回答
0
投票

使用 broom 包 tidier,您可以在数据框中提取值,包括

p.values
rsquare
op
列具有包含
r2
的附加行,以指示
estimate
列中的值是 rsquare 值。

library(lavaan)
library(broom)

model <- ' 
  # latent variable definitions
     ind60 =~ x1 + x2 + x3
     dem60 =~ y1 + a*y2 + b*y3 + c*y4
     dem65 =~ y5 + a*y6 + b*y7 + c*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)

tidy(fit, rsquare = TRUE)
#> # A tibble: 47 × 10
#>    term  op    label estimate std.error statistic p.value std.lv std.all std.nox
#>    <chr> <chr> <chr>    <dbl>     <dbl>     <dbl>   <dbl>  <dbl>   <dbl>   <dbl>
#>  1 ind6… =~    ""        1        0         NA         NA  0.670   0.920   0.920
#>  2 ind6… =~    ""        2.18     0.138     15.8        0  1.46    0.973   0.973
#>  3 ind6… =~    ""        1.82     0.152     12.0        0  1.22    0.872   0.872
#>  4 dem6… =~    ""        1        0         NA         NA  2.20    0.850   0.850
#>  5 dem6… =~    "a"       1.19     0.139      8.55       0  2.62    0.690   0.690
#>  6 dem6… =~    "b"       1.17     0.120      9.76       0  2.59    0.758   0.758
#>  7 dem6… =~    "c"       1.25     0.117     10.7        0  2.75    0.838   0.838
#>  8 dem6… =~    ""        1        0         NA         NA  2.15    0.817   0.817
#>  9 dem6… =~    "a"       1.19     0.139      8.55       0  2.56    0.755   0.755
#> 10 dem6… =~    "b"       1.17     0.120      9.76       0  2.53    0.802   0.802
#> # ℹ 37 more rows

创建于 2024-05-05,使用 reprex v2.1.0

© www.soinside.com 2019 - 2024. All rights reserved.