Learn R Programming

geostan (version 0.8.1)

prep_icar_data: Prepare data for ICAR models

Description

Given a symmetric n x n connectivity matrix, prepare data for intrinsic conditional autoregressive models in Stan. This function may be used for building custom ICAR models in Stan. This is used internally by stan_icar.

Usage

prep_icar_data(C, scale_factor = NULL)

Value

list of data to add to Stan data list:

k

number of groups

group_size

number of nodes per group

n_edges

number of connections between nodes (unique pairs only)

node1

first node

node2

second node. (node1[i] and node2[i] form a connected pair)

weight

The element C[node1, node2].

group_idx

indices for each observation belonging each group, ordered by group.

m

number of disconnected regions requiring their own intercept.

A

n-by-m matrix of dummy variables for the component-specific intercepts.

inv_sqrt_scale_factor

By default, this will be a k-length vector of ones. Placeholder for user-specified information. If user provided scale_factor, then this will be 1/sqrt(scale_factor).

comp_id

n-length vector indicating the group membership of each observation.

Arguments

C

Connectivity matrix

scale_factor

Optional vector of scale factors for each connected portion of the graph structure. If not provided by the user it will be fixed to a vector of ones.

Details

This is used internally to prepare data for stan_icar models. It can also be helpful for fitting custom ICAR models outside of geostan.

See Also

edges, shape2mat, stan_icar, prep_car_data

Examples

Run this code
data(sentencing)
C <- shape2mat(sentencing)
icar.data.list <- prep_icar_data(C)

Run the code above in your browser using DataLab