Learn R Programming

linea (version 0.1.1)

run_model: run_model

Description

Run a linear regression model

Usage

run_model(
  data = NULL,
  dv = NULL,
  ivs = NULL,
  trans_df = NULL,
  id_var = NULL,
  pool_var = NULL,
  model_table = NULL,
  verbose = FALSE,
  normalise_by_pool = FALSE,
  save_all_raw_data = TRUE,
  decompose = TRUE,
  tail_window = NULL,
  categories = NULL
)

Value

Model object

Arguments

data

data.frame containing variables included in the model specification

dv

string of the dependent variable name

ivs

character vector of the independent variables names

trans_df

data.frame defining the non-linear transformations to apply

id_var

string of id variable name (e.g. date)

pool_var

string specifying the pool variable name (e.g. 'country')

model_table

data.frame as created in the build_model_table function

verbose

A boolean to specify whether to print warnings

normalise_by_pool

A boolean to specify whether to apply the normalisation

save_all_raw_data

A boolean to specify whether to save whole input data to the model object

decompose

A boolean to specify whether to generate the model decomposition

tail_window

for time series, length of tail in decomposition

categories

data.frame mapping variables to groups

Details

Run a linear regression model that captures the transformations applied in the model_table and the normalisation based on the pool_var. A model can be run also by only supplying a dependent variable name dv, a vector of independent variable names dependent variable ivs, and the data that contains these.

Examples

Run this code

trans_df = data.frame(
    name = c('diminish', 'decay', 'hill', 'exp'),
    func = c(
      'linea::diminish(x,a)',
      'linea::decay(x,a)',
      "linea::hill_function(x,a,b,c)",
      '(x^a)'
    ),
    order = 1:4
)

data = read_xcsv("https://raw.githubusercontent.com/paladinic/data/main/ecomm_data.csv")
dv = 'ecommerce'
ivs = c('christmas','black.friday')

run_model(data = data,
          dv = dv,
          ivs = ivs,
          trans_df = trans_df)

run_model(data = mtcars,dv = 'mpg',ivs = c('disp','cyl'))

Run the code above in your browser using DataLab