Description Usage Arguments Value Author(s) References Examples
View source: R/print.swissMrP.R View source: R/summary.swissMrP.R View source: R/swissMrP.R
This function provides cantonal estimates of public support based on the MrP procedure. Specifically: this function caries out the third (prediction) and forth step (post-stratification) of MrP.
1 2 |
response.model |
The output object of |
augment.data |
In case one uses survey data for the generation of |
augment.row |
Integer, between 1 and 26. Indicates the row or rows where the |
uncertainty |
Logical. If |
Number.sim |
Integer. Number of simulations to be run for uncertainty measure. Default is set to 1000. |
region |
Vector. The regional grouping is based on the large regions in Switzerland (see Leemann and Wasserfallen, 2013). But for certain questions and models alternative groupings could be beneficial. The user can supply a vector (length 26) with integers from 1 to the maximal number of distict regions whereas the first element indicates the regional group of ZH, the second element implies the regional group of BE, ... etc. (it is the standard order of cantons used by the Federal Statistics Office.) |
Creates an object of class swissMrP
. A list where the first element is a vector of length 26 (an estimate for each of the 26 cantons).
Lucas Leemann lleemann@gmail.com
Gelman, Andrew and Thomas C. Little. 1997. Poststratification Into Many Categories Using Hierarchical Logistic Regression. Survey Research 23:127-135.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | library(lme4)
### 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 <- cbind(rnorm(26),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] +X[,2] + (1|woman) + (1|education) + (1|age) + (1|cantonnr)
+ (1|region), family=binomial(probit))
# use the MrP function
mrp1 <- swissMrP(model1)
## Assume model1 would not have any repsondents from JU (cantonnr 26) and x[26,1]=2 and x[26,2]=-1)
mrp2 <- swissMrP(model1,augment.data=c(1,2,-1),augment.row=26)
## Here is an example if two cantons (10,22; FR & VD) are missing
mrp3 <- swissMrP(model1,augment.data=matrix(c(c(1,2,-1),c(1,1,-5)),2,3, byrow=TRUE),augment.row=c(10,22))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.