Skip to contents

These functions wrap various modelling tools to ensure a consistent input for trending functions. They work by capturing the underlying model call and decoupling it from the data specification. This makes it easy to use the same underlying model specification and fitting procedure across different data sets. See details for available model interfaces.

Usage

lm_model(formula, ...)

glm_model(formula, family = gaussian, ...)

glm_nb_model(formula, ...)

brm_model(formula, ...)

Arguments

formula

The formula of the model, with the response variable on the left of a tilde symbol, and predictors on the right hand-side; variable names used in the formula will need to be matched by columns in the data input to other functions.

...

Further arguments passed to the underlying models with the exception of data.

family

Link function to be used for the glm model.

Value

A trending_model object.

Details

The following interfaces are available:

  • lm_model: interface for linear models implemented in stats::lm().

  • glm_model: interface for generalised linear models (GLMs) implemented in stats::glm().

  • glm_nb_model: interface for negative binomial generalied linear models implemented in MASS::glm.nb().

  • brm_model: interface for Bayesian regression models implemented in brms::brm().

These interfaces will accept the same inputs as the underlying model functions but do not require, nor will they accept, a data argument. Fitting is handled instead by the fit() generic and associated methods.

Author

Tim Taylor

Examples

x = rnorm(100, mean = 0)
y = rpois(n = 100, lambda = exp(1.5 + 0.5*x))

poisson_model <- glm_model(y ~ x , family = "poisson")
negbin_model <- glm_nb_model(y ~ x)