plot_its_poisson: Plot ITS fitted values

View source: R/functions.R

plot_its_poissonR Documentation

Plot ITS fitted values

Description

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

Usage

plot_its_poisson(
  data,
  intervention_start_ind,
  y_lab,
  response,
  offset_name = NULL,
  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

offset_name

either a string indicating the name of the offset column used in the ITS Poisson model, or NULL. Default value is NULL. When offfset_name exists, the function plots the response rate, instead of the count itself.

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("unemployed ~ time")
intervention_start_ind <- which(data$year==2020 & data$month>2| data$year==2021)[1]
fit <- its_poisson(data=data,form=form,offset_name="labour", time_name = "time",intervention_start_ind=intervention_start_ind,over_dispersion=TRUE, freq=12, seasonality= "none", impact_model = "full",counterfactual = TRUE)
new_data <- fit$data
y_lab <- "Unemployment percent"
response <- "percent"
p <- plot_its_poisson(new_data,intervention_start_ind,y_lab,response, offset_name = "labour", "dt")

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