Docsity

Understanding Survival Analysis with 'survival' Package: R Statistical Computing - Prof. M, Study notes of Statistics

Toggle sidebar
bg1
1
22S:166
Computing in Statistics
R packages
Lecture 7
September 13, 2006
Kate Cowles
374 SH, 335-0727
2
R packages
•packages contain all R functions and datasets
•contents of package become available in R
when package is loaded
•search() lists displays packages currently
loaded
> search()
[1] ".GlobalEnv" "package:methods" "package:stats"
[4] "package:graphics" "package:grDevices" "package:utils"
[7] "package:datasets" "Autoloads" "package:base"
•library() displays names of packages in-
stalled (but not necessarily loaded) at site
> library()
Packages in library ’/group/statsoft/Rlibs64’:
abind Combine multi-dimensional arrays
AnalyzeFMRI Functions for analysis of fMRI datasets stored
in the ANALYZE format.
boa Bayesian Output Analysis Program (BOA) for
MCMC
car Companion to Applied Regression
cat Analysis of categorical-variable datasets with
missing values
coda Output analysis and diagnostics for MCMC
3
dopt ** No title available (pre-2.0.0 install?) **
e1071 Misc Functions of the Department of Statistics
.
.
.
SuppDists Supplementary distributions
survrec Survival analysis for recurrent event data
tkrplot TK Rplot
tree Classification and regression trees
tripack Triangulation of irregularly spaced data
tseries Time series analysis and computational finance
xtable Export tables to LaTeX or HTML
Packages in library ’/usr/lib64/R/library’:
base The R Base Package
boot Bootstrap R (S-Plus) Functions (Canty)
class Functions for Classification
cluster Cluster Analysis Extended Rousseeuw et al.
datasets The R Datasets Package
foreign Read Data Stored by Minitab, S, SAS, SPSS,
.
.
.
splines Regression Spline Functions and Classes
stats The R Stats Package
stats4 Statistical Functions using S4 Classes
survival Survival analysis, including penalised
likelihood.
tcltk Tcl/Tk Interface
tools Tools for Package Development
utils The R Utils Package
Stata, Systat, dBase, ...
4
•library( <package name> ) loads pack-
age
> library(survival)
Loading required package: splines
> search()
[1] ".GlobalEnv" "package:survival" "package:splines"
[4] "package:methods" "package:stats" "package:graphics"
[7] "package:grDevices" "package:utils" "package:datasets"
[10] "Autoloads" "package:base"
•standard or base packages are considered part
of R; available automatically
pf3
pf4

Partial preview of the text

Download Understanding Survival Analysis with 'survival' Package: R Statistical Computing - Prof. M and more Study notes Statistics in PDF only on Docsity!

22S:

Computing in Statistics

R packages

Lecture 7

September 13, 2006

Kate Cowles

374 SH, 335-

[email protected]

R packages

• packages contain all R functions and datasets

• contents of package become available in R

when package is loaded

• search() lists displays packages currently

loaded

> search() [1] ".GlobalEnv" "package:methods" "package:stats" [4] "package:graphics" "package:grDevices" "package:utils" [7] "package:datasets" "Autoloads" "package:base"

• library() displays names of packages in-

stalled (but not necessarily loaded) at site

> library() Packages in library ’/group/statsoft/Rlibs64’:

abind Combine multi-dimensional arrays AnalyzeFMRI Functions for analysis of fMRI datasets stored in the ANALYZE format. boa Bayesian Output Analysis Program (BOA) for MCMC car Companion to Applied Regression cat Analysis of categorical-variable datasets with missing values coda Output analysis and diagnostics for MCMC

3

dopt ** No title available (pre-2.0.0 install?) ** e1071 Misc Functions of the Department of Statistics . . . SuppDists Supplementary distributions survrec Survival analysis for recurrent event data tkrplot TK Rplot tree Classification and regression trees tripack Triangulation of irregularly spaced data tseries Time series analysis and computational finance xtable Export tables to LaTeX or HTML

Packages in library ’/usr/lib64/R/library’:

base The R Base Package boot Bootstrap R (S-Plus) Functions (Canty) class Functions for Classification cluster Cluster Analysis Extended Rousseeuw et al. datasets The R Datasets Package foreign Read Data Stored by Minitab, S, SAS, SPSS, . . . splines Regression Spline Functions and Classes stats The R Stats Package stats4 Statistical Functions using S4 Classes survival Survival analysis, including penalised likelihood. tcltk Tcl/Tk Interface tools Tools for Package Development utils The R Utils Package Stata, Systat, dBase, ...

