# \donttest{
if (requireNamespace("relsurv", quietly = TRUE)) {
# data from package relsurv
data(rdata, package="relsurv")
# rate table from package relsurv
data(slopop, package="relsurv")
# get the death rate at event (or end of followup) from slopop for rdata
rdata$iage <- findInterval(rdata$age*365.24+rdata$time, attr(slopop, "cutpoints")[[1]])
rdata$iyear <- findInterval(rdata$year+rdata$time, attr(slopop, "cutpoints")[[2]])
therate <- rep(-1, dim(rdata)[1])
for( i in 1:dim(rdata)[1]){
therate[i] <- slopop[rdata$iage[i], rdata$iyear[i], rdata$sex[i]]
}
rdata$slorate <- therate
# change sex coding
rdata$sex01 <- rdata$sex -1
# fit a relative survival model with a non linear effetc of age
fit <- flexrsurv(Surv(time,cens)~sex01+NLL(age, Knots=60, Degree=3),
rate=slorate, data=rdata,
knots.Bh=1850, # one interior knot at 5 years
degree.Bh=3,
Spline = "b-spline",
initbyglm=TRUE,
initbands=seq(from=0, to=5400, by=200),
int_meth= "CAV_SIM",
step=50
)
summary(fit)
}
# }
Run the code above in your browser using DataLab