R (język programowania)/Analiza przeżyć

Analiza przeżyć ( ang. Survival analysis)[1]


Pakiety

edytuj
  • survival = podstawowy pakiet
  • KMsurv = dodatkowe materiały z książki Klein and Moeschberger  : "Survival Analysis, Techniques for Censored and Truncated Data", Springer (1997)
  • funkcja ggsurv [2]
  • OIsurv = dodatkowe materiału ze strony www.openintro.org
  • survMisc [3][4]

survival

edytuj

Ładujemy biblkiotekę [5]

 library(survival) #

Sprawdzamy :


library(help=survival) # see the version number, list of available functions and data sets.

Przykładowy wynik :

  Informacja dotycząca pakietu ‘survival’

Opis:

Title:              Survival Analysis
Maintainer:         Terry Therneau <therneau.terry@mayo.edu>
Priority:           recommended
Package:            survival
Version:            2.37-4
Date:               2013-02-26
Depends:            stats, utils, graphics, splines, R (>= 2.13.0)
LazyData:           Yes
LazyLoad:           Yes
ByteCompile:        Yes
Authors@R:          c(person(c("Terry", "M"), "Therneau",
                    email="therneau.terry@mayo.edu", role=c("aut",
                    "cre")), person("Lumley", "Thomas", role=c("ctb",
                    "trl"), comment="original S->R port and maintainer
                    until 2009"))
Author:             Terry Therneau
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:            LGPL (>= 2)
URL:                http://r-forge.r-project.org
Packaged:           2013-02-26 17:19:25 UTC; therneau
NeedsCompilation:   yes
Repository:         CRAN
Date/Publication:   2013-02-26 19:03:03
Built:              R 3.0.0; x86_64-pc-linux-gnu; 2013-04-29 18:21:29
                    UTC; unix

Indeks:

Surv                    Create a Survival Object
aareg                   Aalen's additive regression model for censored
                        data
aml                     Acute Myelogenous Leukemia survival data
anova.coxph             Analysis of Deviance for a Cox model.
attrassign              Create new-style "assign" attribute
basehaz                 Compute the baseline survival curve for a Cox
                        model
bladder                 Bladder Cancer Recurrences
cch                     Fits proportional hazards regression model to
                        case-cohort data
cgd                     Chronic Granulotomous Disease data
clogit                  Conditional logistic regression
cluster                 Identify clusters.
colon                   Chemotherapy for Stage B/C colon cancer
cox.zph                 Test the Proportional Hazards Assumption of a
                        Cox Regression
coxph                   Fit Proportional Hazards Regression Model
coxph.control           Ancillary arguments for controling coxph fits
coxph.detail            Details of a Cox Model Fit
coxph.object            Proportional Hazards Regression Object
dsurvreg                Distributions available in survreg.
frailty                 Random effects terms
heart                   Stanford Heart Transplant data
is.ratetable            Verify that an object is of class ratetable.
kidney                  Kidney catheter data
lines.survfit           Add Lines or Points to a Survival Plot
logan                   Data from the 1972-78 GSS data used by Logan
lung                    NCCTG Lung Cancer Data
mgus                    Monoclonal gammapothy data
model.frame.coxph       Model.frame method for coxph objects
model.matrix.coxph      Model.matrix method for coxph models
nwtco                   Data from the National Wilm's Tumor Study
ovarian                 Ovarian Cancer Survival Data
pbc                     Mayo Clinic Primary Biliary Cirrhosis Data
pbcseq                  Mayo Clinic Primary Biliary Cirrhosis,
                        sequential data
plot.aareg              Plot an aareg object.
plot.cox.zph            Graphical Test of Proportional Hazards
plot.survfit            Plot method for 'survfit' objects
predict.coxph           Predictions for a Cox model
predict.survreg         Predicted Values for a 'survreg' Object
print.aareg             Print an aareg object
print.summary.coxph     Print method for summary.coxph objects
print.summary.survexp   Print Survexp Summary
print.summary.survfit   Print Survfit Summary
print.survfit           Print a Short Summary of a Survival Curve
pspline                 Smoothing splines using a pspline basis
pyears                  Person Years
quantile.survfit        Quantiles from a survfit object
ratetable               Ratetable reference in formula
ratetableDate           Convert date objects to ratetable form
rats                    Rat treatment data from Mantel et al
rats2                   Rat data from Gail et al.
residuals.coxph         Calculate Residuals for a 'coxph' Fit
residuals.survreg       Compute Residuals for 'survreg' Objects
ridge                   Ridge regression
stanford2               More Stanford Heart Transplant data
strata                  Identify Stratification Variables
summary.aareg           Summarize an aareg fit
summary.coxph           Summary method for Cox models
summary.survexp         Summary function for a survexp object
summary.survfit         Summary of a Survival Curve
survConcordance         Compute a concordance measure.
survSplit               Split a survival data set at specified times
survdiff                Test Survival Curve Differences
survexp                 Compute Expected Survival
survexp.fit             Compute Expected Survival
survexp.us              Census Data Sets for the Expected Survival and
                        Person Years Functions
survfit                 Create survival curves
survfit.coxph           Compute a Survival Curve from a Cox model
survfit.formula         Compute a Survival Curve for Censored Data
survfit.object          Survival Curve Object
survfitcoxph.fit        A direct interface to the 'computational
                        engine' of survfit.coxph
survobrien              O'Brien's Test for Association of a Single
                        Variable with Survival
survreg                 Regression for a Parametric Survival Model
survreg.control         Package options for survreg and coxph
survreg.distributions   Parametric Survival Distributions
survreg.object          Parametric Survival Model Object
survregDtest            Verify a survreg distribution
tcut                    Factors for person-year calculations
tobin                   Tobin's Tobit data
tt                      Mark time tranform terms
untangle.specials       Help Process the 'specials' Argument of the
                        'terms' Function.
uspop2                  Projected US Population
veteran                 Veterans' Administration Lung Cancer study

Dalsza informacja jest dostępna w następujących ilustracjach w katalogu
‘/usr/lib/R/library/survival/doc’:

timedep: Using Time Dependent Covariates (source, pdf)



Pamiętaj o wyjściu za pomocą

:q


Funkcje

edytuj

Najważniejsze funkcja :

  • Surv ( Survival object = the data has to be in the proper format )
  • survfit ( Kaplan-Meier estimates )[6]
  • survdiff (The log-rank test )
  • coxph (The Cox proportional hazards model )
  • survreg (The Accelerated failure time model )


Surv {survival}
edytuj
Surv (czas, zdarzenie)


gdzie : [7]

  • czas (ang. follow-up time) to zmienna reprezentująca długość czasu obserwacji obiektów
  • wydarzenie( ang. event status indicator) to zmienna logiczna ( zero-jedynkowa, binarna, nie/tak, 0/1) określająca, czy dla danego obiektu ze zbioru danych wystąpiło w okresie obserwacji badane zdarzenie;

Jak przygotować dane ? [8]

Ładujemy dane aml

data(aml)

w nowszych wersjach pakietu otrzymujemy błąd :


Komunikat ostrzegawczy:
In data(aml) : zbiór danych ‘aml’ nie został znaleziony

pomimo że dane są w pakiecie. Jest spowodowane użyciem lazyData[9]. Sprawdzamy :


exists('aml')

przykładowy wynik :

[1] TRUE

wczytujemy i oglądamy dane :


aml 

wynik :


  time status             x
1     9      1    Maintained
2    13      1    Maintained
3    13      0    Maintained
4    18      1    Maintained
5    23      1    Maintained
6    28      0    Maintained
7    31      1    Maintained
8    34      1    Maintained
9    45      0    Maintained
10   48      1    Maintained
11  161      0    Maintained
12    5      1 Nonmaintained
13    5      1 Nonmaintained
14    8      1 Nonmaintained
15    8      1 Nonmaintained
16   12      1 Nonmaintained
17   16      0 Nonmaintained
18   23      1 Nonmaintained
19   27      1 Nonmaintained
20   30      1 Nonmaintained
21   33      1 Nonmaintained
22   43      1 Nonmaintained
23   45      1 Nonmaintained


Wykresy

edytuj

Wykres Kaplan-Meier : [10]

 fit <- survfit(Surv(time, status) ~ x, data = aml) 
 plot(fit, lty = 2:3) 
 legend(100, .8, c("Maintained", "Nonmaintained"), lty = 2:3)


 
Wykres Kaplana-Meiera
 library(survival)
time  = c(1, 12, 22, 29, 31, 36, 38, 50, 60, 61, 70, 88, 99, 110, 140)
event = c(0,  1,  0,  1,  1,  0,  0,  0,  0,  1,  1,  0,  0,   0,   0)
fit = survfit( Surv(time, event)~1 )
plot(fit, main="Estymator Kaplane-Meiera", xlab="t = Czas ( dni)", ylab="S(t) = Prawdopodobieństwo")

Przykłady:

  • r-studio [11]
  • DethWench’s SAS Blog[12]

Źródła

edytuj
  1. Analiza przeżycia w wikipedii
  2. Creating good looking survival curves – the 'ggsurv' function by Edwin Thoen
  3. survMisc
  4. Plotting survival curves in R with ggplot2
  5. Use Software R to do Survival Analysis and Simulation by Mai Zhou
  6. Compute a Survival Curve for Censored Data
  7. Survival Analysis - analiza przeżyć. Statystyka Medyczna : Branicka, Pękalski
  8. How to Make Survival Analysis Variables in R by Monika Wahi
  9. Loading data from a program
  10. survfit.formula {survival}
  11. Drawing survival curves in R
  12. How to Plot a Survival Curve (or Two) in R by Monika Wahi