adstock.multiple: Adstocks a variable - infinite decay.

Description Usage Arguments Examples

View source: R/adstock.multiple.R

Description

User sets adstock rates, which transforms the input variable, outputting in a new table.

Usage

1
adstock.multiple(data, variable, adstock.rates)

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

Examples

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

out1 <- adstock.multiple(data = x, variable = "TVRs", adstock.rates = 0.1)
out2 <- adstock.multiple(data = x, variable = "TVRs", adstock.rates = seq(from = 0.1, to = 0.9, by = 0.1))

out1[, Index := 1:nrow(out1)]
out2[, Index := 1:nrow(out2)]

plot.out1 <- data.table::melt(out1, id.vars = "Index")

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

plot.out2 <- data.table::melt(out2, id.vars = "Index")

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

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