# K-Fold Cross Validation¶

## Overview¶

The K-Fold cross validation feature is used to assess how well a model can predict a phenotype. Training data (subjects we have both phenotype and genotype data for) is partitioned into subsamples and for iterations, each of these subsamples (or folds) is selected to be the validation set and the model is fit with the other folds and predicts the validation set. We can then analyze how well the model was able to predict the phenotypes for these samples in the validation set as we know their true phenotype values.

The initial spreadsheet, if in genotypic format, will be numerically recoded to ensure the major/minor alleles are the same for each fold.

Note

This method uses (with a genotypic spreadsheet) or assumes (with a numerically recoded spreadsheet) an additive genetic model.

## Large N Considerations¶

If your dataset consists of more than 8,000 samples (5,500 for 32-bit systems), you will first be presented with the following dialog:

If you are using the *Genomic Best Linear Unbiased Predictors (GBLUP)*
prediction method (*Options*), please see
*Summary of Performance Tradeoffs* to know how best to respond to this prompt.

If you are using *Bayes C-pi* or *Bayes C*, please select the *Exact*
method. You may use the tool documented in
*Separately Computing the Genomic Relationship Matrix*, if you wish, to pre-compute a Genomic
Relationship Matrix and use that for K-Fold cross validation.

After answering this prompt, you will be taken to the standard K-Fold cross validation options explained below.

## Options¶

**Method(s)**: The following genomic prediction methods are available for cross validation:*Genomic Best Linear Unbiased Predictors (GBLUP)*: please see*Genomic Best Linear Unbiased Predictors Analysis**Bayes C-pi*: please see*Bayes C and C-pi Genomic Prediction Analysis*.*Bayes C*: please see*Bayes C and C-pi Genomic Prediction Analysis*.

**Bayesian Options**: The following parameters can be set and will affect the Bayes C and Bayes C methods:*Number of Iterations*: Enter the number of iterations the MCMC loop should run for.*Burn-in*: How many samples should be thrown out from the beginning of the chain. Set this to 0 for no burn-in.*Thinning*: Only store one sample every*x*iterations, where*x*is the number entered in the box. Set this to 0 for no thinning.*Initial Pi*: This will be either the initial value of for Bayes C or the fixed value of for Bayes C.*Computation Method*:*As Is*will treat the genotypes values as either a 0, 1, or 2 (number of minor alleles).*Centered*will code genotypes as 0, 1, or 2, subtracted by the marker mean.

**Correct For Gender**: Assumes the column coded as if the male were heterozygous for the X-Chromosome allele in question. For GBLUP and Bayesian implementations, please see*gblupGenderCorrOverall*and*Gender Correction*, respectively.Note

This option will only be available if there is a marker map and it contains at least one column in a chromosome that is listed in the assembly file as an allosome. The drop down list will only have chromosomes that are both allosomes and in this spreadsheet.

**Use Pre-Computed Genomic Relationship Matrix**: To use, check this option and click on**Select Sheet**and select the genomic relationship matrix spreadsheet from the window that is presented. To be valid, this spreadsheet must follow the rules outlined in Precomputed Kinship Matrix Option.*Precomputed Kinship Matrix Option*.Note

The HWE variance sum is re-calculated form the genotypic data being used for this analysis.

**Correct for Additional Covariates**: Allows additional fixed effects to be added to this model from this spreadsheet. Fixed effect coefficients can be binary, integer, real-values, categorical, or genotypic. In all cases, if a marker is chosen as an additional fixed effect, it will not be included in the analysis in any other way. To begin, check this option, then click on**Add Columns**to get a choice of spreadsheet columns to use.**Impute Missing Genotypic Data As**: Missing genotypic data can be imputed by either of the following methods:*Homozygous major allele*: All missing genotypic data will be recoded to 0.*Numerically as average value*: All missing genotypic data will be recoded to the average of all non-missing genotype calls (using the additive model).Note

If

**Correct for Gender**(see below) is also selected, and there is non-missing data for both males and females in a given marker, averages for males and females will be computed and used separately.

**Stratify Folds by**: To use stratified random sampling instead of simple random sampling for splitting up the data into folds, check this option and choose either a categorical or binary column for the subpopulation column.**Number of Folds**: This is the in K-Fold, where is the number of subsamples the dataset is randomly partitioned into and the number of times the cross-validation process is repeated. For each iteration, one subsample is left out of the analysis and is used as the validation set.**Number of Iterations**: Set the number of times folds will be run.**Delete intermediate spreadsheets with results for each fold?**: If checked, this option will delete the per fold result options and only the final results will be visible.

