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)
Multinomial Dirichlet model for Ecological Inference in RxC tables with rxc
using ZeligEI.
Unlike other EI models in Zelig, in the $RxC$ case, all the row and column variables need to specified. Let's assume $C1$ through $CC$ are the column totals, and $R1$ through $RR$ are the row totals, and $N=R1_i + R2_i + \ldots + RR_i = C1_i + C2_i + \ldots + CC_i$ is the total in unit $i$. In the case with three row variables and three column variables, the syntax is:
z.out <- zelig(cbind(C1,C2,C3) ~ cbind(R1,R2,R3), data=data)
Additionally, if C1
, C2
, R1
, R2
are percentages rather than counts, then you must also provide N
the unit totals as:
z.out <- zelig( cbind(C1,C2,C3) ~ cbind(R1,R2,R3), 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.
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 <- zeirxc$new() z5$zelig(cbind(C1, C2, C3) ~ cbind(R1, R2, R3), N = myN, weights = w, data = myData)
With the Zelig 4 compatibility wrappers this looks like:
z.out <- zelig(cbind(C1, C2, C3) ~ cbind(R1, R2, R3), N = myN, model = "rxc", weights = w, data = myData)
rm(list=ls(pattern="\\.out")) set.seed(1234)
We'll use a dataset from the eiPack
package, of registration data for White, Black, and Native American voters, and party voteshare, in 277 precincts in eight counties of south-eastern North Carolina in 2001.
library("eiPack", quietly=TRUE) data(senc)
Here is the model estimated in Zelig.
z.out <- zeirxc$new() z.out$zelig(cbind(dem, rep, non) ~ cbind(black, white, natam), N = "total", data = senc) summary(z.out)
You can check for convergence before summarizing the estimates with three diagnostic tests. See the section Diagnostics for Zelig Models for more examples of these tests, and interpretation of their meaning. For brevity we only show the first set of parameters, the $\alpha$'s, as there are twice as many $\beta$'s as there are precincts:
gd <- z.out$geweke.diag() print(gd[[1]]) hd <- z.out$heidel.diag() print(hd[[1]]) rd <-z.out$raftery.diag() print(rd[[1]])
This model is part of the eiPack package by Olivia Lau, Ryan T. Moore and Michael Kellerman. Advanced users may wish to refer to
help(ei.MD.bayes)
in the eiPack package.
z5 <- zeirxc$new() z5$references()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.