Aan de slagGa gratis aan de slag

What did people choose?

Before we fit a model, we want to get a sense for what people choose as a function of each product attribute. The best way to do this is to count how many times a car with a particular feature is chosen. In this exercise, we are going to focus on the transmission feature and count up the number of times chosen cars have manual transmissions versus automatic using the xtabs() function.

Deze oefening maakt deel uit van de cursus

Choice Modeling for Marketing in R

Cursus bekijken

Oefeninstructies

  • Change the formula in the xtabs() function to choice ~ trans, which means "sum up the choice variable for each level of the trans variable."
  • Print the chosen_by_trans table to the console by typing its name. How many times were cars with manual transmissions chosen versus automatic?
  • Plot the chosen_by_trans object using the barplot() function.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create a table of chosen sportscars by transmission type
chosen_by_trans <- xtabs(___, data = sportscar)

# Print the chosen_by_trans table to the console


# Plot the chosen_by_trans object
barplot(___)
Code bewerken en uitvoeren