my_grad_descent: Preform Linear Model with Gradient Descent Method

Description Usage Arguments Examples

View source: R/my-grad-descent.r

Description

This is a simple algorithm to solve a linear regression model.

Usage

1
2
3
4
5
6
7
8
9
my_grad_descent(
  form,
  data,
  contrasts = NULL,
  lambda = 1e-04,
  tolerence = 1e-15,
  beta_ini = 1,
  max_itr = 1e+06
)

Arguments

form

a formula object, e.g. y ~ x1 + x2

data

a data frame

contrasts

a list, whose entries are values (numeric matrices, functions or character strings naming functions) to be used as replacement values for the contrasts replacement function and whose names are the names of columns of data containing factors. If NULL, then contrasts are ommitted.

lambda

a numeric number indicating the learning rate for gradient descent algorithm

tolerence

a numeric number indicating the precision of the algorithm

beta_ini

a numeric number indicating the initial value for beta coeffficient

max_itr

an integer indicating the maximum number iterations

Examples

1
2
3
data(iris)
fit <- my_grad_descent(Sepal.Length ~ ., data = iris)
fit$coefficients

tqchen07/bis557 documentation built on Dec. 21, 2020, 3:06 a.m.