[R] testing for temperature differences between years and sites?
Jim Lemon
jim at bitwrit.com.au
Wed Feb 1 09:12:24 CET 2012
On 01/31/2012 11:34 PM, swertie wrote:
> Hello!
>
> I have a dataset with monthly temperatures for 4 different years and I would
> like to test if they are significantly different between the years. As I
> collected the data for different sites I wondered if there were some
> possibility to perform the calculation at once or if I have to repeat it for
> each site.
>
> I tried like this:
>
> Model_Temp<- lmer(Temp ~Year + (1|Site)+(1|Month),na.action=na.omit, data=
> MeanTemp)
>
> But I am not sure at all if it is correct to put the sites as random factors
> or if I have to do the calculation for each site separately. I am not
> interested in correlation between sites, but only between years for each
> different site.
>
> Alternatively, can you indicate me some way to plot this?
>
Hi swertie,
Let's say you have monthly temperature readings for four sites:
mon_temp<-data.frame(site=rep(LETTERS[1:4],48),
year=rep(2008:2011,each=48),month=rep(month.abb,each=4),
temp=20+rnorm(192)+
10*sin(rep(rep(seq(1.5*pi,3.5*pi,length.out=12),each=4,4))))
Having gotten some data, you can then display a line plot of the
temperatures for the sites:
plot(mon_temp$temp[mon_temp$site=="A"],type="b",xaxt="n",ylim=c(0,40),
main="Temperature by site",xlab="Year",ylab="Temperature")
axis(1,at=seq(6,42,by=12),labels=2008:2011)
lines(mon_temp$temp[mon_temp$site=="B"],type="b",pch=2,col=2)
lines(mon_temp$temp[mon_temp$site=="C"],type="b",pch=3,col=3)
lines(mon_temp$temp[mon_temp$site=="D"],type="b",pch=4,col=4)
legend(24,40,LETTERS[1:4],pch=1:4,col=1:4)
Unless you have some reason to think that the sites vary in some way
that would affect temperature, for instance altitude, using site as a
factor in an overall model might not get you much. Also you may want to
test yearly averages, as there is a strong seasonal component. Thus you
might want to think about a time series model.
Jim
More information about the R-help
mailing list