Skip to content

Commit

Permalink
Slow down the examples for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
chjackson committed Apr 14, 2015
1 parent 2b67fab commit 2dbc201
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions man/flexsurvspline.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,23 @@ and \eqn{(x - a)_+ = max(0, x - a)}.
\examples{
## Best-fitting model to breast cancer data from Royston and Parmar (2002)
## One internal knot (2 df) and cumulative odds scale

spl <- flexsurvspline(Surv(recyrs, censrec) ~ group, data=bc, k=1, scale="odds")

## Fitted survival
plot(spl, ci=TRUE, lwd=3, lwd.ci=1, col.ci="gray")

plot(spl, lwd=3, ci=FALSE)

## Simple Weibull model fits much less well

splw <- flexsurvspline(Surv(recyrs, censrec) ~ group, data=bc, k=0, scale="hazard")
lines(splw, col="blue")
lines(splw, col="blue", ci=FALSE)

## Alternative way of fitting the Weibull

\dontrun{
splw2 <- flexsurvreg(Surv(recyrs, censrec) ~ group, data=bc, dist="weibull")
}

}
\keyword{models}
Expand Down
15 changes: 13 additions & 2 deletions man/msfit.flexsurvreg.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,28 @@ msfit.flexsurvreg(object, t, newdata=NULL, variance=TRUE,
## Compare clock-reset / semi-Markov multi-state models

## Simple exponential model (reduces to Markov)

bexp <- flexsurvreg(Surv(years, status) ~ trans,
data=bosms3, dist="exp")
tmat <- rbind(c(NA,1,2),c(NA,NA,3),c(NA,NA,NA))
mexp <- msfit.flexsurvreg(bexp, t=seq(0,12,by=0.1), trans=tmat, tvar="trans")
mexp <- msfit.flexsurvreg(bexp, t=seq(0,12,by=0.1),
trans=tmat, tvar="trans", variance=FALSE)

## Cox semi-parametric model within each transition

bcox <- coxph(Surv(years, status) ~ strata(trans), data=bosms3)
require(mstate)
mcox <- mstate::msfit(bcox, trans=tmat)

## Flexible parametric spline-based model

bspl <- flexsurvspline(Surv(years, status) ~ trans + gamma1(trans),
data=bosms3, k=3)
mspl <- msfit.flexsurvreg(bspl, t=seq(0,12,by=0.1), trans=tmat, tvar="trans")
mspl <- msfit.flexsurvreg(bspl, t=seq(0,12,by=0.1),
trans=tmat, tvar="trans", variance=FALSE)

## Compare fit: exponential model is OK but the spline is better

plot(mcox, lwd=1, xlim=c(0, 12), ylim=c(0,4))
cols <- c("black","red","green")
for (i in 1:3){
Expand All @@ -130,14 +136,19 @@ legend("topright", lwd=c(1,2,3), lty=c(1,2,1),
## Fit a list of models, one for each transition
## More computationally efficient, but only valid if parameters
## are different between transitions.

\dontrun{
bexp.list <- vector(3, mode="list")
for (i in 1:3) {
bexp.list[[i]] <- flexsurvreg(Surv(years, status) ~ 1, subset=(trans==i),
data=bosms3, dist="exp")
}

## The list of models can be passed to this and other functions,
## as if it were a single multi-state model.

msfit.flexsurvreg(bexp.list, t=seq(0,12,by=0.1), trans=tmat)
}

}
\references{
Expand Down

0 comments on commit 2dbc201

Please sign in to comment.