adstock.maxDecay: Adstocks a variable - max decay.

Description Usage Arguments Examples

Description

User sets adstock rates, and period where adstock decays to 0.

Usage

1
adstock.maxDecay(data, variable, adstock.rates, max.decay)

Arguments

data

data.table that holds the variable to be transformed

variable

Character string of the variable to be transformed

adstock.rates

One (or many) rates to adstock the variable

max.decay

Number of periods that the adstock takes to decay to 0

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
x <- data.table::fread(system.file("extdata", "TVRs.csv", package = "nladwa"))
x[, Week := excelDateToRDate(Week)]

out1 <- adstock.maxDecay(data = x, variable = "TVRs", adstock.rates = 0.5, max.decay = 2)
out2 <- adstock.maxDecay(data = x, variable = "TVRs", adstock.rates = 0.5, max.decay = 10)

data.table::setkey(out1, Week)
data.table::setkey(out2, Week)

out <- out1[out2]
out[, i.TVRs := NULL]

rm(out1, out2)

plot.out <- data.table::melt(out, id.vars = "Week")

ggplot2::ggplot(plot.out, ggplot2::aes(x = Week, y = value, colour = variable)) +
  ggplot2::geom_line()

Braja93/braja documentation built on May 6, 2019, 12:07 a.m.