train_test: Split choice data in train and test subset

View source: R/data_management.R

train_testR Documentation

Split choice data in train and test subset

Description

This function splits choice data into a train and a test part.

Usage

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.

Details

See the vignette on choice data for more details.

Value

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

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)


RprobitB documentation built on Nov. 10, 2022, 5:12 p.m.