ols_gd_hw2b: OLS with Gradient Descent

Description Usage Arguments Value Examples

View source: R/ols_gd_hw2b.R

Description

This function uses the gradient descent algorithm (matrix form) to solve OLS using 10-fold cross validation (to calculate out-of-sample accuracy).

Usage

1
ols_gd_hw2b(form, d, b_0, learn_rate, max_iter, contrasts = NULL)

Arguments

form

linear model formula

d

data frame

b_0

parameters of model: column vector of initialized coefficients

learn_rate

the initialized learning rate (aka step size)

max_iter

the maximum number of iterations for this algorithm

contrasts

optional list of constants for factor variables aka contrast

Value

the estimated coefficients, as well as the penalty (loss)

Examples

1
2
3
4
5
set.seed(2020)
x <- -30:30
df <- data.frame(y = 6 + 7*x + rnorm(length(x)), x = x)
bis557::ols_gd_hw2b(form = y ~ ., d = df, b_0 = rep(1e-16, 2),
                    learn_rate = 0.18, max_iter = 1e5)

brian-d1018/bis557 documentation built on Dec. 17, 2020, 6:21 p.m.