简体   繁体   English

如何使用broom :: tidy()从lme4 :: lmer()创建的线性混合效果模型中计算p值?

[英]How to calculate p-value from a linear mixed effect model created by lme4::lmer() using broom::tidy()?

I have a built a mixed effect model using the lmer() function from the lme4 package. 我使用lme4包中的lmer()函数构建了一个混合效果模型。 The lme4 package does not output the p-value of the coefficients for some good philosophical reason. lme4软件包出于某些良好的哲学原因不会输出系数的p值。 However, I still need p-values to report in my publication. 但是,我仍然需要p值才能在出版物中进行报告。 I know there are multiple ways to calculate p-values using the model created by lmer() , eg here . 我知道有多种方法可以使用lmer()创建的模型来计算p值,例如here

My problem is: I want to extract p-value using the tidy() function from the broom package. 我的问题是:我想从broom包中使用tidy()函数提取p值。 Here, I really want to stick with tidy() because I want to maintain the following pipeline: 在这里,我真的想坚持使用tidy()因为我想维护以下管道:

data_frame %>% group_by(grouping variables) %>% do(tidy(fitted_model))

One option would be to create a custom function and append it to the pipeline. 一种选择是创建一个自定义函数,并将其附加到管道中。 However, the man page of the broom package ( http://rpackages.ianhowson.com/cran/broom/man/lme4_tidiers.html ) says: 但是, broom软件包的手册页( http://rpackages.ianhowson.com/cran/broom/man/lme4_tidiers.html )说:

"p.value  P-value computed from t-statistic (may be missing/NA)". 

By this I am assuming a function to calculate p-value from the t-value given by lmer model has already been implemented in broom. 这样,我假设已经在扫帚中实现了根据lmer模型给出的t值计算p值的函数。 So, I am reluctant to reinvent the wheel. 因此,我不愿意重新发明轮子。

The problem is I don't get the column with name p.value at all. 问题是我根本没有得到名称为p.value的列。 I was expecting a column named p.value with NAs as the worst case scenario. 我原本以为最坏的情况是NA称为p.value的列。

Code: 码:

library(lme4)
library(broom)
lme <- lmer(Reaction ~ Days + (1 + Days | Subject), sleepstudy)
tidy(lme)
tidy(lme, effects = "fixed")

Output: 输出:

> tidy(lme)
                         term     estimate std.error statistic    group
1                  (Intercept) 251.40510485  6.824557 36.838306    fixed
2                         Days  10.46728596  1.545789  6.771485    fixed
3       sd_(Intercept).Subject  24.74045195        NA        NA  Subject
4              sd_Days.Subject   5.92213312        NA        NA  Subject
5 cor_(Intercept).Days.Subject   0.06555113        NA        NA  Subject
6      sd_Observation.Residual  25.59181564        NA        NA Residual
> tidy(lme, effects = "fixed")
         term  estimate std.error statistic
1 (Intercept) 251.40510  6.824557 36.838306
2        Days  10.46729  1.545789  6.771485

You will need package lmerTest to obtain p-values. 您将需要包lmerTest来获取p值。 tidy will not work on the lme object and you will need to append it to your format. tidy不适用于lme对象,您需要将其附加到格式中。

attach(mtcars)
lme <- lmer(mpg ~ cyl + (1 + cyl | carb), mtcars)
summary(lme)

您可以使用sjstats::p_value()从许多不同的模型(包括(通用)混合模型sjstats::p_value()中获取p值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM