rregressionr-factor

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?


Solution

  • This should work :

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