Get startedGet started for free

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.

This exercise is part of the course

Building Response Models in R

View Course

Exercise instructions

  • Display the relation between HOPPINESS and price.ratio by using the function plot().
  • Obtain the purchase probabilities for Hoppiness by applying the function predict() on the logistic.model with price.ratio in the data frame argument.
  • Fit a curve through the predicted data values by using the function curve().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot HOPPINESS against price.ratio
___(___, data = choice.data)

# Add the logistic response function
___(___(___, data.frame(___), type = "response"), add = TRUE)
Edit and Run Code