解释估计的边际均值(emmans aka lsmeans):负响应值

时间:2019-03-08 10:57:30

标签: r lme4 emmeans

我正在使用lmer建立模型,希望通过emmeans库获得估计的边际均值。这是我的数据框:

df <- structure(list(treatment = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L), .Label = c("CCF", "UN"), class = "factor"), level = structure(c(2L, 
3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 
4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 
2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 
3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 
4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 
2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 
3L, 4L, 2L, 3L, 4L, 2L, 3L, 4L), .Label = c("A", "F", "H", "L"
), class = "factor"), random = structure(c(3L, 3L, 3L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 4L, 
4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L), .Label = c("1.6", "2", "3.2", "5", NA), class = "factor"), 
    continuous = c(72.7951770264767, 149.373765810534, 1.64153094886205, 
    54.6697408615215, 25.5801835808851, 1.45794117443253, 25.3660934894788, 
    91.2321704897132, 2.75353217433675, 44.1995276851725, 33.1854545470435, 
    5.36536076058866, 29.6807620242672, 80.6077496067764, 0.833434180091457, 
    13.6789475327185, 77.4930412025109, 3.65998714174906, 25.2848344605563, 
    136.632099849828, 2.56715261161435, 28.6733878840584, 66.800616194317, 
    1.37475468782539, 23.007491380183, 84.980285774607, 1.13569710795522, 
    33.8610875632139, 56.1234827517798, 1.32327007970416, 60.0843812879313, 
    43.4487832450889, 1.14942423621912, 53.6673704529947, 146.746167255051, 
    3.91593723271292, 27.0321687961004, 89.5925729244878, 1.47707078226047, 
    44.0523211310831, 115.087908243373, 1.94039630728038, 86.4074806697431, 
    43.3266206881612, 2.81456503996437, 66.868588961071, 229.797526052566, 
    1.07971524769264, 30.3390107111747, 116.680801084036, 1.67711446647817, 
    69.0961010697534, 78.5454363192614, 1.92137892126384, 53.5708546850303, 
    37.7175476710608, 1.96087397451467, 25.5166981770257, 37.3755071788757, 
    2.21602000526086, 10.3266195584378, 38.1458490762217, 2.7508022340832, 
    44.5864920143771, 8.45382647692274, 2.63204944520792, 87.5376946978593, 
    27.2354119098268, 3.38134648323956, 26.8815471706502, 14.5539972194568, 
    2.0556994322415, 27.4619977737491, 32.8546665896602, 2.66809379088059, 
    42.3815445857533, 21.3359802201685, 2.19167325121191, 53.3189825439001, 
    13.5708790223439, 2.22274607227071, 88.297423835906, 8.50554349658773, 
    3.5764241495006, 29.284865737912, 21.1213079519954, 2.3070166819956, 
    10.7659615128225, 33.4813413290485, 2.49896565066211, 59.0935696616465, 
    13.2863515051715, 4.36424795471221, 72.1627847396763, 9.09326343200557, 
    2.13701784901259, 27.5824079679471, 8.84486812842272, 1.98293342019671, 
    17.5321126287485, 19.1806349705231, 5.03952187899644, 58.3473975730234, 
    9.17287686145614, 2.99575072457674)), class = "data.frame", row.names = c(NA, 
105L))

这是我的模特

library(lme4)
    model <- lmer((continuous) ~  treatment + level + (1|random), data= df, REML = TRUE)

目前的数据不符合模型假设,但是我仍然想知道为什么在“ UN”级别“ L”(请参见lettering表)上得到负的估计边际均值(响应) df$continuous中没有负数吗?

library(multcompView)
library(emmeans)
lsm.mixed_C <- emmeans::emmeans(my_model,pairwise ~  treatment * level, type="response")
lettering <- CLD(lsm.mixed_C,alpha=0.05,Letters=letters,
                         adjust= "tukey")

1 个答案:

答案 0 :(得分:1)

简短的答案是因为您非常需要在模型中包括交互。比较:

model2 <- lmer((continuous) ~  treatment * level + (1|random), 
               data= df, REML = TRUE)
emmip(model2, treatment ~ level)

enter image description here

具有:

emmip(model, treatment ~ level)

enter image description here

model2中,级别L的两个EMM都接近于零。如果您从模型中删除了互动,则将这两个配置文件强制平行,同时在处理CCFUN之间保持可观的正差异,从而迫使UN的估算值变为负数。不过,实际上,treatment x level组合的所有六个估计都严重失真。

我重复的不够。 emmeans()总结了一个模型。如果给它一个不好的模型,您会得到愚蠢的结果。感谢您对这一点的详尽说明。