adstockDerive: Finds the optimum Adstock rate.

Description Usage Arguments Examples

View source: R/adstockDerive.R

Description

Derives best adstock rate, based on lowest SSE.

Usage

1
adstockDerive(data, y, x, lim = FALSE)

Arguments

data

data.frame that holds the data (independent and dependent)

y

Dependent variable e.g. Sales

x

Independent variable, of which we want to derive optimum adstock

lim

Numeric. Upper limit for adstock rate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
x <- data.table::fread(system.file("extdata", "Model.csv", package = "nladwa"))

opt.rate <- adstockDerive(data = x, y = "Sales", x = "Media")

x[, Adstock.Media := adstock(x = Media, adstock.rate = opt.rate)]

xm <- data.table::melt(x, id.vars = "Week")

ggplot2::ggplot(x, ggplot2::aes(x = Week)) +
  ggplot2::geom_area(ggplot2::aes(y = Adstock.Media), alpha = 0.5) +
  ggplot2::geom_bar(ggplot2::aes(y = Media), stat = "identity")

model1 <- lm(Sales ~ Media, data = x)
model2 <- lm(Sales ~ Adstock.Media, data = x)

summary(model1)
summary(model2)

sum(residuals(model1)^2)
sum(residuals(model2)^2)

sum(residuals(model2)^2) < sum(residuals(model1)^2)

Braja93/braja documentation built on June 1, 2017, 5:19 p.m.