kfold: k-Folds Crossvalidation

View source: R/kfold.R

kfoldR Documentation

k-Folds Crossvalidation

Description

k-Folds crossvalidation for item selection using any approach implemented in STUART.

Usage

kfold(
  type,
  k = 5,
  max.invariance = "strict",
  seed = NULL,
  seeded.search = TRUE,
  ...,
  remove.details = TRUE
)

Arguments

type

A character calling the item-selection procedure. Can be one of "mmas" (see mmas), "gene" (see gene), "bruteforce" (see bruteforce), or randomsamples (see randomsamples).

k

The number of folds.

max.invariance

The maximum measurement invariance level which will be tested. Currently there are four options: 'configural', 'weak', 'strong', and 'strict' (the default). All levels below max.invariance are also tested.

seed

The random seed.

seeded.search

A logical indicating whether the seed should also be used for the search procedure (the default) or only for the sample splitting.

...

Arguments passed to the item-selection procedure called with type.

remove.details

A logical indicating whether to remove detailed information such as models and copies of datasets. Reduces output size by approx. 90%. Defaults to TRUE.

Details

The function splits the provided data into k subsets using holdout and runs the item-selection procedure requested via type on the training datasets. Validation is performed using crossvalidate to check for invariance of the measurement models between the training and validation data up to the invariance level provided via max.invariance. The final item selection is based on the highest value on the objective function in the multiple-group SEM imposing max.invariance between the training and validation data.

Value

Returns an object of the class stuartKfold for which specific summary and print methods are available. The results are a list.

call

The called function.

subtests

A list containing the names of the selected items and their respective subtests.

solution

A list of matrices with the choices made in the global-best solution.

final

The results of the estimation of the solution leading to best objective value when cross-validated.

frequencies

A list of matrices showing the relative frequencies with which an item was selected across the k-folds.

full

A list of the results returned by the k runs of type.

crossvalidations

A list of data.frames showing the fit and model comparisons of all invariance levels up to max.invariance in each of the k folds.

data

A data.frame. The same as the original data.frame provided to data with the added variable stuartKfold indicating which fold an observation was assigned to.

Author(s)

Martin Schultze

See Also

holdout crossvalidate

Examples


# k-Folding for a simple bruteforce selection
data(fairplayer)
fs <- list(ra = names(fairplayer)[53:57])

sel <- kfold('bruteforce', k = 2,
  data = fairplayer, factor.structure = fs, 
  capacity = 3, seed = 55635,
  cores = 1)
summary(sel)


### longitudinal example with mmas ----
data(fairplayer)
fs <- list(si1 = names(fairplayer)[83:92],
  si2 = names(fairplayer)[93:102],
  si3 = names(fairplayer)[103:112])

repe <- list(si = c('si1', 'si2', 'si3'))

sel_mmas <- kfold('mmas', k = 3,
  data = fairplayer, factor.structure = fs,
  repeated.measures = repe, long.invariance = 'strong',
  capacity = 3, seed = 55635, pbest = .5,
  cores = 1)
summary(sel_mmas)




stuart documentation built on June 7, 2023, 6:12 p.m.