swertie
2012-Jan-31 12:34 UTC
[R] testing for temperature differences between years and sites?
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, dataMeanTemp) 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? Thank you very much -- View this message in context: http://r.789695.n4.nabble.com/testing-for-temperature-differences-between-years-and-sites-tp4344311p4344311.html Sent from the R help mailing list archive at Nabble.com.
Jim Lemon
2012-Feb-01 08:12 UTC
[R] testing for temperature differences between years and sites?
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
swertie
2012-Feb-01 09:02 UTC
[R] testing for temperature differences between years and sites?
Thank you very much! This is the kind of plot I tried to do. For the statistical models, I am a bit confused between which factors to put as fixed or random effects. I will have a look at time series models as you suggested. swertie -- View this message in context: http://r.789695.n4.nabble.com/testing-for-temperature-differences-between-years-and-sites-tp4344311p4347278.html Sent from the R help mailing list archive at Nabble.com.