sample_biased: Create samples biased on the categories of one variable

View source: R/analyse.R

sample_biasedR Documentation

Create samples biased on the categories of one variable

Description

This function creates a data.frame which includes one or more samples taken from the original data. These samples are biased on the categories of one variable: some of the categories can be given a lower probability of inclusion than others.

Usage

sample_biased(data, x, probs, size, iterations = 1, replace = FALSE)

Arguments

data

An object of type data.frame.

x

A vector included in the data, which will be used to bias the sample.

probs

A vector of probabilities which has the same length as the number of values x can take.

size

The number of observations to include in each sample.

iterations

The number of samples to take from the data.frame.

replace

Should sampling be with replacement?

Value

The sampled data, with all columns from the original data.frame and a prob column indicating the probability of inclusion of each observation. If iterations > 1, an iterations column is included to identify which iteration the observation belongs to.

Author(s)

CLESSN

Examples


## Not run: 

# Create a 100-respondent sample where men are three
# times more likely to be included than women.

sample_biased(Data, genderWoman,
probs = c(3, 1), size = 100)

## End(Not run)


clessn/clessn-verse documentation built on Feb. 18, 2024, 12:42 p.m.