## Output¶

For each fold the following spreadsheets will be created:

**(Method Name) estimates by marker - Fold #**: Contains the estimates of the allele substitution effect (ASE) by marker with their normalized and absolute values of normalized values. If gender correction is applied, separate columns for the ASE will be outputted for both males and females. If there was a marker map on the original spreadsheet, it will be applied to this one.**(Method Name) fixed effect coefficients - Fold #**: Contains the coefficient corresponding to each fixed effect. If there were no fixed effects chosen, the only coefficient will be the intercept. For categorical covariates, the reference category will be listed with missing for the coefficient and a 1 in the the “Reference Covariate?” column. The “Reference Covariate?” column will contain a 0 for all non categorical and non reference covariates.**(Method Name) estimates by sample - Fold #**: Contains the actual and predicted phenotype, with the missing samples in the actual column being the validation set. For Bayes C/C-, this will be phenotypes after they are transformed. Please see*Standardizing Phenotype Values*.**(Method Name) Genomic Relationship Matrix**: the kinship matrix calculated from the original training set. Please see*The Genomic Relationship Matrix*.Note

The following will only be outputted for the Bayesian methods.

**(Method Name) Run Log - Fold #**: Lists how many markers were included in every hundredth iteration.**(Method Name) Trace Spreadsheet - Fold #**: Lists the values sampled for during each iterations for , , , and the number of markers included, for males and females.**Plot of Numeric Values from (Method Name) Trace Spreadsheet - Fold #**: This is a trace plot representation of the information in the Trace Spreadsheet. Autocorrelation plots can be made from the columns in this spreadsheet, please see*Autocorrelation Plots*.

After all the folds have run:

**(Method Name) - ASE**: These are the average ASE values over all folds.**(Method Name) - Fixed Effect Coefficients**: These are the average coefficients over all folds.**(Method Name) Final Results**: These are the combined predicted phenotype values and the actual values. The predicted values are taken from the predicted phenotypes for the validation set from each fold. Also, the actual phenotypes and fold number each sample was predicted in will be displayed.**(Method Name) Summary Statistics**: This contains the overall and per fold statistics. Please see*Statistics*

Note

If more than one iteration is performed, the per-fold output spreadsheets will also include an iteration number.

## Sampling¶

There are two different sampling techniques available for partitioning the data.

**Simple Random Sampling**:

Each sample has the same probability of being selected.

**Stratified Random Sampling**:

Each subpopulation (grouped by either a categorical or binary variable) is sampled separately and then these samples are combined to ensure a sample with proportional representation of each subgroup.

## Statistics¶

For each fold and the whole dataset, the following statistics are calculated. is the sample size and are the phenotype values.

The means and standard deviations are calculated when there are more than one iterations performed.

### Overall Statistics¶

The overall statistics listed before the per fold statistics use the actual phenotype values for and the predicted phenotype value, , for each sample from the fold where it was part of the validation set. So, if sample 1 was part of the validation set in fold 3, it’s predicted value from fold 3 will be the value included in .

These values can be seen in the **(Method Name) Final Results** spreadsheet. The
*Fold Predicted in* column indicates in which fold a sample was part of the
validation set.

### Quantitative Statistics¶

#### Residual Sum of Squares¶

#### Total Sum of Squares¶

#### R-Squared¶

#### Root Mean Square Error¶

#### Mean Absolute Error¶

### Binary Statistics¶

#### Area Under the Curve (Using the Wilcoxon Mann Whitney method)¶

where is the sample size of observations with actual phenotypes of 0 and is the sample size of observations with actual phenotypes of 1.

And

where is the sum of the ranks for the predicted phenotypes with actual phenotypes of 0.

#### Mathews Correlation Coefficient¶

where is the the number of true positives, is the number of true negatives, is the number of false positives, and is the number of false negatives in the predicted phenotypes. Since GBLUP and Bayes C and C treat binary values as quantitative and predict in the range from 0 to 1, we treat predicted values of 0.5 and higher as 1 and below 0.5 as 0.

#### Accuracy¶

#### Sensitivity (or true positive rate)¶

#### Specificity (or true negative rate)¶

#### Root Mean Square Error¶

### Iteration Level Statistics¶

When there are more than two iterations, the statistics calculated at the end of each iteration will be stored and when K-Fold is done, the mean and standard deviation will be found. These values will be reported on a separate result viewer.