Package raker. October 10, 2017

Similar documents
Package fastdummies. January 8, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package datasets.load

Package clipr. June 23, 2018

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package spark. July 21, 2017

Package ECctmc. May 1, 2018

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package canvasxpress

Package validara. October 19, 2017

Package sfc. August 29, 2016

Package geogrid. August 19, 2018

Package mdftracks. February 6, 2017

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package repec. August 31, 2018

Package messaging. May 27, 2018

Package kirby21.base

Package gtrendsr. October 19, 2017

Package bisect. April 16, 2018

Package ecoseries. R topics documented: September 27, 2017

Package editdata. October 7, 2017

Package tidytransit. March 4, 2019

Package SEMrushR. November 3, 2018

Package fingertipsr. May 25, Type Package Version Title Fingertips Data for Public Health

Package condusco. November 8, 2017

Package sankey. R topics documented: October 22, 2017

Package projector. February 27, 2018

Package nonlinearicp

Package balance. October 12, 2018

Package estprod. May 2, 2018

Package labelvector. July 28, 2018

Package IATScore. January 10, 2018

Package strat. November 23, 2016

Package jstree. October 24, 2017

Package testit. R topics documented: June 14, 2018

Package comparedf. February 11, 2019

Package PCADSC. April 19, 2017

Truncate, replicate, sample

Package opencage. January 16, 2018

Package gtrendsr. August 4, 2018

Package dbx. July 5, 2018

Package calpassapi. August 25, 2018

Package robotstxt. November 12, 2017

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package wrswor. R topics documented: February 2, Type Package

Package barcoder. October 26, 2018

Package deductive. June 2, 2017

Package datapasta. January 24, 2018

Package widyr. August 14, 2017

Package crossword.r. January 19, 2018

Package exifr. October 15, 2017

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package splithalf. March 17, 2018

Package RODBCext. July 31, 2017

Package rgho. R topics documented: January 18, 2017

Package censusapi. August 19, 2018

Package vinereg. August 10, 2018

Package ompr. November 18, 2017

Package graphframes. June 21, 2018

Package sessioninfo. June 21, 2017

Package modmarg. R topics documented:

Package tidyimpute. March 5, 2018

Package MatchIt. April 18, 2017

Package crochet. January 8, 2018

Package crossrun. October 8, 2018

Package farver. November 20, 2018

Package postgistools

Package nngeo. September 29, 2018

Package ether. September 22, 2018

Package available. November 17, 2017

Package d3r. January 29, 2019

Package lumberjack. R topics documented: July 20, 2018

Package fst. December 18, 2017

Package tibble. August 22, 2017

Package BiocManager. November 13, 2018

Package collapsibletree

Package samplesizecmh

Package pinyin. October 17, 2018

Package embed. November 19, 2018

Package githubinstall

Package GetHFData. November 28, 2017

Package oec. R topics documented: May 11, Type Package

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package regexselect. R topics documented: September 22, Version Date Title Regular Expressions in 'shiny' Select Lists

Package rcv. August 11, 2017

Package waver. January 29, 2018

Package Rspc. July 30, 2018

Package zoomgrid. January 3, 2019

Package narray. January 28, 2018

Package icarus. March 4, 2017

Package colf. October 9, 2017

Package nlgeocoder. October 8, 2018

Package knitrprogressbar

Package rpostgislt. March 2, 2018

Package pmatch. October 19, 2018

Package stapler. November 27, 2017

Package GetITRData. October 22, 2017

Package OLScurve. August 29, 2016

Package vip. June 15, 2018

Transcription:

