Built using Zelig version r packageVersion("Zelig")

knitr::opts_knit$set(
    stop_on_error = 2L
)
knitr::opts_chunk$set(
    fig.height = 11,
    fig.width = 7
)

options(cite = FALSE)

Wakefield's Hierarchical Ecological Inference Model with eihier in ZeligEI.

Syntax

The EI models accept several different formula syntaxes. If $C1$ and $C2$ are the column totals, and $R1$ and $R2$ are the row totals, and $N=R1_i + R2_i = C1_i + C2_i$ is the total in unit $i$, then the formula can be expressed with just one row and one column, with the totals provided separately as:

z.out <- zelig(C1 ~ R1, N = N, data = data)

The argument N can be either a numeric vector of the total in each i-th unit, or the character name of a variable in the dataset that contains these values.

Or with both rows and columns coupled together, and omitting the totals:

z.out <- zelig(cbind(C1, C2) ~ cbind(R1, R2), data = data)

Additionally, if C1, C2, R1, R2 are percentages rather than counts, then either formula method above is acceptable, however, N must always be provided.

First load packages:

library(zeligverse)

Here is an example of all the syntax for the analysis using the first syntax method, and the direct use of the reference classes:

z5 <- zeihier$new()
z5$zelig(C1 ~ R1, N = myN, weights = w, data = myData)

With the Zelig 4 compatibility wrappers this looks like:

z.out <- zelig(C1 ~ R1, N = N, model = "eihier", weights = w,
               data = myData)

Additional Inputs

In addition, Zelig accepts the following additional inputs for eihier to monitor the convergence of the Markov chain:

The model also accepts the following additional arguments to specify prior parameters used in the model:

Users may wish to refer to help(MCMCdynamicEI) for more options.

Examples

rm(list=ls(pattern="\\.out"))
set.seed(1234)

We'll use a dataset from the ei package, of black and non-black turnout in 141 precincts.

library("ei", quietly=TRUE)
data(sample)

Here is the model estimated in Zelig.

z.out <- zeihier$new()
z.out$zelig(t ~ x, N = "n", data = sample)
summary(z.out)

You can check for convergence before summarizing the estimates with three diagnostic tests. See the section Diagnostics for Zelig Models for examples of the output with interpretation:

z.out$geweke.diag()
z.out$heidel.diag()
z.out$raftery.diag()

See also

The Wakefield hierarchical model is part of the MCMCpack package by Andrew Martin, Kevin Quinn, and Jong Hee Park. Advanced users may wish to refer to help(MCMChierEI) in the MCMCpack package.

z5 <- zeihier$new()
z5$references()


IQSS/Zelig documentation built on Dec. 11, 2023, 1:51 a.m.