linear_gd_optim: linear_gd_optim

Description Usage Arguments Value Examples

View source: R/linear_gd_optim.R

Description

This function provides a personalized efficient way for optimizing functions. It is used to fit linear models, applying the gradient descent method.

Usage

1
2
3
4
5
6
7
8
9
linear_gd_optim(
  par,
  X,
  Y,
  tolerance = 1e-06,
  maxit = 10000,
  stepsize = 0.001,
  verbose = T
)

Arguments

par

Initial values.

X

Data matrix predictors (first column has to contain values 1 to consider the intercept).

Y

Response vector.

tolerance

Value for the stopping criterion. The default value is set to 1e-6.

maxit

Maximum iterations allowed. The default value is set to 10000.

stepsize

Length of the stepsize parameter. The default value is set to 1e-3.

verbose

If set TRUE the function produce messages during the computation.

Value

Returns the vector containing the estimated parameters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(myOpt)
## basic example code

set.seed(8675309)

# data simulation for example purposes

n = 1000

x1 = rnorm(n)
x2 = rnorm(n)
X <- cbind(rep(1,n),x1,x2)

Y = 1 + 0.5*x1 + 0.2*x2 + rnorm(n)

# random initial values for the parameters of the linear model

par <- rnorm(dim(X)[2])


est_par <- linear_gd_optim(par, X, Y)

lucaaiello/myOpt documentation built on Dec. 21, 2021, 11:51 a.m.