This function runs ACMTF-R with cross-validation. A deterministic K–fold partition
is used: the subjects are split in order into cvFolds
groups. For each fold the
training set consists of the other folds and the test set is the current fold.
Usage
ncrossreg(X, y, maxNumComponents = 5, maxIter = 120, cvFolds = dim(X)[1])
Arguments
- X
Centered tensor of independent data
- y
Centered dependent variable
- maxNumComponents
Maximum number of components to investigate (default 5).
- maxIter
Maximum number of iterations (default 100).
- cvFolds
Number of folds to use in the cross-validation. For example, if
cvFolds
is 5, then the subjects are deterministically partitioned into 5 groups (each CV iteration uses 4/5 for training and 1/5 for testing). Default: equal to the number of subjects (i.e. jack-knifing).
Value
A list with two elements: - varExp: a tibble with the variance–explained (for X and Y) per number of components. - RMSE: a tibble with the RMSE (computed over the unified CV prediction vector) per number of components.
Examples
Y = as.numeric(as.factor(Cornejo2025$Tongue$mode1$GenderID))
Ycnt = Y - mean(Y)
ncrossreg(Cornejo2025$Tongue$data, Ycnt, cvFolds=2)
#> $varExp
#> # A tibble: 5 × 3
#> numComponents X Y
#> <dbl> <dbl> <dbl>
#> 1 1 2.97 43.5
#> 2 2 6.77 75.9
#> 3 3 11.8 85.1
#> 4 4 16.1 89.2
#> 5 5 19.0 92.6
#>
#> $RMSE
#> # A tibble: 5 × 2
#> numComponents RMSE
#> <int> <dbl>
#> 1 1 0.511
#> 2 2 0.597
#> 3 3 0.720
#> 4 4 0.850
#> 5 5 0.882
#>