【问题标题】:how to classify values into factors in r如何将值分类为r中的因子
【发布时间】:2013-06-25 12:22:05
【问题描述】:

我使用逻辑回归得到 y 的一些概率,我做了以下操作:

fit.model <- glm (y~ x1 +x2 , data = mydata, family=binomial)  
pred_model<- plogis(predict(fit.model, mydata))

现在,我想使用 0.5 的截止值将概率分类为是或否
我试过这个,但可能不起作用

class <- ifelse(pred_model>0.5, "yes" , "no" )       

有什么建议吗?

【问题讨论】:

  • 我想你可能误解了plogis 的作用。阅读?predict.glm 并尝试改用type = "response"。更一般地说,“它不起作用”并不是对您的问题的足够具体的描述。

标签: r regression r-factor


【解决方案1】:

这应该可行:

class <- factor(ifelse(pred_model>0.5, "yes", "no"), c("yes", "no"))

【讨论】:

  • 谢谢你,文森特我试过你的代码,它给出了正确的答案,感谢 Joran 的评论
  • 不客气。 :) 您现在应该回答您的问题,以便更有可能看到其他未回答的问题。 ;)
猜你喜欢
  • 1970-01-01
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 2021-03-07
  • 1970-01-01
  • 2019-07-30
  • 1970-01-01
相关资源
最近更新 更多