source("http://192.38.117.59/~linearpredictors/datafiles/readMelanoma.R") melanoma$timeint <- cut(melanoma$years, c(0, 2.5, 5, Inf), right = F, include.lower=T) ## all people contribute to first time interval melext <- melanoma melext$time <- factor(levels(melanoma$timeint)[1]) ## how many years each person contributes melext$pyrs <- sapply(melanoma$years, function(x)min(x, 2.5)) ## whether they had an event during this interval melext$case <- (melext$dc != 2)*(melext$years < 2.5) ## people that contribute to second interval are now duplicated ## and the same variables are created... melext2 <- subset(melanoma, years > 2.5) melext2$time <- factor(levels(melext2$timeint)[2]) melext2$pyrs <- sapply(melext2$years, function(x)min(x - 2.5, 2.5)) melext2$case <- (melext2$dc != 2)*(melext2$years < 5) ## attach the "new" observations melext <- rbind(melext, melext2) ## third interval, which is again the same melext3 <- subset(melanoma, years > 5) melext3$time <- factor(levels(melext3$timeint)[3]) melext3$pyrs <- melext3$years - 5 melext3$case <- (melext3$dc != 2) melext <- rbind(melext, melext3) pois <- glm(case ~ offset(log(pyrs)) + time + sex + ulc + thick + I(age/10) -1, family = poisson, data = melext) ## We now do the same analysis, using 4 as the only cutpoint of time ## first interval, all people m <- melanoma m$time <- factor("<= 4") m$pyrs <- sapply(m$years, function(x)min(x, 4)) ## whether they had an event during this interval m$case <- (m$dc != 2)*(m$years <= 4) ## second and last interval m4 <- subset(melanoma, years > 4) m4$time <- factor("> 4") m4$pyrs <- m4$years - 4 m4$case <- (m4$dc != 2) m <- rbind(m, m4) pois4 <- glm(case ~ offset(log(pyrs)) + time + sex + ulc + thick + I(age/10) -1, family = poisson, data = m)