View source: R/sampleControlElements.R
sampleControlElements | R Documentation |
Randomly sample from a set of control (background) elements, such that the selected elements are similarly distributed as a given set of target (foreground) elements.
sampleControlElements(
x,
idxTarget,
idxControl = NULL,
nbins = 50,
oversample = 1
)
x |
|
idxTarget |
|
idxControl |
|
nbins |
|
oversample |
The number of control elements to sample for each target element. |
numeric
vector with round(length(idxTarget) * oversample)
elements, specifying the index (positions) of the sampled control elements.
Michael Stadler
x <- c(runif(1000, min = 0, max = 10),
rnorm(200, mean = 5, sd = 1))
s <- sampleControlElements(x, idxTarget = 1001:1200, idxControl = 1:1000)
par(mfrow=c(2,2))
h <- hist(x, breaks = 20, main = "all")
hist(x[1:1000], breaks = h$breaks, main = "all control")
hist(x[1001:1200], breaks = h$breaks, main = "target")
hist(x[s], breaks = h$breaks, main = "sampled control")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.