get_states: Function to sample the latent states given sampled covariance...

Description Usage Arguments Value Examples

View source: R/get_states.R

Description

get_states uses the dlm package to sample the latent states via the forward filtering-backward sampling algorithm as described in the research narrative. The same arguments should be supplied for parameters shared by get_states and run_mcmc.

Usage

1
2
3
4
5
6
7
8
get_states(
  mcmc_samples,
  data,
  harmonics = 4,
  crime_types = c("burglary", "robbery"),
  initial_year = 2012,
  final_year = 2016
)

Arguments

mcmc_samples

A list of parameter samples with the same names and classes as those produced by run_mcmc.

data

The full Chicago crime dataset as given by chicago.

harmonics

An integer in 1 to 6 specifiying the number of harmonics to model seasonality. Must be consistent with specification in run_mcmc().

crime_types

Character vector specifying the types of crimes to include in the analysis. The function requires at least two crime types.

initial_year

Integer in 2007 to 2015 specifying the first year in the analysis.

final_year

Integer in 2008 to 2016 specifying the last year in the analysis.

Value

Returns a list with two objects: state_samples and crime_types. state_samples is a three dimensional array where dimension one corresponds to the sample/iteration, dimension two corresponds to the number of time points, and dimension three corresponds to the parameter. Parameters are in the following order: μ_1,μ_2,...,β_1, β_2,.... The ordering of a given set of parameters, say μ, is the ordering of the types of crimes specified by the crime_types argument. After β parameters, the remainder are needed for the construction of seasonal effects. crime_types returns the crime_types argument specified in the function. This serves as a reminder of the ordering of crime types, which is important for interpreting the state_samples output as well as making sure that the order of crime types is consistent between other functions.

Examples

1
2
3
4
5
 ## Not run: 
 cov_samples <- run_mcmc(data = chicago, chains = 2, adapt_delta = 0.8)
 state_samples <- get_states(mcmc_samples = cov_samples$samples, data = chicago)
 
## End(Not run)

nategarton13/CrimeDLM.RPackage documentation built on Aug. 8, 2020, 7:49 p.m.