使用多项式项计算 lmer 模型的边际效应

Calculating marginal effects of a lmer model with polynomial terms

我正在尝试使用 lme4 量化混合模型中变量的影响大小,但我似乎无法让它与创建非线性的 poly() 函数一起使用两个变量之间的相互作用。

library(lme4)
library(lmerTest)
library(readr)

mydata <- read_csv("https://raw.githubusercontent.com/HaydenSchilling/Example_code_and_data/master/example_data2.csv")

m1 <- lmer(CPUE.standardised ~ poly(cbind(X135_degree_winds.standardised, 
       X45_degree_winds.standardised), degree = 2) + 
       Estuary_Type * Drought_Months + (1|Estuary), data = mydata)

anova(m1)
summary(m1)

library(ggeffects)
ggpredict(m1, terms = "X135_degree_winds.standardised")

最后一行报错:

Error: Can't find column cbind in .data. Call rlang::last_error() to see a backtrace

我已经尝试了 ggeffectssjPlot 包,但是 运行 都遇到了 cbind 命令的问题或者找不到指定的变量。如果有人有任何解决方案,我将不胜感激!

根据收到的评论回答我自己的问题。问题出在多项式中的 cbind 命令。解决方案是将模型结构更改为不包含 cbind.

与原始问题中的模型等效的模型是:

m2 <- lmer(CPUE.standardised ~ poly(X135_degree_winds.standardised, degree = 2) + 
   poly(X45_degree_winds.standardised, degree = 2) + 
   X135_degree_winds.standardised:X45_degree_winds.standardised+ 
   Estuary_Type * Drought_Months + (1|Estuary), data = mydata)

这样就可以计算边际效应了。

改进的模型结构也被建议为:

poly(X135_degree_winds.standardised, degree = 2)*
 poly(X45_degree_winds.standardised, degree = 2)