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 exercício faz parte do curso
Building Response Models in R
Instruções do exercício
- Display the relation between
HOPPINESS
andprice.ratio
by using the functionplot()
. - Obtain the purchase probabilities for Hoppiness by applying the function
predict()
on thelogistic.model
withprice.ratio
in the data frame argument. - Fit a curve through the predicted data values by using the function
curve()
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Plot HOPPINESS against price.ratio
___(___, data = choice.data)
# Add the logistic response function
___(___(___, data.frame(___), type = "response"), add = TRUE)