kfold_cv_lm: K-fold Cross Validation for linear models

Description Usage Arguments Details Value Examples

View source: R/kfold_cv_lm.R

Description

Returns the mean of the mean risks calculated in through k-fold cross validation for each specified formula

Usage

1
kfold_cv_lm(data, formulae, nfolds = 5)

Arguments

data

The dataset you would like to run k-fold cross validation on

formulae

One or more strings that are converted to a Formula object

nfolds

The number of folds you would like to use, default to 5

Details

This function subsets the data given by the data argument into k randomly assigned subsets. Each subset is then broken up into training and testing data for each fold. A linear model is fit for each fold for each formula, and then the MSE is calculated. Once all of the k MSEs are calculated for a formula, the mean of the MSEs are returned.

Value

The mean of the mean risks calculated in each iteration of the cross validation for each specified formula

Examples

1
2
3
4
kfold_cv_lm(data = iris, formulae = "Sepal.Length ~ Sepal.Width", nfolds = 5)
kfold_cv_lm(data = iris, formulae = c("Sepal.Length ~ Sepal.Width",
"Sepal.Length ~ Petal.Length"),
 nfolds = 5)

joestoica/STAT-S-432-Package documentation built on Nov. 4, 2019, 3:04 p.m.