我正在嘗試在 lmer 資料集上運行 emmeans 函式,但它不起作用。這是我的資料:
structure(list(Date = structure(c(16578, 16578, 16578, 16578,
16578, 16578), class = "Date"), Time = c(7, 7, 7, 9, 11, 11),
Turtle = c("R3L12", "R3L12", "R3L12", "R3L12", "R3L12", "R3L12"
), Tex = c(11.891, 12.008, 12.055, 13.219, 18.727, 18.992
), m.Tb = c(12.477, 12.54, 12.54, 12.978, 16.362, 16.612),
m.HR = c(7.56457, 6.66759, 17.51107, 9.72277, 19.44553, 13.07674
), season = c("beginning", "beginning", "beginning", "beginning",
"beginning", "beginning"), year = c(2015L, 2015L, 2015L,
2015L, 2015L, 2015L), Mass = c(360L, 360L, 360L, 360L, 360L,
360L)), row.names = c(NA, 6L), class = "data.frame")
模型代碼: model1 <- lmer(m.HR ~ season (1|Time) (1|Date) (1|Turtle), turtledata)
emmeans 代碼:
model1.emmeans <- emmeans(model1, "Turtle")
這些是我得到的錯誤:
To enable adjustments, add the argument 'pbkrtest.limit = 20608' (or larger)
[or, globally, 'set emm_options(pbkrtest.limit = 20608)' or larger];
but be warned that this may result in large computation time and memory use.
Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
To enable adjustments, add the argument 'lmerTest.limit = 20608' (or larger)
[or, globally, 'set emm_options(lmerTest.limit = 20608)' or larger];
but be warned that this may result in large computation time and memory use.
Error in emmeans(model1, "Turtle") :
No variable named Turtle in the reference grid
我不確定為什么它說沒有 Turtle,因為它是我資料集中的一個字符變數。
基本上,我只是想讓 emmeans 運行,但我也擔心它不會運行,因為完整的資料集有 20,000 行長。
uj5u.com熱心網友回復:
emmeans固定效應(被操縱的東西)的功能測驗,而不是隨機效應(由于設計而發生的東西)。以下示例顯示了這一點,也是一種創建最小可重現示例的方法:
library(emmeans)
library(lme4)
# some artificial data
set.seed(143)
foo <- data.frame(
m.HR <- rnorm(100, mean=c(rep(c(5, 6), 25), rep(c(8, 9), 25))),
season <- rep(c("a", "b"), each=50),
Turtle <- rep(c("T1", "T2"), 50)
)
# simplified model with one fixed and one raqndom effect
model1 <- lmer(m.HR ~ season (1|Turtle), foo)
(model1.emmeans <- emmeans(model1, "Turtle"))
# --> error as Turtle is a random effect
(model1.emmeans <- emmeans(model1, "season"))
# --> works as season is a fixed effect
#season emmean SE df lower.CL upper.CL
#a 5.73 0.535 1.07 -0.0567 11.5
#b 8.61 0.535 1.07 2.8254 14.4
#
#Degrees-of-freedom method: kenward-roger
#Confidence level used: 0.95
更多關于隨機與固定的討論可以在Cross Validated 中找到。
uj5u.com熱心網友回復:
你不一定能emmeans直接做你想做的事,但某種合理的計算是可能的。
最簡單的方法是獲得每只海龜的平均預測,并使用跨季節的平均值:
ref_grid <- with(turtledata,
expand.grid(season=unique(season), turtle=unique(Turtle)))
pp <- predict(model1, newdata = ref_grid)
aggregate(pp, by=ref_grid$turtle, FUN=mean)
置信區間更難...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/312490.html
上一篇:如何在data.table中鏈接group_by、filter、distinct、count?
下一篇:帶有排序值的geom_bar()
