cv: Function that creates customized cross-validation folds

Description Usage Arguments Examples

View source: R/int.R

Description

The function creates two matrices and returns them as members of a list. 'train' holds training sample indices, columns are cv-folds and rows are sample indices to hold as training samples in each fold. 'test' holds test/validation sample indices, columns are cv-folds and rows are sample indices to hold as test samples in each fold

Usage

1
2
cv(x, fold = 10, strata = rep(1, times = nrow(x)), shuffle = TRUE,
  seed = NULL)

Arguments

x

The original data matrix or data.frame

fold

Number of desired cross-validation folds; preferably between 3 (3-fold CV) and nrow(x) (LOO-CV)

strata

Indicator if some strata should be balanced over the bins; if no balancing is required, the vector should consist of a single value with length equal to rows in x. Otherwise each strata/batch should be indicated as a unique member in the vector.

shuffle

Whether the indices for the data matrix should be shuffled prior to assigning them to train/test bins

seed

A random seed for reproducibility

Examples

1
2
3
4
data(TYKSSIMU)
cvfolds <- cv(x = xMEDISIMU, fold = 3)
cvfolds$train
cvfolds$test

Example output

Attaching package:ePCRThe following object is masked frompackage:graphics:

    plot

The following object is masked frompackage:base:

    plot

[[1]]
  [1]   7  15  19  22  24  35  36  41  42  44  48  50  55  56  58  59  62  67
 [19]  70  71  74  77  84  85  92  93  94  96 100 102 107 108 109 111 114 117
 [37] 123 124 125 131 134 135 137 139 140 141 143 144 147 148   2   3   4   8
 [55]   9  10  11  12  16  17  21  25  26  27  28  31  32  34  37  38  39  40
 [73]  43  47  49  52  53  54  61  65  69  72  75  78  81  82  86  87  88  99
 [91] 113 115 119 120 121 122 127 136 142 146

[[2]]
  [1]   1   5   6  13  14  18  20  23  29  30  33  45  46  51  57  60  63  64
 [19]  66  68  73  76  79  80  83  89  90  91  95  97  98 101 103 104 105 106
 [37] 110 112 116 118 126 128 129 130 132 133 138 145 149 150   2   3   4   8
 [55]   9  10  11  12  16  17  21  25  26  27  28  31  32  34  37  38  39  40
 [73]  43  47  49  52  53  54  61  65  69  72  75  78  81  82  86  87  88  99
 [91] 113 115 119 120 121 122 127 136 142 146

[[3]]
  [1]   1   5   6  13  14  18  20  23  29  30  33  45  46  51  57  60  63  64
 [19]  66  68  73  76  79  80  83  89  90  91  95  97  98 101 103 104 105 106
 [37] 110 112 116 118 126 128 129 130 132 133 138 145 149 150   7  15  19  22
 [55]  24  35  36  41  42  44  48  50  55  56  58  59  62  67  70  71  74  77
 [73]  84  85  92  93  94  96 100 102 107 108 109 111 114 117 123 124 125 131
 [91] 134 135 137 139 140 141 143 144 147 148

[[1]]
 [1]   1   5   6  13  14  18  20  23  29  30  33  45  46  51  57  60  63  64  66
[20]  68  73  76  79  80  83  89  90  91  95  97  98 101 103 104 105 106 110 112
[39] 116 118 126 128 129 130 132 133 138 145 149 150

[[2]]
 [1]   7  15  19  22  24  35  36  41  42  44  48  50  55  56  58  59  62  67  70
[20]  71  74  77  84  85  92  93  94  96 100 102 107 108 109 111 114 117 123 124
[39] 125 131 134 135 137 139 140 141 143 144 147 148

[[3]]
 [1]   2   3   4   8   9  10  11  12  16  17  21  25  26  27  28  31  32  34  37
[20]  38  39  40  43  47  49  52  53  54  61  65  69  72  75  78  81  82  86  87
[39]  88  99 113 115 119 120 121 122 127 136 142 146

ePCR documentation built on Dec. 1, 2019, 1:21 a.m.

Related to cv in ePCR...