73 lines
2.5 KiB
Plaintext
73 lines
2.5 KiB
Plaintext
|
|
R version 3.0.0 (2013-04-03) -- "Masked Marvel"
|
|
Copyright (C) 2013 The R Foundation for Statistical Computing
|
|
Platform: i686-pc-linux-gnu (32-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.
|
|
|
|
> options(na.action=na.exclude) # preserve missings
|
|
> options(contrasts=c('contr.treatment', 'contr.poly')) #ensure constrast type
|
|
> library(survival)
|
|
Loading required package: splines
|
|
>
|
|
> #
|
|
> # Verify that scale can be fixed at a value
|
|
> # coefs will differ slightly due to different iteration paths
|
|
> tol <- .001
|
|
>
|
|
> # Intercept only models
|
|
> fit1 <- survreg(Surv(time,status) ~ 1, lung)
|
|
> fit2 <- survreg(Surv(time,status) ~ 1, lung, scale=fit1$scale)
|
|
> all.equal(fit1$coef, fit2$coef, tolerance= tol)
|
|
[1] TRUE
|
|
> all.equal(fit1$loglik, fit2$loglik, tolerance= tol)
|
|
[1] TRUE
|
|
>
|
|
> # The two robust variance matrices are not the same, since removing
|
|
> # an obs has a different effect on the two models. This just
|
|
> # checks for failure, not for correctness
|
|
> fit3 <- survreg(Surv(time,status) ~ 1, lung, robust=TRUE)
|
|
> fit4 <- survreg(Surv(time,status) ~ 1, lung, scale=fit1$scale, robust=TRUE)
|
|
>
|
|
>
|
|
> # multiple covariates
|
|
> fit1 <- survreg(Surv(time,status) ~ age + ph.karno, lung)
|
|
> fit2 <- survreg(Surv(time,status) ~ age + ph.karno, lung,
|
|
+ scale=fit1$scale)
|
|
> all.equal(fit1$coef, fit2$coef, tolerance=tol)
|
|
[1] TRUE
|
|
> all.equal(fit1$loglik[2], fit2$loglik[2], tolerance=tol)
|
|
[1] TRUE
|
|
>
|
|
> fit3 <- survreg(Surv(time,status) ~ age + ph.karno, lung, robust=TRUE)
|
|
> fit4 <- survreg(Surv(time,status) ~ age + ph.karno, lung,
|
|
+ scale=fit1$scale, robust=TRUE)
|
|
>
|
|
> # penalized models
|
|
> fit1 <- survreg(Surv(time, status) ~ pspline(age), lung)
|
|
> fit2 <- survreg(Surv(time, status) ~ pspline(age), lung, scale=fit1$scale)
|
|
> all.equal(fit1$coef, fit2$coef, tolerance=tol)
|
|
[1] TRUE
|
|
> all.equal(fit1$loglik[2], fit2$loglik[2], tolerance=tol)
|
|
[1] TRUE
|
|
>
|
|
> fit3 <- survreg(Surv(time,status) ~ pspline(age) + ph.karno, lung, robust=TRUE)
|
|
> fit4 <- survreg(Surv(time,status) ~ pspline(age) + ph.karno, lung,
|
|
+ scale=fit1$scale, robust=TRUE)
|
|
>
|
|
>
|
|
>
|
|
> proc.time()
|
|
user system elapsed
|
|
0.304 0.044 0.344
|