abstract.regression: Abstract Regression

View source: R/dthelper-computation-functions.R

abstract.regressionR Documentation

Abstract Regression

Description

Perform linear regressions given an abstract formulae. This is especially useful for regressing variables over time. Say we have a variable called e in our data that is indexed based on time, e1, e2, e3, etc (this assumes our data is in wide format). We can use the abstract formulae "e{X} ~ e{X-1}" to use e at previous timepoints to predict e at the next time step. Typically, we get a single estimate of this relationship (or autocorrelation). However, abstract regression runs a regression separately at each timestep, for e1 ~ e2, then e2 ~ e3, etc. To use this function, simply replace the index of your variable of interest with the symbol "X". The are necessary if any computations such {X+1} or {X-2} are used

Usage

abstract.regression(form, df)

Arguments

form

Input formulae string.

df

data.frame object

Value

data.frame object

Examples

df <- data.frame(
      x = rnorm(10),
      e1 = rnorm(10),
      e2 = rnorm(10),
      e3 = rnorm(10),
      e4 = rnorm(10)
      )
abstract.regression("e{X} ~ e{X-1}", df)
abstract.regression("e{X} ~ e{X-1} + x", df)
abstract.regression("e{X} ~ e{X-1} * x", df)


dennisteowh/dthelper documentation built on March 19, 2022, 11:42 a.m.