Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data.frame(y = c(332928,358323,422244,430035,3168,2397,3099,5508,23802,26346,28546,33933,2286,2370,5667,9468,6024,5370,6126,7971,5979,4893,5007,6381,17985,18771,24081,26532),t=rep(c(1996,2001,2006,2013),7),type=rep(c("car","mb","bus","train","other","bike","walk"),each=4)) -> dat
- dat$t96 <- dat$t-1996
- dat$type <- relevel(dat$type, "car")
- model <- lm(log(y) ~ t96*type, data=dat)
- summary(model)
- anova(model)
- png("model_fit.png", width=600, height=600)
- plot(log(dat$y) ~ dat$t96, col=dat$type, ylim=log(c(1000,1000000)), xlim=c(0,19), yaxt="n", xaxt="n", xlab="", ylab="Trips (1000s)")
- axis(1, at=unique(dat$t96), labels=unique(dat$t96)+1996)
- axis(2, at=log(10^(3:6)), labels=10^(0:3))
- co <- coef(model, col=1)
- abline(co[1],co[2])
- for (i in 2:length(levels(dat$type)))
- abline(co[1]+co[i+1],co[2]+co[i+7], col=i)
- legend("topright", legend=levels(dat$type), fill=1:length(levels(dat$type)))
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement