View source: R/data_management.R
train_test | R Documentation |
This function splits choice data into a train and a test part.
train_test(
x,
test_proportion = NULL,
test_number = NULL,
by = "N",
random = FALSE,
seed = NULL
)
x |
An object of class |
test_proportion |
A number between 0 and 1, the proportion of the test subsample. |
test_number |
A positive integer, the number of observations in the test subsample. |
by |
One of |
random |
If |
seed |
Set a seed for building the subsamples randomly. |
See the vignette on choice data for more details.
A list with two objects of class RprobitB_data
, named "train"
and "test"
.
### simulate choices for demonstration
x <- simulate_choices(form = choice ~ covariate, N = 10, T = 10, J = 2)
### 70% of deciders in the train subsample,
### 30% of deciders in the test subsample
train_test(x, test_proportion = 0.3, by = "N")
### 2 randomly chosen choice occasions per decider in the test subsample,
### the rest in the train subsample
train_test(x, test_number = 2, by = "T", random = TRUE, seed = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.