optimize_lambda: Optimize Lambda for a given ridge regression function

Description Usage Arguments Value Examples

View source: R/optimize_lambda.R

Description

This function help to choose optimal lambda parameter from a given set by conducting cross-validation to the models with different lambdas and return the lambda that gives the smallest mean squared error. This function was based on the function ridge_regression.

Usage

1
optimize_lambda(formula, data, lambda.set, folds = 10, ...)

Arguments

formula

a symbolic description of the model to be fitted. This should be a formula class argument.

data

Specification of a dataframe that contains the variables in the model.

lambda.set

a set of lambdas to be checked. This should be a vector of values or a sequence of numbers.

folds

Number of folds used in the k-fold cross-validation

...

other inputs that need to be passed to the function ridge_regression.

Value

a optimal value from the specified set of lambda which returns the smallest MSE in the cross-validation check, the vector of MSE over all lambdas, and the minimum of the MSE.

Examples

1
2
data(iris)
optimize_lambda(Sepal.Length ~ ., iris, seq(0,2,0.01))

Zebedial/bis557 documentation built on Dec. 21, 2020, 2:16 a.m.