SHOW:
|
|
- or go back to the newest paste.
1 | 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 | |
2 | ||
3 | dat$t96 <- dat$t-1996 | |
4 | dat$type <- relevel(dat$type, "car") | |
5 | ||
6 | model <- lm(log(y) ~ t96*type, data=dat) | |
7 | summary(model) | |
8 | - | anova(model) |
8 | + | anova(model) |
9 | ||
10 | png("model_fit.png", width=600, height=600) | |
11 | 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)") | |
12 | axis(1, at=unique(dat$t96), labels=unique(dat$t96)+1996) | |
13 | axis(2, at=log(10^(3:6)), labels=10^(0:3)) | |
14 | co <- coef(model, col=1) | |
15 | abline(co[1],co[2]) | |
16 | for (i in 2:length(levels(dat$type))) | |
17 | abline(co[1]+co[i+1],co[2]+co[i+7], col=i) | |
18 | legend("topright", legend=levels(dat$type), fill=1:length(levels(dat$type))) | |
19 | dev.off() |