Bounded predictions
The glm() function is used because you need a response function that bounds the model predictions between zero and one. Let's illustrate this effect in a graph. But this time you need to draw a curve (instead of a straight line)!
You start with plotting the relation HOPPINESS ~ price.ratio. You can add the logistic function to the plot by using curve(). The curve() function is used to evaluate another function at x data points. Here, this function is predict()! The predict() function retrieves the coefficients of the logistic.model to make predictions about some values provided in a data frame object. The trick is to set price.ratio = x in the data.frame argument. This fits a curve through the predicted data values.
Este ejercicio forma parte del curso
Building Response Models in R
Instrucciones del ejercicio
- Display the relation between
HOPPINESSandprice.ratioby using the functionplot(). - Obtain the purchase probabilities for Hoppiness by applying the function
predict()on thelogistic.modelwithprice.ratioin the data frame argument. - Fit a curve through the predicted data values by using the function
curve().
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Plot HOPPINESS against price.ratio
___(___, data = choice.data)
# Add the logistic response function
___(___(___, data.frame(___), type = "response"), add = TRUE)