I have pollution data (quantitative) plotted against time (categorical), the hours of the day. Via ANOVA testing I've found significance at many of the hours, however, the relationship is definitely not linear. For example, it tends to rise in the morning, lower in the afternoon, and rise again in the evening, as you can see in the picture:
How can I transform this data set in order to build a linear model (in R) ?
I've chopped the data up into 6 groups of 4 hours to find average means of each group, but I'd like to be able to say, with a level of significance, that time X is the most polluted, or least polluted. How can I use R to make such a statement?
I've plotted the residuals of the model below -- since it's not normally distributed -- there is something that the linear model is not capturing.
I've put my data in a time series object - but I don't know what it means:
myts = ts(df$value, start=c(0), end=c(24), frequency=24) plot(stl(log(myts), s.window="periodic"))
I now have a model, but not a very good one. It has an adjusted r-squared of .18.
plot(value~(hour), data=df, ylim=c(0, 300)) my.lm = lm(value ~ sin(100*hour) + sin(50*hour) + cos(100*hour) + cos(50*hour) + day + month, data=df) lines(predict(my.lm), col=3, lwd=10)
Any thoughts on what I could do better?