File: frailty.Rout.save

package info (click to toggle)
survival 2.37-7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,684 kB
  • ctags: 364
  • sloc: asm: 6,453; ansic: 4,857; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,552 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

R version 2.11.1 (2010-05-31)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(survival)
Loading required package: splines
> #
> # The constuction of a survival curve with sparse frailties
> #
> # In this case the coefficient vector is kept in two parts, the
> #  fixed coefs and the (often very large) random effects coefficients
> # The survfit function treats the second set of coefficients as fixed
> #  values, to avoid an unmanagable variance matrix, and behaves like
> #  the second fit below.
> 
> fit1 <- coxph(Surv(time, status) ~ age + frailty(inst), lung)
> sfit1 <- survfit(fit1)
> 
> # A parallel model with the frailties treated as fixed offsets
> offvar <- fit1$frail[as.numeric(factor(lung$inst))]
> fit2 <- coxph(Surv(time, status) ~ age + offset(offvar),lung)
> fit2$var <- fit1$var  #force variances to match
> 
> all.equal(fit1$coef, fit2$coef)
[1] TRUE
> sfit2 <- survfit(fit2, newdata=list(age=fit1$means, offvar=0))
> all.equal(sfit1$surv, sfit2$surv)
[1] TRUE
> all.equal(sfit1$var, sfit2$var)
[1] TRUE
>