# NOT RUN {
# Construct a simple data frame of purchases for 3 persons
# The purchase units (in variable dose) correspond to
n <- c( 10, 17, 8 )
dop <- c( 1995.2+cumsum(sample(1:4/10,n[1],replace=TRUE)),
1997.3+cumsum(sample(1:4/10,n[2],replace=TRUE)),
1997.3+cumsum(sample(1:4/10,n[3],replace=TRUE)) )
amt <- sample( 1:3/15, sum(n), replace=TRUE )
dpt <- sample( 15:20/25, sum(n), replace=TRUE )
dfr <- data.frame( id = rep(1:3,n),
dop,
amt = amt,
dpt = dpt )
round( dfr, 3 )
# Construct a simple dataframe for follow-up periods for these 3 persons
fu <- data.frame( id = 1:3,
doe = c(1995,1997,1996)+1:3/4,
dox = c(2001,2003,2002)+1:3/5 )
round( fu, 3 )
( dpos <- gen.exp( dfr,
fu = fu,
breaks = seq(1990,2015,0.5),
lags = 2:3/5 ) )
( xpos <- gen.exp( dfr,
fu = fu,
use.dpt = FALSE,
breaks = seq(1990,2015,0.5),
lags = 2:3/5 ) )
# How many relevant columns
nvar <- ncol(xpos)-3
clrs <- rainbow(nvar)
# Show how the variables relate to the follow-up time
par( mfrow=c(3,1), mar=c(3,3,1,1), mgp=c(3,1,0)/1.6, bty="n" )
for( i in unique(xpos$id) )
matplot( xpos[xpos$id==i,"dof"],
xpos[xpos$id==i,-(1:3)],
xlim=range(xpos$dof), ylim=range(xpos[,-(1:3)]),
type="l", lwd=2, lty=1, col=clrs,
ylab="", xlab="Date of follow-up" )
ytxt <- par("usr")[3:4]
ytxt <- ytxt[1] + (nvar:1)*diff(ytxt)/(nvar+2)
xtxt <- rep( sum(par("usr")[1:2]*c(0.98,0.02)), nvar )
text( xtxt, ytxt, colnames(xpos)[-(1:3)], font=2,
col=clrs, cex=1.5, adj=0 )
# }
Run the code above in your browser using DataLab