【问题标题】:How to extract LME4 output to latex tables?如何将 LME4 输出提取到乳胶表?
【发布时间】:2020-12-13 10:11:27
【问题描述】:

我通常使用modelsummary()stargazer() 将表格提取到 R 中的乳胶。但是,它们似乎不适用于 lme4。有人知道如何将这个可重现的示例提取到一个漂亮的乳胶表中吗?

这是我的模型:

df <- tibble(
      y = rnorm(100000),
      x1 = rnorm(100000),
      x2 = rnorm(100000),
      school =sample.int(300,size=100000,replace=TRUE)-1,
      classes =sample.int(100,size=100000,replace=TRUE)-1
      )
    
    df$school = as.factor(df$school)
    df$classes = as.factor(df$classes)
    
    library(lme4)
    model1 <- lmer(y~ x1 + x2 +  
                  (x1 + x2 |classes) +
                  (x1 + x2 |school), data=df)

【问题讨论】:

    标签: r lme4 stargazer broom modelsummary


    【解决方案1】:

    从 0.6.4 版开始(现在在 CRAN 上),modelsummary 支持开箱即用的 lme4::lmer 模型。您只需更新您的软件包并重试。

    update.packages("modelsummary")
    
    library(lme4)
    library(modelsummary)
    
    N <- 1000
    df <- data.frame(
          y = rnorm(N),
          x1 = rnorm(N),
          x2 = rnorm(N),
          school =sample.int(300,size=N,replace=TRUE)-1,
          classes =sample.int(100,size=,replace=TRUE)-1)
        
    df$school = as.factor(df$school)
    df$classes = as.factor(df$classes)
        
    model1 <- lmer(y~ x1 + x2 +  
                  (x1 + x2 |classes) +
                  (x1 + x2 |school), data=df)
    
    modelsummary(model1, "markdown")
    
    |            |  Model 1  |
    |:-----------|:---------:|
    |(Intercept) |   0.009   |
    |            |  (0.036)  |
    |x1          |  -0.037   |
    |            |  (0.032)  |
    |x2          |   0.042   |
    |            |  (0.033)  |
    |Num.Obs.    |   1000    |
    |R2 Marg.    |   0.003   |
    |R2 Cond.    |           |
    |AIC         |  2858.0   |
    |BIC         |  2936.6   |
    |Log.Lik.    | -1413.013 |
    

    【讨论】:

    【解决方案2】:

    就是为此而存在的。

    library(texreg)
    texreg(model1)
    

    或者,您可以使用 tab_model() 并将 html 输出转换为乳胶(未经测试)。

    library(sjPlot)
    model_html <- tab_model(model1)
    
    library(rrtable)
    HTMLcode2latex(model_html$page.content)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多