best_lambda: find the best lambda in ridge regression function

View source: R/best_lambda.R

best_lambdaR Documentation

find the best lambda in ridge regression function

Description

This is a function taking a formula, a dataframe and an optional list of contrast for factor variables, and taking into account colinear (or nearly colinear) regression variables and returning coefficients.

Usage

best_lambda(
  formula,
  df,
  contrasts = NULL,
  lambdas = seq(-2, 2, by = 0.01),
  nfold = 10
)

Arguments

formula

an object of class "formula": describing the model to be fitted.

df

a dataframe that containing all the variables in the model.

contrasts

an optional list of contrasts for factor variables.

lambdas

a sequence of lambdas to be selected from, default is seq(-1, 1, by = 0.01)

nfold

number of folds for the cross validation

Examples

data(iris)
form <- Sepal.Length ~ Sepal.Width
best_lambda(formula = form,df = iris)


carolineying/bis557 documentation built on April 17, 2023, 4 a.m.