作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试执行具有随机效应的逐步模型,其中我可以获得 BIC 值。
lmerTest 包说它适用于 lme4,但只有从模型中删除我的一个自变量(这是一个具有两个选项 (TM) 的因素),我才能让它工作
错误代码是:
Error in
$<-
(*tmp*
, formula, value = Terms) : no method for assigning subsets of this S4 class
Error in as_lmerModLmerTest(model) : model not of class 'lmerMod': cannot coerce to class 'lmerModLmerTest
full.model <- lme4::lmer(dep ~ TM + ind + (1 | dorp), data=test) #lmerTest:: give same outcome
step.model<- lmerTest::step(full.model, direction="both",k=log(16)) # n=16
summary(step.model)
BIC(step.model)
#Example dataset
test <- data.frame(TM = as.factor(c(rep("org", 3), rep("min", 3),rep("org", 3), rep("min", 3),rep("org", 3), rep("min", 3))),
dep = runif(18,0,20),
ind = runif(18,0,7),
dorp = as.factor(c(rep(1,6),rep(2,6),rep(3,6))))
最佳答案
问题是lmerTest::step.lmerModLmerTest
在随机效应选择阶段从模型中消除所有随机效应时中断。它可能不应该(我认为该包的早期版本可能不会),但解决这个问题并不太难。您可以指定不应简化随机效应模型 ( step(full.model, reduce.random=FALSE)
),或者,当您遇到此错误时,丢弃模型的随机效应分量,然后使用 step()
在得到的线性模型上:
fixmodel <- lm(formula(full.model,fixed.only=TRUE),
data=eval(getCall(full.model)$data))
step(fixmodel)
eval()
,这仅适用于 R 可以找到由
data=
参数引用的数据框的环境)。
stats::step
与
step.lmerModLmerTest
有不同的论点/做出不同的假设在
lmerTest
包裹。
stats::step
被定义为
step(object, scope, scale = 0,
direction = c("both", "backward", "forward"),
trace = 1, keep = NULL, steps = 1000, k = 2, ...)
step.lmerModLmerTest
用途
step(object, ddf = c("Satterthwaite",
"Kenward-Roger"), alpha.random = 0.1, alpha.fixed = 0.05,
reduce.fixed = TRUE, reduce.random = TRUE, keep, ...)
direction
参数不适用(
step.lmerModLmerTest
仅进行向后消除);不是
k
(我相信
step.lmerModLmerTest
使用 AIC,但我必须仔细检查)。
set.seed(1001)
dd <- data.frame(x1=rnorm(500),x2=rnorm(500),
x3=rnorm(500),f=factor(rep(1:50,each=10)))
library(lme4)
dd$y <- simulate(~x1+x2+x3+(1|f),
newdata=dd,
newparams=list(theta=1,beta=c(1,2,0,0),
sigma=1),
family=gaussian)[[1]]
library(lmerTest)
full.model <- lmer(y~x1+x2+x3+(1|f), data=dd)
step.model<- step(full.model)
step.model
有课
step_list
;有打印方法,但没有摘要方法。
关于r - 如何使用随机效应进行逐步模型(lme4 + lmerTest?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638476/
图像显示,但不转换。 CSS 代码显示在上传的页面上。 我正在使用 EverWeb 构建页面。 下面是我正在尝试的代码。提前致谢。 HTML 片段 CSS .image { width: 100
我是一名优秀的程序员,十分优秀!