lrm.fit | R Documentation |
Logistic Model Fitter
lrm.fit(
x,
y,
offset = 0,
initial,
opt_method = c("NR", "nlminb", "LM", "glm.fit", "nlm", "BFGS", "L-BFGS-B", "CG",
"Nelder-Mead"),
maxit = 50,
reltol = 1e-10,
abstol = if (opt_method %in% c("NR", "LM")) 1e+10 else 0,
gradtol = if (opt_method %in% c("NR", "LM")) 0.001 else 1e-05,
factr = 1e+07,
eps = 5e-04,
minstepsize = 0.01,
trace = 0,
tol = .Machine$double.eps,
penalty.matrix = NULL,
weights = NULL,
normwt = FALSE,
transx = FALSE,
compstats = TRUE,
inclpen = TRUE,
initglm = FALSE,
y.precision = 7
)
x |
design matrix with no column for an intercept. If a vector is transformed to a one-column matrix. |
y |
response vector, numeric, categorical, or character. For ordinal regression, the order of categories comes from |
offset |
optional numeric vector containing an offset on the logit scale |
initial |
vector of initial parameter estimates, beginning with the intercepts |
opt_method |
optimization method, with possible values
|
maxit |
maximum number of iterations allowed, which means different things for different |
reltol |
used by |
abstol |
used by |
gradtol |
used by |
factr |
see |
eps |
difference in -2 log likelihood for declaring convergence with |
minstepsize |
used with |
trace |
set to a positive integer to trace the iterative process. Some optimization methods distinguish |
tol |
QR singularity criterion for |
penalty.matrix |
a self-contained ready-to-use penalty matrix - see |
weights |
a vector (same length as |
normwt |
set to |
transx |
set to |
compstats |
set to |
inclpen |
set to |
initglm |
set to |
y.precision |
when |
Fits a binary or propoortional odds ordinal logistic model for a given design matrix and response vector with no missing values in either. Ordinary or quadratic penalized maximum likelihood estimation is used.
lrm.fit
implements a large number of optimization algorithms with the default being Newton-Raphson with step-halving. For binary logistic regression without penalization iteratively reweighted least squares method in stats::glm.fit()
is an option. The -2 log likeilhood, gradient, and Hessian (negative information) matrix are computed in Fortran for speed. Optionally, the x
matrix is mean-centered and QR-factored to help in optimization when there are strong collinearities. Parameter estimates and the covariance matrix are adjusted to the original x
scale after fitting. More detail and comparisons of the various optimization methods may be found here. For ordinal regression with a large number of intercepts (distinct y
values less one) you may want to use ‘optim_method=’BFGS', which does away with the need to compute the Hessian. This will be helpful if statistical tests and confidence intervals are not being computed, or when only likelihood ratio tests are done.
When using Newton-Raphson or Levenberg-Marquardt optimization, sparse Hessian/information/variance-covariance matrices are used throughout. For nlminb
the Hessian has to be expanded into full non-sparse form, so nlminb
will not be very efficient for a large number of intercepts.
When there is complete separation (Hauck-Donner condition), i.e., the MLE of a coefficient is \pm\infty
, and y
is binary and there is no penalty, glm.fit
may not converge because it does not have a convergence parameter for the deviance. Setting trace=1
will reveal that the -2LL is approaching zero but doesn't get there, relatively speaking. In such cases the default of NR
with eps=5e-4
or using nlminb
with its default of abstol=0.001
works well.
a list with the following elements:
call
: the R call to lrm.fit
freq
: vector of y
frequencies
ymedian
: median of original y
values if y
is numeric, otherwise the median of the integer-recorded version of y
yunique
: vector of distinct original y
values, subject to rounding
sumty
: vector of weighted y
frequencies
stats
: vector with a large number of indexes and model parameters (NULL
if compstats=FALSE
):
Obs
: number of observations
Max Deriv
: maximum absolute gradiant
Model L.R.
: overall model LR chi-square statistic
d.f.
: degrees of freedom (number of non-intercepts)
P
: p-value for the overall Model L.R.
and d.f.
C
: concordance probability between predicted probability and y
Dxy
: Somer's Dxy rank correlation between predicted probability and y
, = 2(C - 0.5)
Gamma
:
Tau-a
:
R2
: documented here; the first element, with the plain 'R2'
name is Nagelkerke's R^2
Brier
: Brier score. For ordinal models this is computed with respect the the median intercept.
g
: g-index (Gini's mean difference of linear predictors)
gr
: g-index on the odds ratio scale
gp
: g-index on the probability scale
fail
: TRUE
if any matrix inversion or failure to converge occurred, FALSE
otherwise
coefficients
:
info.matrix
: a list of 3 elements a
, b
, ab
with a
being a $k x 2$ matrix for $k$ intercepts, b
being $p x p$ for $p$ predictors, and ab
being $k x p$. See infoMxop()
for easy ways of operating on these 3 elements.
u
: gradient vector
iter
: number of iterations required. For some optimization methods this is a vector.
deviance
: vector of deviances: intercepts-only, intercepts + offset (if offset
is present), final model (if x
is used)
non.slopes
: number of intercepts in the model
linear.predictors
: vector of linear predictors at the median intercept
penalty.matrix
: penalty matrix or NULL
weights
: weights
or NULL
xbar
: vector of column means of x
, or NULL
if transx=FALSE
xtrans
: input value of transx
R
: R matrix from QR to be used to rotate parameters back to original scale in the future
Ri
: inverse of R
opt_method
: input value
Frank Harrell fh@fharrell.com
lrm()
, stats::glm()
, cr.setup()
, gIndex()
, stats::optim()
, stats::nlminb()
, stats::nlm()
,stats::glm.fit()
, recode2integer()
, Hmisc::qrxcenter()
, infoMxop()
## Not run:
# Fit an additive logistic model containing numeric predictors age,
# blood.pressure, and sex, assumed to be already properly coded and
# transformed
fit <- lrm.fit(cbind(age,blood.pressure,sex=='male'), death)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.