subsample | R Documentation |
Generate a vector of subsamples.
subsample( x, trt = NULL, trt_control = "Control", training_fraction = NULL, validation_fraction = NULL, test_fraction = NULL, n_samples = 1 )
x |
<Source data to subsample. |
trt |
Treatment variable. (optional) |
trt_control |
Value for treatment control arm. Defaulte value is 'Control'. |
training_fraction |
Fraction of source data to include in training subsample. |
validation_fraction |
Fraction of source data to include in validation subsample. |
test_fraction |
Fraction of source data to include in test subsample. |
n_samples |
Number of subsamples to generate. |
Each subsample will contain training, validation, and test data in proportions specified by the user. If a treatment variable is supplied the ratio of treatments will be preserved as closely as possible.
Vector of objects of class Subsample.
Subsample
## Generate example data frame containing response and treatment N <- 50 x <- data.frame( runif( N ) ) names( x ) <- "response" x$treatment <- factor( sample( c("Control","Experimental"), size = N, prob = c(0.8,0.2), replace = TRUE ) ) ## Generate two subsamples ex1 <- subsample( x, training_fraction = 0.9, test_fraction = 0.1, n_samples = 2 ) ## Generate two subsamples preserving treatment ratio ex2 <- subsample( x, trt = x$treatment, trt_control = "Control", training_fraction = 0.7, validation_fraction = 0.2, test_fraction = 0.1, n_samples = 2 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.