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/r_scale.R
options(na.action=na.exclude) # preserve missings
options(contrasts=c('contr.treatment', 'contr.poly')) #ensure constrast type
library(survival)

#
# 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)
all.equal(fit1$loglik, fit2$loglik, tolerance= tol)

# 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)
all.equal(fit1$loglik[2], fit2$loglik[2], tolerance=tol)

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)
all.equal(fit1$loglik[2], fit2$loglik[2], tolerance=tol)

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)