linear_gd_optim2: Linear Gradient Descend (2)

Description Usage Arguments Value Examples

View source: R/linear_gd_optim2.R

Description

This function is the slower version of linear_gd_optim given that it makes use of the grad function contained in the package "numDeriv".

Usage

1
linear_gd_optim2(b_pre, X, y, tol = 0.001, maxit = 1000, stepsize = 0.001)

Arguments

b_pre

vector of initial parameters

X

Covariates Matrix: each column contains observations for each covariate.

y

Response variable observations

tol

Tolerance level for the optimization process, the default is 0.001.

maxit

Maximum iterations number. Default is 1000.

stepsize

The value for the stepsize in the equation of the gradient descend. Default is 0.001.

Value

A list containing the fitted values for the beta vector and the number of iterations performed.

Examples

1
2
3
4
5
6
7
8
set.seed(8675309)
n = 1000
x1 = rnorm(n)
x2 = rnorm(n)
y = 1 + .5*x1 + .2*x2 + rnorm(n)
X=cbind(x1,x2)
b_pre=c(0,0,0)
linear_gd_optim(b_pre,X,y)

FedericoCortese/R4DScm documentation built on July 12, 2021, 5:30 a.m.