View source: R/fakeunion_functions.r
samplePartners | R Documentation |
This function will draw a set of counterfactual partners for a given set of real unions.
It is primarily intended for internal use by the generateCouples
functiom.
samplePartners(actual, eligibles, n, partner, weight = NULL, id = "id")
actual |
a data.frame of actual unions identical in structure to that for |
eligibles |
a data.frame of eligible partners to be sampled. This should
have the same structure as that for |
n |
The number of alternate partners to sample for each real spouse. |
partner |
a character sting of either "h" or "w" indicating which type of partner should be sampled. |
weight |
optional name of weights variable in eligibles that allows for different probabilities of sampling eligible partners. If left out then sampling will be done with equal probability |
id |
a character string indicating the first part of the variable name for the id to identify indidividuals in actual and eligibles. Identical to the argument in generateCouples. |
This function uses the wrswoR package for fast weighted sampling without replacement. In addition, for speed, the initial matching is done without concern for potentially sampling the correct partner from the set of alternate partners. This is then checked and removed in a secondary stage for the rare cases where such duplication occurs.
a data.frame object similar to actual
but containing only counterfactual unions.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.