| split_holdout | R Documentation |
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.
split_holdout(data, prop = 0.5, strata = NULL, cluster = NULL, seed = NULL)
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 |
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. |
seed |
Optional integer seed. |
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.
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.
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.
confirm_ctreeMI(), discover_confirm()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.