Title: | 'Rcpp' Integration for Numerical Computing Libraries |
---|---|
Description: | A collection of open source libraries for numerical computing (numerical integration, optimization, etc.) and their integration with 'Rcpp'. |
Authors: | Yixuan Qiu [aut, cre], Ralf Stubner [ctb] (Integration on infinite intervals), Sreekumar Balan [aut] (Numerical integration library), Matt Beall [aut] (Numerical integration library), Mark Sauder [aut] (Numerical integration library), Naoaki Okazaki [aut] (The libLBFGS library), Thomas Hahn [aut] (The Cuba library) |
Maintainer: | Yixuan Qiu <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.6-0 |
Built: | 2024-11-06 04:57:57 UTC |
Source: | https://github.com/yixuan/rcppnumerical |
fastLR()
uses the L-BFGS algorithm to efficiently fit logistic
regression. It is in fact an application of the C++ function
optim_lbfgs()
provided by RcppNumerical to perform L-BFGS
optimization.
fastLR( x, y, start = rep(0, ncol(x)), eps_f = 1e-08, eps_g = 1e-05, maxit = 300 )
fastLR( x, y, start = rep(0, ncol(x)), eps_f = 1e-08, eps_g = 1e-05, maxit = 300 )
x |
The model matrix. |
y |
The response vector. |
start |
The initial guess of the coefficient vector. |
eps_f |
Iteration stops if |
eps_g |
Iteration stops if
|
maxit |
Maximum number of iterations. |
fastLR()
returns a list with the following components:
coefficients |
Coefficient vector |
fitted.values |
The fitted probability values |
linear.predictors |
The fitted values of the linear part, i.e.,
|
loglikelihood |
The maximized log likelihood |
converged |
Whether the optimization algorithm has converged |
Yixuan Qiu https://statr.me
glm.fit()
set.seed(123) n = 1000 p = 100 x = matrix(rnorm(n * p), n) beta = runif(p) xb = c(x %*% beta) p = 1 / (1 + exp(-xb)) y = rbinom(n, 1, p) system.time(res1 <- glm.fit(x, y, family = binomial())) system.time(res2 <- fastLR(x, y)) max(abs(res1$coefficients - res2$coefficients))
set.seed(123) n = 1000 p = 100 x = matrix(rnorm(n * p), n) beta = runif(p) xb = c(x %*% beta) p = 1 / (1 + exp(-xb)) y = rbinom(n, 1, p) system.time(res1 <- glm.fit(x, y, family = binomial())) system.time(res2 <- fastLR(x, y)) max(abs(res1$coefficients - res2$coefficients))