Learn R Programming

geocausal (version 0.3.2)

get_hist: Obtain histories of treatment or outcome events

Description

`get_hist()` takes a hyperframe and time and columns of interest, and generates histories of events of interest.

Usage

get_hist(tt, Xt, Yt = NA, lag, window, x_only = TRUE)

Value

list of treatment and outcome histories

Arguments

tt

values of the time variable of interest for which `get_hist()` generates histories

Xt

the name of a treatment column

Yt

the name of an outcome column

lag

numeric. `lag` specifies the number of time periods over which `get_hist()` aggregates treatment and outcome columns.

window

owin object.

x_only

logical. `x_only` specifies whether to generate only treatment history (no outcome history). By default, `FALSE`.

Examples

Run this code
dat_out <- insurgencies[1:100, ]
dat_out$time <- as.numeric(dat_out$date - min(dat_out$date) + 1)

# Hyperframe
dat_hfr <- get_hfr(data = dat_out,
                   col = "type",
                   window = iraq_window,
                   time_col = "time",
                   time_range = c(1, max(dat_out$time)),
                   coordinates = c("longitude", "latitude"),
                   combine = TRUE)

# Histories
lapply(1:nrow(dat_hfr), get_hist,
       Xt = dat_hfr$all_outcome,
       lag = 1, window = iraq_window)

Run the code above in your browser using DataLab