my_grad: Gradient computation

Description Usage Arguments Value Examples

View source: R/my_grad.R

Description

This function provides a vectorized version of the gradient computation

Usage

1
my_grad(par, X, Y, verbose = T)

Arguments

par

Parameters values.

X

Data predictors.

Y

Response variables.

verbose

If set TRUE the function produce messages during the computation.

Value

Returns the vector containing the gradient scores.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Having the parameters vector "par", the predictors matrix "X",
# and the outcome vector "Y",
# the gradient is calculated as follows:

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])

# gradient calculation

my_grad(par, X, Y)

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