Description Usage Arguments Value Examples
View source: R/linear_gd_optim.R
This function provides a personalized efficient way for optimizing functions. It is used to fit linear models, applying the gradient descent method.
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
)
|
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. |
Returns the vector containing the estimated parameters.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.