| lrm {Design} | R Documentation |
Fit binary and proportional odds ordinal
logistic regression models using maximum likelihood estimation or
penalized maximum likelihood estimation. See cr.setup for how to
fit forward continuation ratio models with lrm.
lrm(formula, data, subset, na.action=na.delete, method="lrm.fit",
model=FALSE, x=FALSE, y=FALSE, linear.predictors=TRUE, se.fit=FALSE,
penalty=0, penalty.matrix, tol=1e-7,
strata.penalty=0, var.penalty=c('simple','sandwich'),
weights, normwt, ...)
formula |
a formula object. An offset term can be included. The offset causes
fitting of a model such as logit(Y=1) = Xβ + W, where W is the
offset variable having no estimated coefficient.
The response variable can be any data type; lrm converts it
in alphabetic or numeric order to an S factor variable and
recodes it 0,1,2,... internally.
|
data |
data frame to use. Default is the current frame. |
subset |
logical expression or vector of subscripts defining a subset of observations to analyze |
na.action |
function to handle NAs in the data. Default is na.delete, which
deletes any observation having response or predictor missing, while
preserving the attributes of the predictors and maintaining frequencies
of deletions due to each variable in the model.
This is usually specified using options(na.action="na.delete").
|
method |
name of fitting function. Only allowable choice at present is lrm.fit.
|
model |
causes the model frame to be returned in the fit object |
x |
causes the expanded design matrix (with missings excluded)
to be returned under the name x.
|
y |
causes the response variable (with missings excluded) to be returned
under the name y.
|
linear.predictors |
causes the predicted X beta (with missings excluded) to be returned
under the name linear.predictors. When the response variable has
> in case of non-convergence.
This is especially useful in simulation work.
Value
Author(s)
Frank Harrell See Also
Examples
n <- 400
set.seed(1)
age <- rnorm(n, 50, 12)
sex <- factor(sample(c('Female','Male'),n,TRUE))
dd <- datadist(age,sex)
options(datadist='dd')
# Population hazard function:
h <- .02*exp(.06*(age-50)+.8*(sex=='Female'))
d.time <- -log(runif(n))/h
cens <- 15*runif(n)
death <- ifelse(d.time <= cens,1,0)
d.time <- pmin(d.time, cens)
f <- psm(Surv(d.time,death) ~ sex*pol(age,2),
dist=if(.R.)'lognormal' else 'gaussian')
# Log-normal model is a bad fit for proportional hazards data
anova(f)
fastbw(f) # if deletes sex while keeping age*sex ignore the result
f <- update(f, x=TRUE,y=TRUE) # so can validate, compute certain resids
validate(f, dxy=TRUE, B=10) # ordinarily use B=150 or more
plot(f, age=NA, sex=NA) # needs datadist since no explicit age, hosp.
survplot(f, age=c(20,60)) # needs datadist since hospital not set here
# latex(f)
S <- Survival(f)
plot(f$linear.predictors, S(6, f$linear.predictors),
xlab=if(.R.)expression(X*hat(beta)) else 'X*Beta',
ylab=if(.R.)expression(S(6,X*hat(beta))) else 'S(6|X*Beta)')
# plots 6-month survival as a function of linear predictor (X*Beta hat)
times <- seq(0,24,by=.25)
plot(times, S(times,0), type='l') # plots survival curve at X*Beta hat=0
lam <- Hazard(f)
plot(times, lam(times,0), type='l') # similarly for hazard function
med <- Quantile(f) # new function defaults to computing median only
lp <- seq(-3, 5, by=.1)
plot(lp, med(lp=lp), ylab="Median Survival Time")
med(c(.25,.5), f$linear.predictors)
# prints matrix with 2 columns
# fit a model with no predictors
f <- psm(Surv(d.time,death) ~ 1, dist=if(.R.)"weibull" else "extreme")
f
pphsm(f) # print proportional hazards form
g <- survest(f)
plot(g$time, g$surv, xlab='Time', type='l',
ylab=if(.R.)expression(S(t)) else 'S(t)')
f <- psm(Surv(d.time,death) ~ age,
dist=if(.R.)"loglogistic" else "logistic", y=TRUE)
r <- resid(f, 'cens') # note abbreviation
survplot(survfit(r), conf='none')
# plot Kaplan-Meier estimate of
# survival function of standardized residuals
survplot(survfit(r ~ cut2(age, g=2)), conf='none')
# both strata should be n(0,1)
lines(r) # add theoretical survival function
#More simply:
survplot(r, age, g=2)
options(datadist=NULL)
[Package Design version 2.1-1 Index]
|