Title: | ANES Raking Implementation |
---|---|
Description: | Provides a comprehensive system for selecting variables and weighting data to match the specifications of the American National Election Studies. The package includes methods for identifying discrepant variables, raking data, and assessing the effects of the raking algorithm. It also allows automated re-raking if target variables fall outside identified bounds and allows greater user specification than other available raking algorithms. A variety of simple weighted statistics that were previously in this package (version .55 and earlier) have been moved to the package 'weights.' |
Authors: | Josh Pasek [aut, cre] |
Maintainer: | Josh Pasek <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.80 |
Built: | 2025-03-03 04:34:36 UTC |
Source: | https://github.com/cran/anesrake |
A dataset containing demographic data from the 2004 American National Election Studies. The data include 5 variables: "female" (A Logical Variable Indicating Sex), "age" (Numerically Coded, Ranging From 18 to a Topcode of 90), "educats" (5 Education Categories corresponding to 1-Less than A High School Degree, 2-High School Gradutate, 3-Some College, 4-College Graduate, 5-Post College Education), "racecats" (6 Racial Categories), and "married" (A Logical Variable Indicating the Respondent's Marital Status, with one point of missing data). Dataset is designed show how production of survey weights works in practice.
data(anes04)
data(anes04)
The format is: chr "anes04"
http://www.electionstudies.org
anesrake
takes a list of variables and target values and determines how they should be weighted to match the procedures outlined in DeBell and Krosnick, 2009. It then performs raking to develop weights for the variables selected such that they match the targets provided.
anesrake(inputter, dataframe, caseid, weightvec = NULL, cap = 5, verbose = FALSE, maxit = 1000, type = "pctlim", pctlim = 5, nlim = 5, filter = 1, choosemethod = "total", iterate = TRUE, convcrit = 0.01, force1=TRUE, center.baseweights=TRUE)
anesrake(inputter, dataframe, caseid, weightvec = NULL, cap = 5, verbose = FALSE, maxit = 1000, type = "pctlim", pctlim = 5, nlim = 5, filter = 1, choosemethod = "total", iterate = TRUE, convcrit = 0.01, force1=TRUE, center.baseweights=TRUE)
inputter |
The
|
dataframe |
The |
caseid |
The |
weightvec |
|
cap |
|
verbose |
Users interested in seeing the progress of the algorithm can set |
maxit |
Users can set a maximum number of iterations for the function should it fail to converge using |
type |
|
pctlim |
|
nlim |
|
filter |
|
choosemethod |
|
iterate |
|
convcrit |
|
force1 |
|
center.baseweights |
|
A list object of anesrake
has the following elements:
weightvec |
Vector of weights From raking algorithm |
type |
Type of variable selection used (identical to specified |
caseid |
Case IDs for final weights – helpful for matching |
varsused |
List of variables selected for weighting |
choosemethod |
Method for choosing variables for weighting (identical to specified |
converge |
Notes whether full convergence was achieved, algorithm failed to converge because convergence was not possible, or maximum iterations were reached |
nonconvergence |
Measure of remaining discrepancy from benchmarks if convergence was not achieved |
targets |
|
dataframe |
Copy of the original |
iterations |
Number of iterations required for convergence (or non-convergence) of final model |
iterate |
Copy of |
Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).
DeBell, M. and J.A. Krosnick. (2009). Computing Weights for American National Election Study Survey Data, ANES Technical Report Series, No. nes012427. Available from: ftp://ftp.electionstudies.org/ftp/nes/bibliography/documents/nes012427.pdf
data("anes04") anes04$caseid <- 1:length(anes04$age) anes04$agecats <- cut(anes04$age, c(0, 25,35,45,55,65,99)) levels(anes04$agecats) <- c("age1824", "age2534", "age3544", "age4554", "age5564", "age6599") marriedtarget <- c(.4, .6) agetarg <- c(.10, .15, .17, .23, .22, .13) names(agetarg) <- c("age1824", "age2534", "age3544", "age4554", "age5564", "age6599") targets <- list(marriedtarget, agetarg) names(targets) <- c("married", "agecats") outsave <- anesrake(targets, anes04, caseid=anes04$caseid, verbose=TRUE) caseweights <- data.frame(cases=outsave$caseid, weights=outsave$weightvec) summary(caseweights) summary(outsave)
data("anes04") anes04$caseid <- 1:length(anes04$age) anes04$agecats <- cut(anes04$age, c(0, 25,35,45,55,65,99)) levels(anes04$agecats) <- c("age1824", "age2534", "age3544", "age4554", "age5564", "age6599") marriedtarget <- c(.4, .6) agetarg <- c(.10, .15, .17, .23, .22, .13) names(agetarg) <- c("age1824", "age2534", "age3544", "age4554", "age5564", "age6599") targets <- list(marriedtarget, agetarg) names(targets) <- c("married", "agecats") outsave <- anesrake(targets, anes04, caseid=anes04$caseid, verbose=TRUE) caseweights <- data.frame(cases=outsave$caseid, weights=outsave$weightvec) summary(caseweights) summary(outsave)
anesrake
takes a list of variables and target values and determines which variables should be used for weighting in accordance with DeBell and Krosnick, 2009. Used as part of anesrake
.
anesrakefinder(inputter, dataframe, weightvec = NULL, choosemethod = "total")
anesrakefinder(inputter, dataframe, weightvec = NULL, choosemethod = "total")
inputter |
The
|
dataframe |
The |
weightvec |
|
choosemethod |
|
Returns a vector of variable names and discrepancies via the method chosen in choosemethod
.
Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).
Finds the discrepancy between the proportion of data in each level of a weighted vector and a set of targets for each level of that same vector. Used as part of anesrake
.
discrep(datavec, targetvec, weightvec)
discrep(datavec, targetvec, weightvec)
datavec |
Vector of values for a particular variable. |
targetvec |
Vector of targets with a single item per level of that variable. |
weightvec |
Weighting vector to be applied to |
Vector of discrepancies at each level.
Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).
Calculates a general design effect given weights for a dataset.
generaldesigneffect(weightvec)
generaldesigneffect(weightvec)
weightvec |
Vector of weights. |
rakelist
takes a list of variables and target values weights a dataset with those variables to match the targets via raking. It is the primary workhorse command of anesrake
.
rakelist(inputter, dataframe, caseid, weightvec = NULL, cap = 999999, verbose = FALSE, maxit = 1000, convcrit = 0.01)
rakelist(inputter, dataframe, caseid, weightvec = NULL, cap = 999999, verbose = FALSE, maxit = 1000, convcrit = 0.01)
inputter |
The
|
dataframe |
The |
caseid |
The |
weightvec |
|
cap |
|
verbose |
Users interested in seeing the progress of the algorithm can set |
maxit |
Users can set a maximum number of iterations for the function should it fail to converge using |
convcrit |
|
A list object of rakelist
has the following elements:
weightvec |
Vector of weights From raking algorithm |
caseid |
Case IDs for final weights – helpful for matching |
iterations |
Number of iterations required for convergence (or non-convergence) of final model |
nonconvergence |
Measure of remaining discrepancy from benchmarks if convergence was not achieved |
converge |
Notes whether full convergence was achieved, algorithm failed to converge because convergence was not possible, or maximum iterations were reached |
varsused |
List of variables selected for weighting |
targets |
|
dataframe |
Copy of the original |
Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).
Shows weighted data on specified variables compared to targets and baseweights.
weightassess(inputter, dataframe, weightvec, prevec = NULL)
weightassess(inputter, dataframe, weightvec, prevec = NULL)
inputter |
The
|
dataframe |
The |
weightvec |
|
prevec |
|
Prints out a list of all levels of all variables named in inputter. For each variable, shows values weighted with prevec, weightvec, and the targets and assesses discrepancies for each.
Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).