#Supplement 1 # Fricker, G.A., Wolf, J.A., Saatchi, S.S., Gillespie, T.W. #Predicting spatial variations of tree species richness in tropical forests from high resolution remote sensing. Ecological Applications. # File name: 2015_02_03_bci_ols_predictions.r #is the r-code for making the Ordinary Least Squares (and one GLS) prediction across BCI. # the purpose of this code is to predict species richness at each tree size using the OLS equations # numbers in the input table = size dbh in mm # ex. d10_100 = trees from 1cm to 10 cm dbh # *note d10 = all tree sizes d200 = read.csv(file = 'D:\\bci_publication\\r\\in\\gls\\200.csv', header=T) d100 = read.csv(file = 'D:\\bci_publication\\r\\in\\gls\\100.csv', header=T) d10 = read.csv(file = 'D:\\bci_publication\\r\\in\\gls\\10.csv', header=T) d10_100 = read.csv(file = 'D:\\bci_publication\\r\\in\\gls\\10_100.csv', header=T) d10_200 = read.csv(file = 'D:\\bci_publication\\r\\in\\gls\\10_200.csv', header=T) library(nlme) # Prediction maps #SPECIES #GLS model only made for all stems (no size binning) glsfit = gls(sr_all ~ twi_sd+curv+mch_sd+evi_sd,data = d10,correlation = corGaus(form = ~utm_e+utm_n,nugget = T)) olsfit10_100 = lm(sr_10_100 ~ twi_sd+mch_sd+mch+curv_sd,data = d10_100) #S trees summary (olsfit10_100) olsfit10_200 = lm(sr_10_200 ~ twi_sd+mch_sd+mch+curv_sd,data = d10_200) # SM trees summary(olsfit10_200) olsfit10 = lm(sr_all ~ twi_sd+curv+mch_sd+evi_sd,data = d10) #All stems summary(olsfit10) olsfit100 = lm(sr_100 ~ mch+evi_sd+slp,data = d100) #ML trees summary (olsfit100) olsfit200_max = lm(sr_200_max ~ evi_sd+mch+twi_sd+curv_sd,data = d200) #Large max summary(olsfit200_max) olsfit200_min = lm(sr_200_min ~ evi_sd+mch+twi_sd+curv_sd,data = d200) #Large min summary(olsfit200_min) D_Island = read.csv(file ='D:\\bci_publication\\r\\in\\QB_BCI_prediciton_grid_rsvars.csv', header=T) #island extracted 1-ha data gls_predicted_10 = predict(glsfit, newdata = D_Island, se.fit = T) ols_predicted_10 = predict(olsfit10, newdata = D_Island, se.fit = T) ols_predicted_10_100 = predict(olsfit10_100, newdata = D_Island, se.fit = T) ols_predicted_10_200 = predict(olsfit10_200, newdata = D_Island, se.fit = T) ols_predicted_100 = predict(olsfit100, newdata = D_+++Island, se.fit = T) ols_predicted_200_max = predict(olsfit200_max, newdata = D_Island, se.fit = T) ols_predicted_200_min = predict(olsfit200_min, newdata = D_Island, se.fit = T) #RVIDF = data.frame(FID=D_Island$FID_, ols_rvi_pred=ols_predicted, gls_rvi_pred=gls_predicted, ols_rvi_fused = ols_predicted2, gls_rvi_fused = gls_predicted2) #Include 7 outputs #All Stems Species Richness predictions for each tree size setwd("D:\\bci_publication\\r\\out\\TEMP") RVIDF = data.frame(FID=D_Island$FID, gls_pred=gls_predicted_10,ols_pred_10=ols_predicted_10,ols_pred_10_100=ols_predicted_10_100, ols_pred_10_200=ols_predicted_10_200,ols_pred_100=ols_predicted_100,ols_pred_200_max=ols_predicted_200_max,ols_pred_200_min=ols_predicted_200_min) write.csv(RVIDF, "2014_fricker_predictions_fid.csv", quote=F, sep=",", row.names=F)