########################### # MAC fraility example -- R code to arrange the dataset # Weibull survival model -- Example 2.15 ########################### # Our dataset is unbalanced, as the number of subjects differs from site to site: # nsub=c(4,2,1,10,8,12,6,6,13,4,3), i.e. there are 4 subjects in site 1, 2 in site 2, etc. # # We use "offset" to hold the position in the dataset at which each person's data starts. # Here is a snippet of R code to calculate offset from nsub: nsub<-c(4,2,1,10,8,12,6,6,13,4,3) temp<-1 offset<-rep(0,(length(nsub)+1)) for(i in 1:length(nsub)){offset[i]<-temp; temp<-temp+nsub[i]} offset[ (length(nsub)+1)] <-sum(nsub)+1