plot_its_lm: Plot ITS fitted values

View source: R/functions.R

plot_its_lmR Documentation

Plot ITS fitted values

Description

plot_its_lm uses ggplot2 to plot the model-based fitted values, together with a scatterplot of the observed time series

Usage

plot_its_lm(data, intervention_start_ind, y_lab, response, date_name)

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

intervention_start_ind

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

y_lab

a string with the y axis label for the predictions

response

The name of the response variable to be plotted in the scatterplot

date_name

A string giving the name of the date column. The date column must be a Date object.

Value

a ggplot object including a scatterplot of the time series, the predictions line, and the counterfactual predictions in red (if available.

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)
new_data <- fit$data
y_lab <- "Unemployment percent"
response <- "percent"
p <- plot_its_lm(new_data,intervention_start_ind,y_lab,response, "dt")

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