its_lm: ITS analysis for continuous outcomes

View source: R/functions.R

its_lmR Documentation

ITS analysis for continuous outcomes

Description

its_lm fits a linear regression model to an ITS, and returns the model, the summary of the model (including the mean difference and Cohen's d), and the original data together with the model predictions.

Usage

its_lm(
  data,
  form,
  time_name,
  intervention_start_ind,
  freq,
  seasonality = "none",
  impact_model = "full",
  counterfactual = FALSE,
  print_summary = FALSE
)

Arguments

data

The data frame corresponding to the supplied formula, existing of at least 2 variables: (1) the count outcome, and (2) a vector of time points

form

A formula with the response on the left, followed by the ~ operator, and the covariates on the right, separated by + operators. The formula should not contain an offest term.

time_name

A string giving the name of the time variable. The time variable may or may not be supplied as a covariate in the formula

intervention_start_ind

Numeric - a number between 1 and nrow(data)-1 stating the time point of the start of the intervention

freq

A positive integer describing the frequency of the time series.

seasonality

A string specifying whether seasonality should be considered. Possible options include "none" corresponding to no seasonal adjustment, "full" corresponding to using freq-1 Fourier terms to model the seasonal component, and "significant" indicating whether only the significant Fourier terms should be considered in the seasonal adjustment. Default value is "none".

impact_model

A string specifying the assumed impact model. Possible options include "full" corresponding to a model including both a level change and a slope change, "level" corresponding to a model including just a level change, and "slope" corresponding to a model including just a slope change. Default value is "full".

counterfactual

Logical - indicating whether the model-based counterfactual values should also be returned as an additional column in the data. Default value is FALSE, in which case the counterfactual values are not returned.

print_summary

Logical - indicating whethwe the entire model summary should be printed, or just the relevant effect size. Default value is FALSE in which case only the effect size, together with its 95% CI and P-value, are printed.

Value

The function returns a list with three elements: the fitted linear regression model, the summary of the model (including the mean difference and Cohen's d), and the original data together with the model predictions.

Examples

data <- unemployed
form <- as.formula("percent ~ time")
intervention_start_ind <- which(data$year==2020 & data$month>2| data$year==2021)[1]
fit <- its_lm(data=data,form=form,time_name = "time",intervention_start_ind=intervention_start_ind,freq=12, seasonality= "none", impact_model = "full",counterfactual = TRUE)

Yael-Travis-Lumer/its2es documentation built on Oct. 31, 2022, 8:05 a.m.