How "type" attribute affect the logistic model in R

r
logistic_regression

#1

I am working on logistic model in R and while predicting results of my model I am getting different values when I am using type attribute in predication

without type attribute in predication
predict(model1,newdata)
1
-1.174136

with type attribute in predication
predict(model1,newdata,type=“response”)
1
0.2361081

I am not able to understand why I am getting different result??


#2

Can you elaborate further by sharing your code and objective. Explaining what you are trying to do ?


#3

I am trying to develop the model of logistic regression on the data set of mtcars in r
data(mtcars)
names(mtcars)
model1<-glm(formula=vs~wt+disp,data=mtcars,family=“binomial”)
newdata<-data.frame(wt=2.1,disp=180)
predict(model1,newdata,type=“response”)
currently I have written the type=“response” but I am getting different result when I not include it


#4

Okay here is it.

type
" the type of prediction required. The default is on the scale of the linear predictors; the alternative “response” is on the scale of the response variable. Thus for a default binomial model the default predictions are of log-odds (probabilities on logit scale) and type = “response” gives the predicted probabilities. The “terms” option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale."

I picked this up from https://stat.ethz.ch/R-manual/R-devel/library/stats/html/predict.glm.html

You would need to use response because the predicted probability is what we are interested in.
Now you would need to put a cut off for it , 0.5 being the default. If the predicted probability is lower than 0.5 then 0 else 1.

Which in this case makes your prediction from model as “0”.

You might want to read about logistic regression a bit, you will then be able to make sense about what I wrote. Let me know if things are still not clear.