mrp_eval: Evaluate MRP cell predictions

Description Usage Arguments Details Value See Also Examples

Description

Compares the accuracy of the cell predictions produced by mrp_model with the standard raked demographic weights in the survey data frame data. The comparison is conducted by creating weighted proportion tables for xvars and yvar using the two sets of weights, and then generating various descriptive statistics for the two tables compared to the known values of variables as found in target.

Usage

1
2
mrp_eval(data, xvars, yvar, target, cor.method = c("pearson", "kendall",
  "spearman"))

Arguments

data

A data frame containing the original survey data used in a call to mrp_model that has had the cell predictions from the regression fit merged with the data frame. See Details.

xvars

character: Vector of variable names in data for x-axis rows to pass to wtd_tab.

yvar

character: Response variable for the y-axis in a two-way table to pass to wtd_tab.

target

A data frame or table containing the true values of the weighted proportions between xvars and yvars. If target is an object of class data.frame, it will be coerced into as table. See Details.

Details

If a data frame is passed to target, the object will be coerced into a table using the first column of the data frame as the table row names. The column names of target do not need to be exact matches to the variable levels of yvar, but the table row names (or first column, if a data frame) must be exact string matches as the levels of the variables in xvars, and must be in the same order as xvars. If the order is not exactly matched, then the analysis will compare the estimated values with incorrect known values.

Since the evaluation focuses on the accuracy of the different demographic groups' in xvars proportions compared to the known values, all of the variables specified in xvars within data need to have matching value labels (levels) as those in target, as these will become the rows (and row names) of the weighted crosstabulations created by wtd_tab. Any demographic groups (row names) in target not present in the survey data crosstables will be dropped from the analysis.

Value

A table containing diagnostic statistics describing the accuracry of the estimates using raked weights and multilevel regression with postratification cell predictions.

See Also

mrp_model, wtd_tab

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
### Run the MRP regression
mrp.fit1 <- mrp_model(y ~ z.st.repvote + (1 | age4) + (1 | sex) + (1 | race4) + (1 | educ3),
                      data = data, mrp.data = cps.tbl)

### Extract cell predictions and merge with data
res <- mrp_merge(data, mrp.fit1)

### Create target as a data frame
load("Data/pollstr_data.Rda")
# Aggregate single estimates by state
pollstr_data_agg <- pollstr_data %>%
  group_by(state, choice) %>%
  summarise(value = mean(value))
pollstr1 <- reshape2::dcast(pollstr_data_agg, state ~ choice, value.var = 'value')
pollstr1$state <- abbr2state(pollstr1$state)
for (i in 2:ncol(pollstr1))
  pollstr1[, i] <- round(pollstr1[, i], 2)

### Run evaluation
mrp_eval(data = res, xvars = 'demState', yvar = 'nr2Bin', target = pollstr1)


### Create target as a table
load("Data/cps_nov12_clean.Rda")
cps <- cps_nov12_clean
cps <- copy.lev(cps, cps_nov12_clean)
cps$demState <- cps$state
levels(cps$demState) <- levels(res$demState)[1:51]
t0 <- wtd_tab(cps, 'demState', 'kids2', 'wts')
t0 <- t0 / rowSums(t0) * 100

### Run evaluation
mrp_eval(data = res, xvars = 'demState', yvar = 'demKids', target = t0)

alexdulin/MCmrp documentation built on May 11, 2019, 11:29 p.m.