How to lag?
Possibly, customers do not immediately react to price reductions of Hoppiness. Therefore, it is important to check if the effect of price promotion might extend to the next week. You can do this by adding lags into your model.
Lagging a variable means shifting the time base back by a given number of observations. This can be done by using the function lag()
. The lag()
function takes only one argument; n = 1
, by default for defining the number of periods to be shifted.
You apply lag()
on PRICE
and compare the result to the original PRICE
by using the function cbind()
. To display only the first six elements of the data columns, you can use the function head()
.
This is a part of the course
“Building Response Models in R”
Exercise instructions
- Calculate a lagged
PRICE
variable by using the functionlag()
. - Compare the lagged
PRICE
variable to the originalPRICE
variable by using the functionscbind()
andhead()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compare lagged PRICE to original PRICE
___(___(sales.data$PRICE, ___(sales.data$PRICE)))
This exercise is part of the course
Building Response Models in R
Learn to build simple models of market response to increase the effectiveness of your marketing plans.
An effective marketing strategy combines all the tools available to communicate the benefits of a product. The key is crafting the right mix of these tools to achieve sales increases and market share goals. In the second chapter, you will learn how to incorporate the effects of advertising and promotion in your sales-response model and how to identify the marketing strategy that is most likely to succeed.
Exercise 1: Model extension part 1: Dummy variablesExercise 2: Understanding dummy variablesExercise 3: The effect of display on salesExercise 4: The effect of multiple dummies on salesExercise 5: What about price?Exercise 6: Model extensions part 2: Dynamic variablesExercise 7: How to lag?Exercise 8: Adding lagged price effectsExercise 9: More lagsExercise 10: What's the value added?Exercise 11: How many extensions are needed?Exercise 12: Summarizing the modelExercise 13: Unnecessary predictorsExercise 14: Dropping predictorsExercise 15: Eliminating predictorsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.