Importing Tree Growth Data
treedata <- read.csv("C:\\Users\\Gabriela Krochmal\\Documents\\Morton Aboretum Data\\Practice R Data\\PracticeTreeGrowthData.csv")
Calculating the change in DBH between consecutive censuses
dbh1 <- treedata$DBH_cm.1 - treedata$DBH_cm #census 1-2
dbh2 <- treedata$DBH_cm.2 - treedata$DBH_cm.1 #census 2-3
dbh3 <- treedata$DBH_cm.3 - treedata$DBH_cm.2 #census 3-4
DBH increments into a growth rate
growthrate1 <- 12 * (dbh1) / 6
growthrate2 <- 12 * (dbh2) / 5
growthrate3 <- 12 * (dbh3) / 5
Scatter plots of initial dbh & growth
#create a scatter plot of growth vs. tree dbh (initial dbh on x axis, growth rate on y)
plot(growthrate1 ~ DBH_cm, data=treedata,pch=16, col="blue", cex=0.7, ylim=c(-1.1, 4))
#points function to add all plots on one graph
points(growthrate2 ~ DBH_cm.1, data=treedata,pch=16, cex=0.7, col="red")
points(growthrate3 ~ DBH_cm.2, data=treedata,pch=16, cex=0.7, col="purple")
Growth Function
growthrate = function(c1, c2, cns, pt=16,yr=c(-2,5), maxg=6.5, color="black", addit=FALSE)
{
dbhcol1 = paste("DBH_cm", c1, sep="")
dbhcol2 = paste("DBH_cm", c2, sep="")
datecol1 = paste("date", c1, sep="")
datecol2 = paste("date", c2, sep="")
date1 = gsub("Ene", "Jan", cns[,datecol1])
date2 = gsub("Ene", "Jan", cns[,datecol2])
julian1 = tojulian(date1, "%d-%b-%y")
julian2 = tojulian(date2, "%d-%b-%y")
s2= cns[,dbhcol2]
s1= cns[,dbhcol1]
t = (julian2 - julian1) / 365.25
g=(s2-s1) / t
bad = g>maxg #creating a filtering variable
if(addit)
points(s1[!bad],g[!bad],pch=pt, col=color) #exclamation means NOT
else
plot(s1[!bad],g[!bad],pch=pt,ylim=yr, col=color)
lm1 = lm(g[!bad]~s1[!bad]) #creating a regression line
abline(lm1, col=color)
full = data.frame(dbh1=s1,dbh2=s2, growth=g,time=t,sp_code=cns$sp_code, tag= cns$tag, bad) #creating a new data frame
return(list(growthrate=summary(g),time=summary(t), linearmodel=lm1, growth=full)) #sends data back out
}
Julian Function
tojulian=function(x,dateform='%m/%d/%Y')
{
x=strptime(x,format=dateform)
year=x$year+1900
month=x$mon+1
day=x$mday
return(mdy.date(month=month,day=day,year=year))
}
library(date)
Plots for consecutive censuses
plot.new()
y12=growthrate(c1="", c2=".1", cns=treedata,yr=c(-2,6), pt=20, color="blue", addit=FALSE) #pt=pch pch=point character
y23=growthrate(c1=".1", c2=".2", cns=treedata, pt=20, color="red", addit=TRUE)
y34=growthrate(c1=".2", c2=".3", cns=treedata, pt=20, color="purple", addit=TRUE)
Statisitical Summary
summary(y12$linearmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.05405203 0.165204933 -0.3271817 0.74537439
## s1[!bad] 0.01272084 0.005146531 2.4717316 0.01817098
summary(y23$linearmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.264641158 0.166034146 1.593896 0.1192443
## s1[!bad] 0.005639213 0.005203745 1.083684 0.2853334
summary(y34$linearmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.21457673 0.33696421 -0.6367938 0.5285236453
## s1[!bad] 0.05428041 0.01120045 4.8462716 0.0000271562
Calculating the change in DBH between alternate censuses
#calculate the change in dbh between consecutive censuses for every tree
dbh4 <- treedata$DBH_cm.2 - treedata$DBH_cm #interval 1-3
dbh5 <- treedata$DBH_cm.3 - treedata$DBH_cm #interval 1-4
dbh6 <- treedata$DBH_cm.3 - treedata$DBH_cm.1 #interval 2-4
DBH increments into a growth rate
#convert dbh increment into growth rate (dbh change/time)
growthrate4 <- 12 * (dbh4) / 11 #number is in months
growthrate5 <- 12 * (dbh5) / 16 #number is in months
growthrate6 <- 12 * (dbh6) / 10 #number is in months
Scatter plots of initial dbh & growth
#creating scatterplots to visualize spread of data, to know where to set limits of axis and any outliers
plot(growthrate4 ~ DBH_cm, data=treedata,pch=16, cex=0.7,col="green", ylim=c(-0.5, 8))
#using the points function to add all data onto one graph
points(growthrate5 ~ DBH_cm, data=treedata,pch=16, cex=0.7, col="orange")
points(growthrate6 ~ DBH_cm.1, data=treedata,pch=16, cex=0.7, col="blue")
Plots for alternate censuses
y13=growthrate(c1="", c2=".2", cns=treedata,yr=c(-1,5), pt=20, color="green", addit=FALSE) #pt=pch pch=point character
y14=growthrate(c1="", c2=".3", cns=treedata, pt=20, color="orange", addit=TRUE)
y24=growthrate(c1=".1", c2=".3", cns=treedata, pt=20, color="blue", addit=TRUE)
Statistical Summary
summary(y13$linearmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.073927493 0.155363729 0.475835 0.63698957
## s1[!bad] 0.009764628 0.004839954 2.017504 0.05094018
summary(y24$linearmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.03398873 0.219289901 -0.1549945 8.777160e-01
## s1[!bad] 0.03333430 0.006698611 4.9762996 1.723304e-05
summary(y14$linearmodel)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.04500786 0.189366978 -0.2376753 8.135594e-01
## s1[!bad] 0.02588046 0.005745545 4.5044388 7.469113e-05
This analysis evaluated the diameter at breast height (dbh) growth rates between consecutive census (1-2, 2-3, 3-4). Change between intervals was calculated first, then change was then divided by t(months). Time was eventually converted into Julian time for consistency using the Julian function provided by Dr. Condit. Scatter plots were created to have a visual representation of the data, and summaries were generated to note of any outliers. Significant outliers, and missing data points were excluded from the analysis. Using the ‘growth rate’ function created, I was able to plug the different censuses in to generate summaries. A statistically significant relationship exists between growth rates from censuses 1-2 (pvalue= 0.018) and 3-4 (pvalue=0.000). There was not a significant relationship between census 2-3 (pvalue=0.29). After this inital analysis comparing growth rates between consecutive censuses, I analyzed growth between different censuses to see if there were any significant relationships. I calculcated the change between censuses (1-3, 1-4, 2-4). Similar to the other analysis, I calculated the growth and created scatter plots to visualise the data and note of any outliers.There was a significant statistical relationship between censuses 2-4 (pvalue=0.000) and 1-4 (pvalue=0.000) There was not a significant relationship between census 1-3 (pvalue=0.050).