在序数CLMM模型中查看每个级别的系数
continue
Overview
I want to access the intercepts and coefficients for each level in a multilevel ordinal response model using the ordinal::clmm
function in R
.
I can easily do this with multilevel linear models estimated using lme4::lmer
and calling the coef
function. I can't seem to figure out how to do so with the ordinal model.
Example
Replication dataset
Below is a randomly-generated replication dataset. I create an independent variable ("indv"), a dependent variable ("depv") and an ordinal version of the dependent variable ("depv2") as well as some levels ("level").
test <- data.frame(depv = sample(1:4, 250, replace = TRUE),
indv = runif(250),
level = sample(1:4, 250, replace = TRUE)) %>%
mutate(depv2 = factor(depv, levels = 1:4, labels = c("bad", "okay", "good", "great")),
level = factor(level, levels = 1:4, labels = c("USA", "France", "China", "Brazil")))
Running the models
First, I estimate the linear model:
test1 <- lmer(depv ~ indv + (1 + indv | level), data = test)
Now, I estimate the ordinal response model:
test2 <- clmm(depv2 ~ indv + (1 + indv | level), data = test)
How to access the level coefficients?
I can easily access the level intercepts and coefficients for the linear model:
> coef(test1)
$level
(Intercept) indv
USA 2.239171 0.6238428
France 2.766888 -0.4173206
China 1.910860 1.2715852
Brazil 2.839156 -0.5599012
Doing this on the ordinal response model does not produce the same result:
> coef(test2)
bad|okay okay|good good|great indv
-1.13105544 0.09101709 1.32240904 0.37157688
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 lme4 安装的模型
test1
,呼叫coef(test1)
是在内部进行lme4 ::: coef.mermod(test1)
lme4 ::: /代码>。这是一种用户友好的例程,可以将固定效应系数和随机效应系数(条件模式)一起添加在一起。以下是此不错功能的源代码。
但是,在 ordinal 中,
coef
没有此功能。相反,它只需提取拟合模型的$系数
即可。因此,coef(test2)
与test2 $系数
一样。如果您阅读?clmm
,您会看到此向量收集alpha
(阈值参数),beta
(固定效应系数)和tau
(如果存在)。因此,要获得类似于 lme4 提供的输出,我们需要自己定义以下功能。现在,您可以为所需的输出调用
coef_ordinal(test2)
。For model
test1
fitted by lme4, callingcoef(test1)
is internally doinglme4:::coef.merMod(test1)
. This is a user-friendly routine that adds fixed-effect coefficients and random-effect coefficients (conditional mode) together. Below is the source code of this nice function.In ordinal however,
coef
does not have this functionality. Instead, it simply extracts the$coefficients
of the fitted model. Socoef(test2)
is as same astest2$coefficients
. If you read?clmm
, you will see that this vector collectsalpha
(threshold parameters),beta
(fixed-effect coefficients) andtau
(if exists). Therefore, to get an output similar to what lme4 provides, we need to define the following function ourselves.You can now call
coef_ordinal(test2)
for your desired output.