split_holdout: Split Data Into Discovery and Confirmation Sets

View source: R/confirm.R

split_holdoutR Documentation

Split Data Into Discovery and Confirmation Sets

Description

Partitions a data frame into two disjoint subsets of original observations, before imputation. Each subset should then be imputed separately, so that neither half's outcomes inform the other's imputed predictor values.

Usage

split_holdout(data, prop = 0.5, strata = NULL, cluster = NULL, seed = NULL)

Arguments

data

A data frame, typically containing missing values.

prop

Proportion of observations assigned to the discovery set. Default 0.5.

strata

Optional name of a column on which to stratify the split, so that its distribution is preserved in both halves. Ordinarily the outcome, if categorical. Rows with a missing value in this column are allocated at random. When cluster is given, strata must be constant within each cluster, and the clusters are stratified.

cluster

Optional name of a column identifying a higher-level unit such as a school, district or site. When given, whole clusters are assigned to one half or the other, so that no cluster contributes observations to both. prop then refers to the proportion of clusters.

seed

Optional integer seed.

Details

The split is performed on original observations, not on stacked rows, and before any imputation. This matters. Imputing the full data once and then splitting leaves each half's imputed values informed by the other half's outcomes, which compromises the independence the confirmation step relies on. Impute the two halves separately.

Clustered data

When observations are nested in higher-level units, splitting rows at random places members of the same unit on both sides, and the confirmation sample is then not independent of the discovery sample in the way the test assumes. Passing the unit identifier as cluster keeps every unit intact on one side. The confirmation test in confirm_ctreeMI() should then use a cluster-robust variance by passing the same cluster argument there.

With few clusters the two halves may be unequal in rows even when equal in clusters. The returned n_clusters reports the count on each side.

Value

A list of class "ctreeMI_split" with elements discover and confirm, each a data frame; index, the row indices of data assigned to the discovery set; cluster, the cluster column name or NULL; and, when clustered, n_clusters for each half.

See Also

confirm_ctreeMI(), discover_confirm()

Examples

set.seed(1)
d <- data.frame(x = rnorm(200), y = rnorm(200))
d$x[sample(200, 30)] <- NA
parts <- split_holdout(d, prop = 0.5, seed = 1)
nrow(parts$discover); nrow(parts$confirm)

ctreeMI documentation built on Oct. 12, 2026, 5:08 p.m.