Title Easy Spatial Microsimulation (Raking) in R Version 0.2.1 Date 2017-10-10 Package raker October 10, 2017 Functions for performing spatial microsimulation ('raking') in R. Depends R (>= 3.4.0) License GPL-3 Encoding UTF-8 LazyData true RoxygenNote 6.0.1 Imports ipfp, wrswor Suggests testthat, readr URL https://philmikejones.github.io/raker/ BugReports https://github.com/philmikejones/raker/issues NeedsCompilation no Author Phil Mike Jones [aut, cre] (0000-0001-5173-3245), Robin Lovelace [aut] (Many functions are based on code by Robin Lovelace and Morgane Dumont), Morgane Dumont [aut] (Many functions are based on code by Robin Lovelace and Morgane Dumont), Andrew Smith [ctb] Maintainer Phil Mike Jones <philmikejones@gmail.com> Repository CRAN Date/Publication 2017-10-10 13:44:46 UTC R topics documented: check_constraint...................................... 2 check_ind.......................................... 3 1

2 check_constraint extract............................................ 3 extract_weights....................................... 4 integerise.......................................... 5 rake............................................. 6 simulate........................................... 7 weight............................................ 7 Index 10 check_constraint check_constraint Checks a constraint table for common errors. check_constraint(constraint_var, num_zones) Details constraint_var The constraint table to check, usually a data frame num_zones The number of zones that should be present in the table Checks a constraint table for the following common errors: Ensures all zone codes are unique Ensures there are the expected number of zones Ensures all but the zone column are numeric (integer or double) If no errors are detected the function returns silently. Any errors will stop the function or script to be investigated. cons <- data.frame( "zone" = letters[1:3], "age_0_49" = c(8, 2, 7), "age_gt_50" = c(4, 8, 4), "sex_f" = c(6, 6, 8), "sex_m" = c(6, 4, 3) ) check_constraint(cons, 3) # no errors

check_ind 3 check_ind check_ind Checks an individual (survey) variable for common errors. check_ind(ind_var) ind_var the individual (survey) variable you want to check Details Checks an individual (survey) variable for the following common errors: That each row sums to 1 (i.e. correctly converted to a dummy variable) If no errors are detected the function returns silently. Any errors will stop the function or script to be investigated. ## check_ind(ind_var) extract extract Extract aggregate weights from individual weight table extract(weights, inds, id) weights inds id A weight table, typically produced by raker::weight() The individual level data The unique id variable in the individual level data (inds), usually the first column

4 extract_weights Details Extract aggregate weights from individual weight table, typically produced by raker::weight() Extract cannot operate with numeric variables because it creates a new variable for each unique factor of each variable If you want numeric information, like income, use integerise() instead. A data frame with zones and aggregated simulated values for each variable ## Not run ## Use weights object from weights() ## ext_weights <- extract(weights = weights, inds = inds, id = "id") extract_weights extract_weights Deprecated: use raker::extract() extract_weights(weights, inds, id) weights inds id A weight table, typically produced by raker::weight() The individual level data The unique id variable in the individual level data (inds), usually the first column A data frame with zones and aggregated simulated values for each variable ## Not run ## extract_weights() is deprecated, use extract() instead

integerise 5 integerise integerise Generate integer cases from numeric weights matrix. integerise(weights, inds, method = "trs", seed = 42) weights inds Details method A matrix or data frame of fractional weights, typically provided by raker::weight() The individual level data (i.e. one row per individual) The integerisation method specified as a character string. Defaults to "trs"; currently other methods are not implemented. seed The seed to use, defaults to 42. Extracted weights (using raker::extract()) are more precise than integerised weights (although the user should be careful this is not spurious precision based on context) as they return fractions. Nevertheless, integerised weights are useful in cases when: Numeric information (such as income) is required, as this needs to be cut() to work with raker::extract() Simulated individuals are required for case studies of key areas. Input individual-level data for agent-based or dynamic models are required The default integerisation method uses the truncate, replicate, sample method developed by Robin Lovelace and Dimitris Ballas http://www.sciencedirect.com/science/article/pii/s0198971513000240 Other methods (for example proportional probabilities) may be implemented at a later date. A data frame of integerised cases cons <- data.frame( "zone" = letters[1:3], "age_0_49" = c(8, 2, 7), "age_gt_50" = c(4, 8, 4), "sex_f" = c(6, 6, 8), "sex_m" = c(6, 4, 3), stringsasfactors = FALSE

