考虑以下数据框和 glmer 模型:
数据框
hunger <- sample(x = 0:1, size = 50, replace = TRUE)
treat <- sample(x = c("A1","A2"), prob = c(.75, .25), size = 50, replace = TRUE)
owner <- sample(x = c("Alice","Ben"), prob = c(.5, .5), size = 50, replace = TRUE)
animal <- sample(x = c("d","cat","cow"), prob = c(.33, .33, .33), size = 50, replace = TRUE)
df <- as.data.frame(cbind(animal,treat,owner,hunger))
df$hunger <- as.numeric(df$hunger)
df$animal <- as.factor(df$animal)
型号
testM <- glmer(hunger ~ animal + treat + animal*treat +
(1 + animal + treat + animal*treat||owner), data = df, family="binomial", glmerControl(optimizer="bobyqa", optCtrl = list(maxfun=1e5)))
summary(testM)
我使用
ggcoef_model
来可视化模型:
ggcoef_model(testM, include = !contains(c("owner","Residual.sd")))
这产生了情节:
正如我们在“动物”下看到的,其中一个级别被命名为“d”。
(1) 如何将此标签更改为“狗”?
(2)此外,我还想将“A1”级别的可视化隐藏在“treat”下。
(3) 如何隐藏变量的特定级别?
我可以看到这里有一些操作变量标签的方法(即通过 set_variable_labels(treat = "Treat for the Animal")),但是如何操作变量内级别的标签?
对于问题1,你只需更改我的意思是动物的名字:
animal <- sample(x = c("dog","cat","cow"), prob = c(.33, .33, .33), size = 50, replace = TRUE)
我用狗代替了d。
对于问题2,可以添加设置 no_reference_row = "var where you要删除"
ggcoef_model(testM, include = !contains(c("owner","Residual.sd")),no_reference_row = "treat")
对于问题3,我不确定我的理解是否充分,我需要知道你到底想做什么?