HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Program Files/R/R-4.4.0/library/survival/tests/frailty.Rout.save
R Under development (unstable) (2019-05-15 r76504) -- "Unsuffered Consequences"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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)
> #
> # 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, tol=1e-7)
[1] TRUE
> all.equal(sfit1$var, sfit2$var)
[1] TRUE
> 
> proc.time()
   user  system elapsed 
  0.768   0.040   0.807