rms (version 6.8-0)

rms: rms Methods and Generic Functions


This is a series of special transformation functions (asis, pol, lsp, rcs, catg, scored, strat, matrx), fitting functions (e.g., lrm,cph, psm, or ols), and generic analysis functions (anova.rms, summary.rms, Predict, plot.Predict, ggplot.Predict, survplot, fastbw, validate, calibrate, specs.rms, which.influence, latexrms, nomogram, datadist, gendata) that help automate many analysis steps, e.g. fitting restricted interactions and multiple stratification variables, analysis of variance (with tests of linearity of each factor and pooled tests), plotting effects of variables in the model, estimating and graphing effects of variables that appear non-linearly in the model using e.g. inter-quartile-range hazard ratios, bootstrapping model fits, and constructing nomograms for obtaining predictions manually. Behind the scene is the Design function which stores extra attributes. Design() is not intended to be called by users. Design causes detailed design attributes and descriptions of the distribution of predictors to be stored in an attribute of the terms component called Design.

modelData is a replacement for model.frame.default that is much streamlined and prepares data for Design(). If a second formula is present, modelData ensures that missing data deletions are the same for both formulas, and produces a second model frame for formula2 as the data2 attribute of the main returned data frame.


modelData(data=environment(formula), formula, formula2=NULL,
          weights, subset, na.action=na.delete, dotexpand=TRUE,

Design(mf, formula=NULL, specials=NULL, allow.offset=TRUE, intercept=1) # not to be called by the user; called by fitting routines # dist <- datadist(x1,x2,sex,age,race,bp) # or dist <- datadist(my.data.frame) # Can omit call to datadist if not using summary.rms, Predict, # survplot.rms, or if all variable settings are given to them # options(datadist="dist") # f <- fitting.function(formula = y ~ rcs(x1,4) + rcs(x2,5) + x1%ia%x2 + # rcs(x1,4)%ia%rcs(x2,5) + # strat(sex)*age + strat(race)*bp) # See rms.trans for rcs, strat, etc. # %ia% is restricted interaction - not doubly nonlinear # for x1 by x2 this uses the simple product only, but pools x1*x2 # effect with nonlinear function for overall tests # specs(f) # anova(f) # summary(f) # fastbw(f) # pred <- predict(f, newdata=expand.grid(x1=1:10,x2=3,sex="male", # age=50,race="black")) # pred <- predict(f, newdata=gendata(f, x1=1:10, x2=3, sex="male")) # This leaves unspecified variables set to reference values from datadist # pred.combos <- gendata(f, nobs=10) # Use X-windows to edit predictor settings # predict(f, newdata=pred.combos) # plot(Predict(f, x1)) # or ggplot(...) # latex(f) # nomogram(f)


a data frame augmented with additional information about the predictors and model formulation



a data frame or calling environment


model formula


an optional second model formula (see for example ppo in blrm)


a weight variable or expression


a subsetting expression evaluated in the calling frame or data


NA handling function, ideally one such as na.delete that stores extra information about data omissions


a character vector specifying which function evaluations appearing in formula are "special" in the model.frame sense


set to FALSE to prevent . on right hand side of model formula from expanding into all variables in data; used for cph


the parent frame that called the fitting function


a model frame


set to TRUE if model fitter allows an offset term


1 if an ordinary intercept is present, 0 otherwise


Frank Harrell
Department of Biostatistics, Vanderbilt University

See Also

rms.trans, rmsMisc, cph, lrm, ols, specs.rms, anova.rms, summary.rms, Predict, gendata, fastbw, predictrms. validate, calibrate, which.influence, latex, latexrms, model.frame.default, datadist, describe, nomogram, vif, dataRep


Run this code
if (FALSE) {
dist <- datadist(data=2)     # can omit if not using summary, (gg)plot, survplot,
                             # or if specify all variable values to them. Can
                             # also  defer.  data=2: get distribution summaries
                             # for all variables in search position 2
                             # run datadist once, for all candidate variables
dist <- datadist(age,race,bp,sex,height)   # alternative
f <- cph(Surv(d.time, death) ~ rcs(age,4)*strat(race) +
anova(f,age,height)          # Joint test of 2 vars
summary(f, sex="female")     # Adjust sex to "female" when testing
                             # interacting factor bp
bplot(Predict(f, age, height))   # 3-D plot
ggplot(Predict(f, age=10:70, height=60))
latex(f)                     # LaTeX representation of fit

f <- lm(y ~ x)               # Can use with any fitting function that
                             # calls model.frame.default, e.g. lm, glm
specs.rms(f)                 # Use .rms since class(f)="lm"
anova(f)                     # Works since Varcov(f) (=Varcov.lm(f)) works
f <- ols(y ~ x1*x2)          # Saves enough information to do fastbw, anova
anova(f)                     # Will not do Predict since distributions
fastbw(f)                    # of predictors not saved
plot(f, x1=seq(100,300,by=.5), x2=.5) 
                             # all values defined - don't need datadist
dist <- datadist(x1,x2)      # Equivalent to datadist(f)
plot(f, x1, x2=.5)        # Now you can do plot, summary
plot(nomogram(f, interact=list(x2=c(.2,.7))))

Run the code above in your browser using DataLab