train_test: Split choice data into train and test subset

View source: R/train_test.R

train_testR Documentation

Split choice data into 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
)

Arguments

x

An object of class RprobitB_data.

test_proportion

[numeric(1)]
The proportion of the test subset.

test_number

[integer(1)]
The number of observations in the test subset.

by

[character(1)]
Either "N" (split by deciders) and "T" (split by occasions).

random

[logical(1)]
Build subsets randomly?

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)


RprobitB documentation built on Aug. 26, 2025, 1:08 a.m.