train_test function

Split choice data in train and test subset

Split choice data in train and test subset

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 )

Arguments

  • x: An object of class RprobitB_data.
  • 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 "N" (split by deciders) and "T" (split by choice occasions).
  • random: If TRUE, the subsamples are build randomly.
  • seed: Set a seed for building the subsamples randomly.

Returns

A list with two objects of class RprobitB_data, named "train"

and "test".

Details

See the vignette on choice data

for more details.

Examples

### 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)