BaşlayınÜcretsiz Başlayın

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().

Bu egzersiz

Building Response Models in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Calculate a lagged PRICE variable by using the function lag().
  • Compare the lagged PRICE variable to the original PRICE variable by using the functions cbind() and head().

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Compare lagged PRICE to original PRICE
___(___(sales.data$PRICE, ___(sales.data$PRICE)))
Kodu Düzenle ve Çalıştır