About the dataframes: ‘dirty’ has temp. from all 20 sites on all days overlapping and not. Df ‘over’ contains only temperature from sites overlapping in dates. It has 24617 obs, 10 var)

library(xts)
library(lubridate)
library(plyr)
library(lme4)
library(nlme)
library(ggplot2)

dirty<- read.csv("/Users/Ang/Documents/Tesis New/TempHum/dirty.csv")
big_means<-round(with(dirty, tapply(Temp, Type, mean)),digits=1) #with all sites, all days
big_means
##    I    L    S 
## 23.0 23.4 23.3

Preliminary plots with all 20 sites, all temperatures, overlapping dates and not.

Now we focus only on the 20 days that all ibuttons were working simultaneously. For next steps we exclude data from sites without overlapping dates (6). The following code (not executed here) is just to keep track of how I calculated daily means.

#Create a "timestamp", a column combining date and time columns in one
format<- within(over,{ timestamp=format(as.POSIXct(paste(Date, Time)), "%d/%m/%Y %H:%M:%S") })
format[,"DoY"] <- format.Date(format[,"Date"], format="%j") over[,"DoY"] <- format.Date(over[,"Date"], format="%j")

Calculate DAILY means, max and mins of each site.

MeanTempAll <- aggregate(format$Temp, by=list(Day=format$DoY,Site=format$Site), mean) #:)
MaxTempAll <- aggregate(format$Temp, by=list(Day=format$DoY,Site=format$Site), max)
MinTempAll <- aggregate(format$Temp, by=list(Day=format$DoY,Site=format$Site), min)

I summarized all those lists that in a separate file, and reload them into R, under “daily”:

Mean daily temperatures

daily<-read.csv ("/Users/Ang/Documents/Tesis New/TempHum/Mean_temp_per_day_from_R.csv")
daily2<-na.omit(daily)
qplot(Site, Mean, data=daily, colour=Size, geom="point") + geom_point(size = 5) + theme_bw() +theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + ggtitle("Mean daily temperatures") + ylab("Mean daily Temp °C") +xlab("Sites")+ scale_x_discrete(limits=c("BUTT","I1","I2","I5","NIC","PIA","PIB", "PIC", "L1","L3","L4","L6","PLA","PSP","S1","S2","S4","L2","PSA","S6"))

t <- lme(Mean ~ Size*Elevation, random= ~ 1 | Site, data = daily2)
plot(fitted(t), residuals(t),main= "lme (Mean.temp ~ Size * Altitude |Site)")
abline(h=0, lty=2)

anova(t)
##                numDF denDF  F-value p-value
## (Intercept)        1     8 97387.18  <.0001
## Size               2     8     1.55  0.2708
## Elevation          1     8    15.92  0.0040
## Size:Elevation     2     8     0.03  0.9698
#No large differences in mean temperatures:

Maximum daily temperatures

#Maxs
qplot(Site, Max.mean, data=daily, colour=Size, geom="point") + geom_point(size = 5) + theme_bw() +theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+ ggtitle("Maximum daily temperatures") + ylab("Max daily Temp (°C)") +xlab("Sites") +scale_x_discrete(limits=c("BUTT","I1","I2","I5","NIC","PIA","PIB", "PIC", "L1","L3","L4","L6","PLA","PSP","S1","S2","S4","L2","PSA","S6"))
## Warning: Removed 6 rows containing missing values (geom_point).
## Warning: Removed 6 rows containing missing values (geom_point).

tmax <- lme(Max.mean ~ Size*Elevation, random= ~ 1 | Site, data = daily2)
plot(fitted(tmax), residuals(tmax),main= "lme (Mean of Max.temp ~ Size*Altitude |Site)")
abline(h=0, lty=2)

anova(tmax)
##                numDF denDF  F-value p-value
## (Intercept)        1     8 36966.69  <.0001
## Size               2     8     4.75  0.0436
## Elevation          1     8     9.48  0.0152
## Size:Elevation     2     8     0.83  0.4688
#There is a significant effect of size

Patches DO reach hotter maximum temperatures:

Comparing forest by size categories

sizemax<-tapply(daily$Max.mean, daily$Size, mean, na.rm=T) #by forest size
sizemax
## Intact  Large  Small 
## 24.780 25.400 25.775
tmax <- lme(Max.mean ~ Size*Elevation, random= ~ 1 | Site, data = daily2)
anova(tmax)
##                numDF denDF  F-value p-value
## (Intercept)        1     8 36966.69  <.0001
## Size               2     8     4.75  0.0436
## Elevation          1     8     9.48  0.0152
## Size:Elevation     2     8     0.83  0.4688
tmax3<-lme(Max.mean ~ Size*Elevation, random= ~ 1 | Site, data = daily2)
anova(tmax3)
##                numDF denDF  F-value p-value
## (Intercept)        1     8 36966.69  <.0001
## Size               2     8     4.75  0.0436
## Elevation          1     8     9.48  0.0152
## Size:Elevation     2     8     0.83  0.4688
#No interaction between size and elevation

Finally, contrasting forest patches vs continuous forest, t.max are sign. higher in patches:

typemax<-tapply(daily$Max.mean, daily$Type, mean, na.rm=T) #by forest type
typemax
## Continuous      Patch 
##   24.78000   25.56667
tmax.type <- lme(Max.mean ~ Type+Elevation, random= ~ 1 | Site, data = daily2)
anova(tmax.type)
##             numDF denDF  F-value p-value
## (Intercept)     1    11 34985.77  <.0001
## Type            1    11     7.77  0.0176
## Elevation       1    11     8.34  0.0148
#compare to a no size model:
tmax.notype<-lme(Max.mean ~ Elevation, random= ~ 1 | Site, data = daily2)
anova(tmax.notype)
##             numDF denDF   F-value p-value
## (Intercept)     1    12 25133.624  <.0001
## Elevation       1    12     7.479  0.0181
#Model including forest type has smallest AIC:
AIC(tmax.type, tmax.notype) 
##             df      AIC
## tmax.type    5 40.79742
## tmax.notype  4 43.09047