6 rake ) inds <- data.frame( "id" = LETTERS[1:5], "age" = c("age_gt_50", "age_gt_50", "age_0_49", "age_gt_50", "age_0_49"), "sex" = c("sex_m", "sex_m", "sex_m", "sex_f", "sex_f"), "income" = c(2868, 2474, 2231, 3152, 2473), stringsasfactors = FALSE ) vars <- c("age", "sex") weights <- weight(cons = cons, inds = inds, vars = vars) weights_int <- integerise(weights, inds = inds) rake rake A convenience function wrapping weight() and extract() or weight() and integerise() rake(cons, inds, vars, output = "fraction", iterations = 10,...) cons inds vars output A data frame of constraint variables A data frame of individual level (survey) data A character string of variables to iterate over A string specifying the desired output, either "fraction" (extract()) or "integer" (integerise()) iterations The number of iterations to perform. Defaults to 10.... Additional arguments to pass to depending on desired output: if "fraction" specify id (see extract() documentation) if "integer" specify method and seed (see integerise() documentation) A data frame with extracted weights (if output == "fraction", the default) or integerised cases (if output == "integer")

simulate 7 ## not run ## frac_weights <- rake(cons, inds, vars, output = "fraction", ## id = "id") ## int_weight <- rake(cons, inds, vars, output = "integer", ## method = "trs", seed = "42") simulate simulate Deprecated: integerise() %>% simulate() has been replaced by simply integerise() to be consistent with extract(). simulate(...)... arguments previously passed to simulate() Returns an error if used. Just use integerise() weight weight Produces fractional weights using the iterative proportional fitting algorithm. weight(cons, inds, vars = NULL, iterations = 10)

8 weight cons inds vars Details A data frame containing all the constraints. This should be in the format of one row per zone, one column per constraint category. The first column should be a zone code; all other columns must be numeric counts. A data frame containing individual level (survey) data. This should be in the format of one row per individual, one column per constraint. The first column should be an individual ID. A character vector of variables that constrain the simulation (i.e. independent variables) iterations The number of iterations the algorithm should complete. Defaults to 10 The first column of each data frame should be an ID. The first column of cons should contain the zone codes. The first column of inds should contain the individual unique identifier. Both data frames should only contain: an ID column (zone ID cons or individual ID inds). constraints inds or constraint category cons. inds can optionally contain additional dependent variables that do not influence the weighting process. No other columns should be present (the user can merge these back in later). It is essential that the levels in each inds constraint (i.e. column) match exactly with the column names in cons. In the example below see how the column names in cons ('age_0_49', 'sex_f',...) match exactly the levels in inds variables. The columns in cons must be in alphabetical order because these are created alphabetically when they are spread in the individual level data. A data frame of fractional weights for each individual in each zone with zone codes recorded in column names and individual id recorded in row names. # SimpleWorld cons <- data.frame( "zone" = letters[1:3], "age_0_49" = c(8, 2, 7), "age_gt_50" = c(4, 8, 4), "sex_f" = c(6, 6, 8), "sex_m" = c(6, 4, 3), stringsasfactors = FALSE ) inds <- data.frame( "id" = LETTERS[1:5], "age" = c("age_gt_50", "age_gt_50", "age_0_49", "age_gt_50", "age_0_49"),

weight 9 "sex" = c("sex_m", "sex_m", "sex_m", "sex_f", "sex_f"), "income" = c(2868, 2474, 2231, 3152, 2473), stringsasfactors = FALSE ) # Set variables to constrain over vars <- c("age", "sex") weights <- weight(cons = cons, inds = inds, vars = vars) print(weights)

Index check_constraint, 2 check_ind, 3 extract, 3 extract_weights, 4 integerise, 5 integerize (integerise), 5 rake, 6 simulate, 7 weight, 7 10