R Under development (unstable) (2023-08-12 r84939 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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.87 0.09 0.96