DLM: Dynamic Linear Model Function on panel data

Description Usage Arguments Value

View source: R/DLM.R

Description

A function to run DLM and post-modelling calculation on panel data for Marketing-Mix modelling

Usage

1
2
3
4
5
6
DLM(spec, data, model.name, contrb.date, group, date.var, start.date.m,
  end.date.m, start.date.c, end.date.c, is.output = F, is.graph = T,
  clv = 1, varlist, dum, dum_matrix, num_ng_coef, dep, actual, mean,
  CI.level = 0.95, iter = 100, level_type, var_coef, var_level, var_slope,
  per_sea, ord_sea, var_sea, optim.method = "L-BFGS-B", optim.lb = -Inf,
  optim.ub = Inf)

Arguments

spec

a character vector for parallel computation; for example, rep("localhost",3) means open 3 local R sessions.

data

a data.table class object as modelling dataset.

model.name

a character for the name of your model, used in output file names.

contrb.date

a character for the time period of your contribution calculation time window, used in output file names.

group

a character for cross section variable name name in modelling dataset.

date.var

a character for date variable name in modelling dataset.

start.date.m

a character for the start date of modelling; format is YYYY-MM-DD.

end.date.m

a character for the end date of modelling; format is YYYY-MM-DD.

start.date.c

a character for the start date of post-modelling contribution calculation; format is YYYY-MM-DD.

is.output

TRUE output decomp tables.

is.graph

TRUE graph AVP chart.

clv

a numeric for value calcualtion of dependent, such as NPV or CLV. Default value is 1.

varlist

a character vector for the independent variable names, if no independent, then put c(). Always put variables required NEGATIVE coefficient at the beginning, then POSITIVE coefficient variables, and variables NOT required the sign of coefficient in the end. The order would be used in a build-in coefficient sign check feature. If no sign check needed, then the order doesn't matter.

dum

a character vector for variables in varlist which is not required sign(the last several variables from the above vector),if none then put c().

dum_matrix

a numeric matrix for the variables in the dum vector, which specify the cross section that each variable would have impact on. If dum is c(), then put NA. Row is cross section and column is variables in dum vector. Only put 1 or 0 to specify whether a variable has impact or not.

num_ng_coef

a numeric for the number of variables required negative cofficient.

dep

a character for dependent variable name.

actual

a character for actual depdendent before indexed.

mean

a character for weight used to index actual dependent.

CI.level

a numeric for confidence interval level in output; range is from 0 to 1. For example, 0.95 means 95 percent CI level.

iter

a numeric for the number of iteration of coefficient sign check. Default value is 100. If no sign check needed, please put 1.

level_type

a numeric for the type of level component in DLM; 1 represents level type; 2 represents level+slope type.

var_coef

a numeric for the variance of independent coefficient; 0 reprensents constant coef, non-zero value represents time-varying coef. For example, 1^2 means the standard deviation of each coef is 1 and time-varying; "est" means estimated by model itself.

var_level

a numeric for the variance of level component; 0 reprensents constant coef, non-zero value represents time-varying coef. For example, 1^2 means the standard deviation of each coef is 1 and time-varying; "est" means estimated by model itself.

var_slope

a numeric for the variance of slope component; 0 reprensents constant coef, non-zero value represents time-varying coef. For example, 1^2 means the standard deviation of each coef is 1 and time-varying; "est" means estimated by model itself.

per_sea

a numeric for the period of seasonality variable. For example, in weekly data, 52 means the period is 52 weeks.

ord_sea

a numeric for the number of harmonics of seasonality component which is a Fourier series.

var_sea

a numeric for the variance of seasonality component; 0 reprensents constant coef, non-zero value represents time-varying coef. For example, 1^2 means the standard deviation of each coef is 1 and time-varying; "est" means estimated by model itself.

optim.method

a charater for the optimization method used in MLE. Default is "L-BFGS-B". Any other method in stats::optim is available.

optim.lb

a numeric for the lower bond of optimization. Defualt is -Inf.

optim.ub

a numeric for the upper bond of optimization. Defualt is Inf.

end.date.m

c character for the end date of post-modelling contribution calculation; format is YYYY-MM-DD.

Value

a list of modeling result. It contains the following components: stat: Diagnostic Statistics coef: a coefficient table if possible


xinzhou1023/dlmpanel documentation built on May 4, 2019, 1:07 p.m.