简体   繁体   中英

how to classify values into factors in r

I used logistic regression to get some probabilities of y, I did the following:

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

Now, I want to classify the probabilities using a cut off value of 0.5 to yes or no
I tried this, but doesn't work probably

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

Any suggestions?

这应该工作:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM