Skip to content

Commit

Permalink
Merge pull request #14 from philmikejones/examples
Browse files Browse the repository at this point in the history
bump version
  • Loading branch information
philmikejones authored Sep 9, 2016
2 parents 39d85fe + 990398f commit f33a5eb
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rakeR
Title: Spatial Microsimulation (Raking) Helper Functions
Version: 0.0.0.9000
Version: 0.0.1
Authors@R: person("Phil Mike", "Jones", email = "[email protected]", role = c("aut", "cre"))
Description: Helper functions for performing spatial microsimulation ('raking')
in R.
Expand Down
44 changes: 42 additions & 2 deletions R/rake_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,27 @@ weight <- function(cons, inds, vars = NULL, iterations = 10) {
#' @return A data frame of integerised weights to be used by \code{simulate()}
#' @export
#'
#' @examples # not run
#' @examples
#' cons <- data.frame(
#' "zone" = letters[1:3],
#' "a0_49" = c(8, 2, 7),
#' "a_gt50" = c(4, 8, 4),
#' "f" = c(6, 6, 8),
#' "m" = c(6, 4, 3)
#' )
#'
#' inds <- data.frame(
#' "id" = LETTERS[1:5],
#' "age" = c("a_gt50", "a_gt50", "a0_49", "a_gt50", "a0_49"),
#' "sex" = c("m", "m", "m", "f", "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)
#' weights_int
integerise <- function(weights, method = "trs") {

# Ensures the output of the function is reproducible (uses sample())
Expand Down Expand Up @@ -246,7 +266,27 @@ integerise <- function(weights, method = "trs") {
#' @export
#'
#' @examples
#' # not run
#' cons <- data.frame(
#' "zone" = letters[1:3],
#' "a0_49" = c(8, 2, 7),
#' "a_gt50" = c(4, 8, 4),
#' "f" = c(6, 6, 8),
#' "m" = c(6, 4, 3)
#' )
#'
#' inds <- data.frame(
#' "id" = LETTERS[1:5],
#' "age" = c("a_gt50", "a_gt50", "a0_49", "a_gt50", "a0_49"),
#' "sex" = c("m", "m", "m", "f", "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)
#' sim_df <- simulate(weights_int, inds)
#' sim_df
simulate <- function(weights, inds) {

weights <- as.matrix(weights)
Expand Down
21 changes: 20 additions & 1 deletion man/integerise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion man/simulate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/test_integerise.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ vars <- c("age", "sex")
weights <- weight(cons = cons, inds = inds, vars = vars)
weights_int <- integerise(weights)


test_that("integerised weights should add up to cons population", {
expect_equal(sum(weights_int), sum(weights))
expect_equal(sum(weights_int), (sum(cons[, -1] / length(vars))))
Expand Down

0 comments on commit f33a5eb

Please sign in to comment.