mrp.zurich: Multilevel Regression with Poststratification

Description Usage Arguments Note Author(s) References Examples

View source: R/mrp.zurich.R

Description

This function provides cantonal estimates of public support based on MrP.

Usage

1
2
mrp.zurich(response.model, augment.data = NA, augment.row = 0, uncertainty = FALSE, 
           Number.sim = 1000, output = 2)

Arguments

response.model

The output object of glmer or blmer where one estimates a hierarchical model with random effects for: age, education, gender, canton, and region.

augment.data

In case one uses survey data for the generation of response.model which does not have any respondents from one or more cantons there is a problem. The function does not know the values of the level 2 explanatory variables in the response.model and would hence produce NA's or wrong results. Users can supply the missing information as augment.data.

augment.row

Integer, between 1 and 26. Indicates the row or rows where the augment.data will be inserted. If data is missing for BE (second canton) and LU (third canton) one will have to supply a vector c(2,3).

uncertainty

Logical. If uncertainty=TRUE the function will run Number.sim simulations to obtain a measure of uncertainty for each cantonal prediction.

Number.sim

Integer. Number of simulations to be run for uncertainty measure. Default is set to 1000.

output

Integer (0,1,2). Controls how much information is displayed. This option does not affect any functionality but only impacts on the amount of information which will be displayed.

Note

This function was written for a MA class at the University of Zurich (Fall 2013), see lecture by Fabio Wasserfallen on 11.29.2013 and the follow-up lecture by Lucas Leemann (12.13.2013).

Author(s)

Lucas Leemann

References

Jeffrey Lax and Justin Phillips. 2009. How Should We Estimate Public Opinion in The States? American Journal of Political Science 53 (1), 107-121.

Leemann, Lucas and Fabio Wasserfallen. 2013. Direct Democracy, Representation, and Policy Congruence. Presented at the General Conference of the European Political Science Association Barcelona: June 20-22.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
### Fake data
err.ind <- rnorm(1000,sd=4)
woman <- sample(c(0,1),replace=TRUE,size=1000) 
age <- sample(c(1:4),replace=TRUE,size=1000) 
education <- sample(c(1:6),replace=TRUE,size=1000) 
cantonnr <- sample(c(1:26),replace=TRUE,size=1000) 
region <- sample(c(1:7),replace=TRUE,size=1000) 
x <- rnorm(26); err.con <- rnorm(26,sd=4); X <- matrix(NA,1000,2)
for (q in 1:1000){ X[q,] <- c(x[cantonnr[q]],err.con[cantonnr[q]])}
y.fake <- X[,1] +X[,2] + woman+age+education+cantonnr+region + err.ind
y <- rep(0,length(y.fake))
y[y.fake>mean(y.fake)]<-1
model1 <- glmer(y ~ X[,1] + (1|woman)  + (1|education) + (1|age) + (1|cantonnr) 
                + (1|region), family=binomial(probit))
# now we can use the MrP function
mrp1 <- mrp.zurich(model1)

## Assume model1 would not have any repsondents from JU (cantonnr 26) and x[26]==2
mrp2 <- mrp.zurich(model1,augment.data=2,augment.row=26)

MrPzurich2013 documentation built on May 2, 2019, 4:42 p.m.