Zu den Inhalten springen

R code for chapter 7

Section 7.3

Create of a dummy day variable.
 

  • dummies <- c(1:20, rep(20, max(my.sir.data$time) - 20))
 
Then, we extend the data set.
 

  • sir.data.ext <- by(my.sir.data, my.sir.data$id, function(x) { temp <- x[rep(1, x$time), ] temp$day <- dummies[1:nrow(temp)] status <- c(rep("cens", nrow(temp) - 1), as.character(temp$to[1])) temp$status <- factor(ifelse(status == "cens", 0, status), levels = c(0, 1, 2)) temp }) sir.data.ext <- do.call(rbind, sir.data.ext) head(sir.data.ext, 4L)
 
Fit of a multinomial logit model using the nnet package
 

  • require(nnet) fit.multinom <- multinom(status ~ pneu + factor(day), sir.data.ext) coef(fit.multinom)[, "pneu"]