将lmer输出转换为word/excel

Mar*_*oes 1 r lme4

我正在工作R,有一个名为的包lme4.

执行模型:

lmer.rasch <- lmer(Response ~ item -1 + (1|STIDSTD),family=binomial, data=exampledata)
Run Code Online (Sandbox Code Playgroud)

让我在控制台输出,如帖子末尾所示.我想复制这个,似乎是一个表,excel,或最终说,识别单独的列和行.Ctrl-C/Ctrl-V到excel会识别行,但不识别列.

使用write.csv(lmer.rasch)给出错误:

as.data.frame.default(x [[i]],optional = TRUE)中的错误:无法将类的结构("mer",package ="lme4")强制转换为data.frame

这是包中的问题,还是我错误地使用write函数的一般问题,或者R实际上没有将此输出分成列?

    Fixed effects:
                        Estimate Std. Error z value Pr(>|z|)    
    variableamoeba       -2.7529     0.3000  -9.175  < 2e-16 ***
    variablebacterium    -2.3937     0.2244 -10.668  < 2e-16 ***
    variableleech         0.5578     0.1693   3.294 0.000987 ***
    variablecentipede     1.7012     0.1909   8.911  < 2e-16 ***
    variablelizard       -4.1836     0.4090 -10.229  < 2e-16 ***
    variabletapeworm     -1.3697     0.1841  -7.439 1.01e-13 ***
    variablehead lice     1.1803     0.1777   6.643 3.07e-11 ***
    variablemaggot        0.8819     0.1740   5.068 4.03e-07 ***
    variableant           2.5971     0.2332  11.137  < 2e-16 ***
    variablemoth          2.5389     0.2305  11.016  < 2e-16 ***
    variablemosquito      4.1270     0.3984  10.359  < 2e-16 ***
    variableearthworm    -0.3113     0.1675  -1.858 0.063106 .  
    variablecaterpillar   0.7278     0.1706   4.265 2.00e-05 ***
    variablescorpion     -3.1011     0.2748 -11.286  < 2e-16 ***
    variablesnail        -1.4499     0.1861  -7.791 6.66e-15 ***
    variablespider        0.4913     0.1681   2.923 0.003469 ** 
    variablegrasshopper   1.9167     0.1986   9.650  < 2e-16 ***
    variabledust mite     0.5767     0.1701   3.391 0.000696 ***
    variabletarantula    -0.7640     0.1734  -4.406 1.05e-05 ***
    variabletermite       1.8333     0.2007   9.136  < 2e-16 ***
    variablebat          -5.2427     0.6486  -8.083 6.33e-16 ***
    variablewasp          3.0696     0.2687  11.423  < 2e-16 ***
    variablesilkworm      1.1310     0.1792   6.313 2.74e-10 ***
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
Run Code Online (Sandbox Code Playgroud)

use*_*1_G 9

这是一种方式:

 x <- rnorm(100)
 y <- 1:100
 g <- c(rep("a",50),rep("b",50))

library(lme4)
mod1 <- glmer(y ~ x  + (1|g) )
summary(mod1)

library(memisc)
getSummary.mer(mod1)$coef
write.csv(getSummary.mer(mod1)$coef,"answer.csv")
Run Code Online (Sandbox Code Playgroud)

这应该给出我认为你想要的东西,但你的模型mer不是a matrix或者类data.frame:

 class(mod1)
[1] "mer"
attr(,"package")
[1] "lme4"

class(getSummary.mer(mod1)$coef)
[1] "matrix"
Run Code Online (Sandbox Code Playgroud)

这就是为什么你不能只是根据需要写入文件.


编辑


现在也是:

summary(mod1)$coefficients  
write.csv( summary(mod1)$coefficients )
Run Code Online (Sandbox Code Playgroud)