r - 当响应已经是有序因子时,R 显示“getY(fullmf) 中的错误:响应需要成为一个因子”
问题描述
我正在使用 ordinal 包并在 R 上使用 clmm 函数,但是尽管确保我的响应变量是序数(又名有序因子),但仍然出现以下错误:
getY(fullmf) 中的错误:响应需要成为一个因素
这是有错误的代码,还显示了 R 如何将变量“帮助”理解为有序因子。
> library(ordinal)
> hyp1.model1<-clmm(helpfulness~reflectiontype+session+(1+reflectiontype|participant),data=hyp1data)
Error in getY(fullmf):response needs to be a factor
> unique(helpfulness)
[1] 4 2 1 3 0
Levels: 0 < 1 < 2 < 3 < 4
> class(helpfulness)
[1] "ordered" "factor"
解决方案
对于 Roland 和 Ryan J Field 所说的话,我没有太多要补充的。我只是想解释一下。如果不查看您的数据,我可能完全错了。我已经使用示例数据进行了测试wine
。该模型仅在 ~ 的左侧为数字时才给出这样的错误消息。当我用数值替换其他变量时,它没有给人们任何错误消息。
您的数据中可能有两个helpfulness
:一个向量helpfulness
和一个变量。helpfulness
hyp1data
> unique(helpfulness)
[1] 4 2 1 3 0
Levels: 0 < 1 < 2 < 3 < 4
> class(helpfulness)
[1] "ordered" "factor"
只告诉向量helpfulness
是一个因子。您的变量hyp1data$helpfulness
可能仍然是数字。您可能想尝试class(hyp1data$helpfulness)
检查一下。如果不是这种情况,请告诉我。我会删除这个答案。
推荐阅读
- pandas - 为 Pandas 列编写一个可选的可执行(惰性)函数
- vue.js - 如何在 Vue.js 中将组件用作按钮
- c# - 有没有办法在一个程序集中记录所有方法?
- c# - XML Attribute to Winforms TextBox
- java - 在哪里可以找到有关 Quarkus 支持版本的信息?
- spring - Spring Cloud Data Flow 监控阻止任务完成
- python - Applying map function to OO method call
- windows - find the status of the hotfixes installed in the system using WMI/ Win32
- python - 如何通过某个步骤生成随机数?
- vue.js - Swiper doesn't work correctly when looping (last and first slides are empty)