4

• library( ) loads pack-

age

> library(survival) Loading required package: splines > search() [1] ".GlobalEnv" "package:survival" "package:splines" [4] "package:methods" "package:stats" "package:graphics" [7] "package:grDevices" "package:utils" "package:datasets" [10] "Autoloads" "package:base"

• standard or base packages are considered part

of R; available automatically

Contributed R packages

• hundreds of contributed packages written by

authors all over the world

– e.g. Luke Tierney and Jun Yan from UI

stats dept!

• recommended packages come in binary dis-

tribution of R

• most available from Comprehensive R Archive

Network (CRAN)

www.cran.r-project.org

Using R packages

> help(package="survival")

Information on package ’survival’

Description:

Title: Survival analysis, including penalised likelihood. Maintainer: Thomas Lumley Priority: recommended Package: survival Version: 2. Depends: stats, utils, graphics, splines, R (>= 2.0.0) LazyData: Yes LazyLoad: Yes Author: S original by Terry Therneau, ported by Thomas Lumley Description: survival analysis: descriptive statistics, two-sample tests, parametric accelerated failure models, Cox model. Delayed entry (truncation) allowed for all models; interval censoring for parametric models. Case-cohort designs. License: GPL Packaged: Fri May 19 11:27:43 2006; tlumley Built: R 2.3.1; x86_64-redhat-linux-gnu; 2006-06-23 12:53:09; unix

Index:

Surv Package a survival variable clogit Conditional logistic regression cluster Identify clusters. cox.zph Test the proportional hazards assumption of a Cox regression

7

coxph Proportional Hazards Regression coxph.detail Details of a cox model fit coxph.object Proportional Hazards Regression Object coxph.rvar Robust variance for a Cox model frailty Frailty models by penalised likelihood is.ratetable Verify that an object is of class ratetable. lines.survfit Add lines to a survival plot plot.cox.zph Graphical test of proportional hazards (requires splines) plot.survfit Plot method for survfit. print.survfit Short summary of a survival curve pspline Penalised (smoothing) splines pyears Person Years residuals.coxph Calculate residuals for a coxph fit. residuals.survreg Compute Residuals for survreg Objects ridge ridge regression strata Identify strata variables. summary.survfit Print a Survival Curve survdiff Test Survival Curve Differences survexp Compute Expected Survival survexp.fit Compute expected survival survexp.usr Mortality tables for US and some states (requires date) survfit Compute a survival Curve for Censored Data survfit.object Survival Curve Object survobrien O’Brien’s test for association of a variable with survival survreg Regression for a parametric survival model survreg.object Parametric Survival Model Object survSplit Split data for creating time-dependent covariates. anova.survreg ANOVA tables for survreg objects untangle.specials Help process the ’specials’ argument of the terms function.

-------- date functions -------------- as.date Coerce Data to Dates date.ddmmmyy Format a Julian date date.mdy Convert from Julian Dates to Month, Day, and

8

Year date.mmddyy Format a Julian date date.mmddyyyy Format a Julian date date.object Date Objects mdy.date Convert to Julian Dates

(END)

Enter

q()

to exit the “help”

> exponanalysis <- survreg( Surv( survtime, cenflag) ~ trt,

  • data = leuk, dist="exponential") > summary(exponanalysis)

Call: survreg(formula = Surv(survtime, cenflag) ~ trt, data = leuk, dist = "exponential") Value Std. Error z p (Intercept) 2.92 0.199 14.67 9.70e- trt -1.53 0.398 -3.83 1.27e-

Scale fixed at 1

Exponential distribution Loglik(model)= -108.5 Loglik(intercept only)= -116. Chisq= 16.49 on 1 degrees of freedom, p= 4.9e-

Number of Newton-Raphson Iterations: 4 n= 42

> weibullanalysis <- survreg( Surv( survtime, cenflag) ~ trt,

  • data = leuk, dist="weibull")

> summary(weibullanalysis)

Call: survreg(formula = Surv(survtime, cenflag) ~ trt, data = leuk, dist = "weibull") Value Std. Error z p (Intercept) 2.882 0.146 19.73 1.29e- trt -1.267 0.311 -4.08 4.51e- Log(scale) -0.312 0.147 -2.12 3.43e-

Scale= 0.

Weibull distribution Loglik(model)= -106.6 Loglik(intercept only)= -116. Chisq= 19.65 on 1 degrees of freedom, p= 9.3e- Number of Newton-Raphson Iterations: 5 n= 42