swissMrP: Multilevel Regression with Poststratification for the 26...

View source: R/swissMrP.R View source: R/summary.swissMrP.R View source: R/print.swissMrP.R

swissMrPR Documentation

Multilevel Regression with Poststratification for the 26 Swiss Cantons

Description

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.

Usage

swissMrP(response.model, augment.data = NA, augment.row = 0, uncertainty = FALSE,
         Number.sim = 1000, region)

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. One can include any level 2 predictors.

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. If a canton is missing it will be a vector, if more than one is missing it is a matrix where the number of rows equals the number of missing cantons. For each level 2 variable one adds a column (see example) and a preceeding column of 1's.

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.

region

Vector. The regional grouping is based on the large regions in Switzerland (see Leemann and Wasserfallen, 2016). 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.)

The default setting is 1 (Geneva, Valais, Vaud), 2 (Bern, Fribourg, Jura, Neuchatel, Solothurn), 3 (Aargau, Basel-Stadt, Basel-Landschaft), 4 (Zurich), 5 (Appenzell I. Rh., Appenzell A. Rh., Glarus, Grisons, St. Gallen, Schaffhausen, Thurgau), 6 (Lucerne, Nidwalden, Obwalden, Schwyz, Uri, Zug), and 7 (Ticino).

Value

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).

Author(s)

Lucas Leemann lleemann@gmail.com

References

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. 2016. The Democratic Effect of Direct Democracy. American Political Science Review 110(4): 750-762.

Examples


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(link = 'probit'))
# use the MrP function
mrp1 <- swissMrP(model1)

## Here is an example if two cantons (10,22; FR & VD) are missing
mrp2 <- swissMrP(model1,
			augment.data=matrix(c(c(1,2,-1),c(1,1,-5)),2,3, byrow=TRUE),
			augment.row=c(10,22))


lleemann/swissMrP documentation built on April 25, 2023, 6:12 a.m.