Aan de slagGa gratis aan de slag

Understanding dummy variables

Selling craft beer is highly competitive. Increasing in-store visibility usually generates additional sales. Therefore, the brewery makes use of point-of-sales display ads. The volume sales of Hoppiness were recorded for all weeks with and without displays.

It is useful to start with examining log(SALES) separately for DISPLAY and no-DISPLAY activities. You can do this by using the function aggregate(). The aggregate() function can also operate on formula statements, a feature making its usage quite handy. Here, log(SALES) ~ DISPLAY groups log(SALES) according to the levels in DISPLAY. The function argument FUN applies a specified function to each level. Again, you calculate some simple descriptive measures using the functions mean(), min() and max().

Deze oefening maakt deel uit van de cursus

Building Response Models in R

Cursus bekijken

Oefeninstructies

  • Calculate the mean of log(SALES) for each level in DISPLAY.
  • Calculate the minimum of log(SALES) for each level in DISPLAY.
  • Calculate the maximum of log(SALES) for each level in DISPLAY.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Mean log(SALES)
aggregate(___ ~ ___, FUN = ___, data = sales.data)

# Minimum log(SALES)
aggregate(___, FUN = ___, data = sales.data)

# Maximum log(SALES)
___(___, FUN = ___, data = sales.data)
Code bewerken en uitvoeren