run_mcmc: Function to sample observation and state covariance...

Description Usage Arguments Value Examples

View source: R/run_mcmc.R

Description

run_mcmc uses Stan to run a Hamiltonian Monte Carlo algorithm to sample the observation and latent state covariance parameters in the dynamic linear model specificied in the research narrative. The full chicago crime dataset must be passed to the data argument. Other parameter arguments dictate the subset of the data on which the analysis is performed as well as details of the MCMC to be passed to rstan::sampling.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
run_mcmc(
  data,
  harmonics = 4,
  chains = 3,
  iter = 2000,
  warmup = 1000,
  adapt_delta = 0.9,
  crime_types = c("burglary", "robbery"),
  initial_year = 2012,
  final_year = 2016
)

Arguments

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.

chains

An integer specifying the number of MCMC chains for Stan to run.

iter

An integer specifying the total number of samples for each chain, including warmup.

warmup

An integer specifying the number of burn-in samples in Stan.

adapt_delta

See Stan language manual at http://mc-stan.org/users/documentation/.

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 of three objects: samples, summary, and crime_types. summary gives a summary of the samples. 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 covariance matrix output as well as making sure that the order of crime types is consistent between other functions. samples is itself a list where each element is either a two or three dimensional array containing all of the samples of a given parameter. The first dimension of the array always corresponds to the sample/iteration. Parameter names work as follows: omega_evo corresponds to evolution correlation matrices, omega_error corresponds to error correlation matrices, sigma_evo corresponds to a vector of evolution standard deviations, sigma_error corresponds to a vector of the error standard deviations, sigma_evo_mat corresponds to evolution covariance matrices, sigma_error_mat corresponds to error covariance matrices. See Stan documentation for lp__.

Examples

1
2
3
4
 ## Not run: 
 cov_samples <- run_mcmc(data = chicago, chains = 2, adapt_delta = 0.8)
 
## End(Not run)

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