Import Packages
# Import Packages
library(randomForest)
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
library(e1071)
library(MASS)
library(Metrics)
library(crossval)
Import trainging data
Mastersheet<- read.csv('/Users/lavran_pagano/Downloads/Lidar_Training_Data/Lidar_Training_Data.csv')
Mastersheet<-Mastersheet[,c(1, 4:14)]
LogMastersheet <-log(Mastersheet)
head(Mastersheet)
## Biomass Height_Max Height_90th Height_80th Height_70th Height_60th
## 1 871.66795 24.69305 20.185764 17.364426 16.402422 15.081573
## 2 4368.08175 23.17831 20.175051 18.762633 17.708784 16.554840
## 3 93.84396 13.80469 3.573896 2.688893 1.849311 0.922133
## 4 2183.24861 25.21630 18.768464 15.334843 12.366899 10.346326
## 5 4428.25440 26.17726 25.676257 24.368158 23.180297 21.661765
## 6 1902.20067 24.77719 20.720548 18.824860 17.582340 16.441333
## Height_50th Height_40th Height_30th Height_20th Height_10th Height_Min
## 1 13.0685883 10.7047987 7.6694551 4.69686174 2.64366555 0.566577733
## 2 15.5763903 14.7431707 13.7775090 12.30440731 10.36071844 5.671622276
## 3 0.5074804 0.2877415 0.1435401 0.05910957 0.01463966 0.000000000
## 4 8.3944836 6.6744009 4.7610702 3.31624961 1.88995376 0.005437903
## 5 19.7485580 17.6486725 15.4554695 11.09653397 7.12897930 2.459211111
## 6 15.4770098 14.6396532 13.5641876 11.92233410 9.56084290 2.340075731
OLS
Finding the best OLS model
#OLS with all covariates
fit <- lm(Biomass~.,data=Mastersheet)
Stepwise AIC to determine best model
step <- stepAIC(fit, direction="both")
## Start: AIC=948.46
## Biomass ~ Height_Max + Height_90th + Height_80th + Height_70th +
## Height_60th + Height_50th + Height_40th + Height_30th + Height_20th +
## Height_10th + Height_Min
##
## Df Sum of Sq RSS AIC
## - Height_50th 1 1432 232872563 946.46
## - Height_Min 1 26440 232897570 946.47
## - Height_70th 1 571884 233443015 946.61
## - Height_90th 1 1693318 234564449 946.90
## - Height_60th 1 2628063 235499194 947.15
## - Height_80th 1 2876851 235747982 947.21
## - Height_20th 1 3352095 236223226 947.33
## - Height_10th 1 3856335 236727466 947.46
## - Height_40th 1 5520207 238391338 947.89
## <none> 232871131 948.46
## - Height_Max 1 9838359 242709490 948.99
## - Height_30th 1 10707507 243578638 949.20
##
## Step: AIC=946.46
## Biomass ~ Height_Max + Height_90th + Height_80th + Height_70th +
## Height_60th + Height_40th + Height_30th + Height_20th + Height_10th +
## Height_Min
##
## Df Sum of Sq RSS AIC
## - Height_Min 1 25705 232898268 944.47
## - Height_70th 1 684577 233557140 944.64
## - Height_90th 1 1892794 234765357 944.96
## - Height_80th 1 3070850 235943413 945.26
## - Height_20th 1 3371405 236243968 945.34
## - Height_10th 1 3856023 236728585 945.46
## - Height_60th 1 6906098 239778661 946.25
## <none> 232872563 946.46
## - Height_Max 1 10297804 243170366 947.10
## - Height_30th 1 13247119 246119682 947.84
## + Height_50th 1 1432 232871131 948.46
## - Height_40th 1 17392534 250265097 948.86
##
## Step: AIC=944.47
## Biomass ~ Height_Max + Height_90th + Height_80th + Height_70th +
## Height_60th + Height_40th + Height_30th + Height_20th + Height_10th
##
## Df Sum of Sq RSS AIC
## - Height_70th 1 661223 233559491 942.64
## - Height_90th 1 1870461 234768729 942.96
## - Height_80th 1 3124868 236023136 943.28
## - Height_20th 1 3619281 236517549 943.41
## - Height_10th 1 5007589 237905857 943.77
## - Height_60th 1 6881173 239779440 944.25
## <none> 232898268 944.47
## - Height_Max 1 10277870 243176138 945.10
## - Height_30th 1 13668928 246567195 945.95
## + Height_Min 1 25705 232872563 946.46
## + Height_50th 1 697 232897570 946.47
## - Height_40th 1 17367118 250265386 946.86
##
## Step: AIC=942.64
## Biomass ~ Height_Max + Height_90th + Height_80th + Height_60th +
## Height_40th + Height_30th + Height_20th + Height_10th
##
## Df Sum of Sq RSS AIC
## - Height_90th 1 2410758 235970249 941.27
## - Height_20th 1 4546010 238105501 941.82
## - Height_10th 1 6493666 240053157 942.32
## <none> 233559491 942.64
## - Height_Max 1 10442143 244001634 943.31
## - Height_60th 1 12367357 245926848 943.79
## - Height_30th 1 13810637 247370128 944.15
## - Height_80th 1 13846286 247405777 944.16
## + Height_70th 1 661223 232898268 944.47
## + Height_50th 1 114204 233445287 944.61
## + Height_Min 1 2351 233557140 944.64
## - Height_40th 1 16781194 250340685 944.88
##
## Step: AIC=941.27
## Biomass ~ Height_Max + Height_80th + Height_60th + Height_40th +
## Height_30th + Height_20th + Height_10th
##
## Df Sum of Sq RSS AIC
## - Height_20th 1 5394802 241365051 940.65
## - Height_10th 1 7790542 243760791 941.25
## <none> 235970249 941.27
## - Height_60th 1 10942539 246912788 942.03
## + Height_90th 1 2410758 233559491 942.64
## - Height_30th 1 14360278 250330527 942.87
## + Height_70th 1 1201521 234768729 942.96
## - Height_80th 1 15030632 251000881 943.04
## + Height_Min 1 11920 235958329 943.27
## + Height_50th 1 403 235969846 943.27
## - Height_40th 1 16894138 252864387 943.49
## - Height_Max 1 19848044 255818293 944.20
##
## Step: AIC=940.65
## Biomass ~ Height_Max + Height_80th + Height_60th + Height_40th +
## Height_30th + Height_10th
##
## Df Sum of Sq RSS AIC
## - Height_10th 1 2702982 244068033 939.33
## <none> 241365051 940.65
## - Height_30th 1 10023565 251388616 941.13
## + Height_20th 1 5394802 235970249 941.27
## - Height_60th 1 12536275 253901326 941.74
## + Height_90th 1 3259550 238105501 941.82
## - Height_40th 1 12973498 254338549 941.84
## + Height_70th 1 2606331 238758720 941.99
## + Height_Min 1 1023562 240341489 942.39
## - Height_80th 1 16227769 257592820 942.62
## + Height_50th 1 88 241364963 942.65
## - Height_Max 1 18092590 259457641 943.06
##
## Step: AIC=939.33
## Biomass ~ Height_Max + Height_80th + Height_60th + Height_40th +
## Height_30th
##
## Df Sum of Sq RSS AIC
## <none> 244068033 939.33
## + Height_90th 1 3777637 240290396 940.38
## + Height_70th 1 3584823 240483210 940.42
## - Height_60th 1 12844609 256912642 940.46
## + Height_Min 1 3230535 240837498 940.51
## + Height_10th 1 2702982 241365051 940.65
## + Height_20th 1 307242 243760791 941.25
## + Height_50th 1 58808 244009225 941.31
## - Height_80th 1 16508909 260576942 941.32
## - Height_Max 1 17423403 261491436 941.53
## - Height_40th 1 17731763 261799795 941.61
## - Height_30th 1 24929710 268997743 943.26
step$anova # display results
## Stepwise Model Path
## Analysis of Deviance Table
##
## Initial Model:
## Biomass ~ Height_Max + Height_90th + Height_80th + Height_70th +
## Height_60th + Height_50th + Height_40th + Height_30th + Height_20th +
## Height_10th + Height_Min
##
## Final Model:
## Biomass ~ Height_Max + Height_80th + Height_60th + Height_40th +
## Height_30th
##
##
## Step Df Deviance Resid. Df Resid. Dev AIC
## 1 49 232871131 948.4624
## 2 - Height_50th 1 1431.924 50 232872563 946.4628
## 3 - Height_Min 1 25704.777 51 232898268 944.4695
## 4 - Height_70th 1 661223.335 52 233559491 942.6425
## 5 - Height_90th 1 2410758.114 53 235970249 941.2689
## 6 - Height_20th 1 5394801.599 54 241365051 940.6478
## 7 - Height_10th 1 2702982.274 55 244068033 939.3271
OLS Model with the lowest AIC
AIC(lm<- lm(Biomass ~ Height_Max + Height_80th + Height_60th + Height_40th +
Height_30th,data=Mastersheet))
## [1] 1114.438
summary(lm)
##
## Call:
## lm(formula = Biomass ~ Height_Max + Height_80th + Height_60th +
## Height_40th + Height_30th, data = Mastersheet)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3441.3 -1411.8 -319.2 1072.9 7974.7
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1142.7 1977.4 -0.578 0.5657
## Height_Max 326.3 164.7 1.981 0.0525 .
## Height_80th -844.8 438.0 -1.929 0.0589 .
## Height_60th 1469.9 864.0 1.701 0.0945 .
## Height_40th -2391.3 1196.3 -1.999 0.0506 .
## Height_30th 1717.7 724.7 2.370 0.0213 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2107 on 55 degrees of freedom
## Multiple R-squared: 0.2757, Adjusted R-squared: 0.2098
## F-statistic: 4.187 on 5 and 55 DF, p-value: 0.002701
10 Fold Cross Validation for OLS
# set seed
set.seed(100)
# create a function for cross valdidated R^2 and RMSE
lmfun <- function(train.x, train.y, test.x, test.y)
{lm.fit <- lm(train.y ~ ., data=train.x)
R2 <- cor(test.x, test.y) ^ 2
predbio <- predict(lm.fit, test.x )
RMSE <- rmse(predbio,test.y)
stats<-data.frame(R2,RMSE)
return(stats)
}
# dataframe of lidar predictors from the model with the lowest AIC
x <- Mastersheet[c( "Height_Max", "Height_80th", "Height_60th", "Height_40th" ,"Height_30th")]
# vector of biomass
y <-Mastersheet$Biomass
# apply the crossval function
results <- crossval(lmfun,x,y, K=10)
## Number of folds: 10
## Total number of CV fits: 200
##
## Round # 1 of 20
## CV Fit # 1 of 200
## CV Fit # 2 of 200
## CV Fit # 3 of 200
## CV Fit # 4 of 200
## CV Fit # 5 of 200
## CV Fit # 6 of 200
## CV Fit # 7 of 200
## CV Fit # 8 of 200
## CV Fit # 9 of 200
## CV Fit # 10 of 200
##
## Round # 2 of 20
## CV Fit # 11 of 200
## CV Fit # 12 of 200
## CV Fit # 13 of 200
## CV Fit # 14 of 200
## CV Fit # 15 of 200
## CV Fit # 16 of 200
## CV Fit # 17 of 200
## CV Fit # 18 of 200
## CV Fit # 19 of 200
## CV Fit # 20 of 200
##
## Round # 3 of 20
## CV Fit # 21 of 200
## CV Fit # 22 of 200
## CV Fit # 23 of 200
## CV Fit # 24 of 200
## CV Fit # 25 of 200
## CV Fit # 26 of 200
## CV Fit # 27 of 200
## CV Fit # 28 of 200
## CV Fit # 29 of 200
## CV Fit # 30 of 200
##
## Round # 4 of 20
## CV Fit # 31 of 200
## CV Fit # 32 of 200
## CV Fit # 33 of 200
## CV Fit # 34 of 200
## CV Fit # 35 of 200
## CV Fit # 36 of 200
## CV Fit # 37 of 200
## CV Fit # 38 of 200
## CV Fit # 39 of 200
## CV Fit # 40 of 200
##
## Round # 5 of 20
## CV Fit # 41 of 200
## CV Fit # 42 of 200
## CV Fit # 43 of 200
## CV Fit # 44 of 200
## CV Fit # 45 of 200
## CV Fit # 46 of 200
## CV Fit # 47 of 200
## CV Fit # 48 of 200
## CV Fit # 49 of 200
## CV Fit # 50 of 200
##
## Round # 6 of 20
## CV Fit # 51 of 200
## CV Fit # 52 of 200
## CV Fit # 53 of 200
## CV Fit # 54 of 200
## CV Fit # 55 of 200
## CV Fit # 56 of 200
## CV Fit # 57 of 200
## CV Fit # 58 of 200
## CV Fit # 59 of 200
## CV Fit # 60 of 200
##
## Round # 7 of 20
## CV Fit # 61 of 200
## CV Fit # 62 of 200
## CV Fit # 63 of 200
## CV Fit # 64 of 200
## CV Fit # 65 of 200
## CV Fit # 66 of 200
## CV Fit # 67 of 200
## CV Fit # 68 of 200
## CV Fit # 69 of 200
## CV Fit # 70 of 200
##
## Round # 8 of 20
## CV Fit # 71 of 200
## CV Fit # 72 of 200
## CV Fit # 73 of 200
## CV Fit # 74 of 200
## CV Fit # 75 of 200
## CV Fit # 76 of 200
## CV Fit # 77 of 200
## CV Fit # 78 of 200
## CV Fit # 79 of 200
## CV Fit # 80 of 200
##
## Round # 9 of 20
## CV Fit # 81 of 200
## CV Fit # 82 of 200
## CV Fit # 83 of 200
## CV Fit # 84 of 200
## CV Fit # 85 of 200
## CV Fit # 86 of 200
## CV Fit # 87 of 200
## CV Fit # 88 of 200
## CV Fit # 89 of 200
## CV Fit # 90 of 200
##
## Round # 10 of 20
## CV Fit # 91 of 200
## CV Fit # 92 of 200
## CV Fit # 93 of 200
## CV Fit # 94 of 200
## CV Fit # 95 of 200
## CV Fit # 96 of 200
## CV Fit # 97 of 200
## CV Fit # 98 of 200
## CV Fit # 99 of 200
## CV Fit # 100 of 200
##
## Round # 11 of 20
## CV Fit # 101 of 200
## CV Fit # 102 of 200
## CV Fit # 103 of 200
## CV Fit # 104 of 200
## CV Fit # 105 of 200
## CV Fit # 106 of 200
## CV Fit # 107 of 200
## CV Fit # 108 of 200
## CV Fit # 109 of 200
## CV Fit # 110 of 200
##
## Round # 12 of 20
## CV Fit # 111 of 200
## CV Fit # 112 of 200
## CV Fit # 113 of 200
## CV Fit # 114 of 200
## CV Fit # 115 of 200
## CV Fit # 116 of 200
## CV Fit # 117 of 200
## CV Fit # 118 of 200
## CV Fit # 119 of 200
## CV Fit # 120 of 200
##
## Round # 13 of 20
## CV Fit # 121 of 200
## CV Fit # 122 of 200
## CV Fit # 123 of 200
## CV Fit # 124 of 200
## CV Fit # 125 of 200
## CV Fit # 126 of 200
## CV Fit # 127 of 200
## CV Fit # 128 of 200
## CV Fit # 129 of 200
## CV Fit # 130 of 200
##
## Round # 14 of 20
## CV Fit # 131 of 200
## CV Fit # 132 of 200
## CV Fit # 133 of 200
## CV Fit # 134 of 200
## CV Fit # 135 of 200
## CV Fit # 136 of 200
## CV Fit # 137 of 200
## CV Fit # 138 of 200
## CV Fit # 139 of 200
## CV Fit # 140 of 200
##
## Round # 15 of 20
## CV Fit # 141 of 200
## CV Fit # 142 of 200
## CV Fit # 143 of 200
## CV Fit # 144 of 200
## CV Fit # 145 of 200
## CV Fit # 146 of 200
## CV Fit # 147 of 200
## CV Fit # 148 of 200
## CV Fit # 149 of 200
## CV Fit # 150 of 200
##
## Round # 16 of 20
## CV Fit # 151 of 200
## CV Fit # 152 of 200
## CV Fit # 153 of 200
## CV Fit # 154 of 200
## CV Fit # 155 of 200
## CV Fit # 156 of 200
## CV Fit # 157 of 200
## CV Fit # 158 of 200
## CV Fit # 159 of 200
## CV Fit # 160 of 200
##
## Round # 17 of 20
## CV Fit # 161 of 200
## CV Fit # 162 of 200
## CV Fit # 163 of 200
## CV Fit # 164 of 200
## CV Fit # 165 of 200
## CV Fit # 166 of 200
## CV Fit # 167 of 200
## CV Fit # 168 of 200
## CV Fit # 169 of 200
## CV Fit # 170 of 200
##
## Round # 18 of 20
## CV Fit # 171 of 200
## CV Fit # 172 of 200
## CV Fit # 173 of 200
## CV Fit # 174 of 200
## CV Fit # 175 of 200
## CV Fit # 176 of 200
## CV Fit # 177 of 200
## CV Fit # 178 of 200
## CV Fit # 179 of 200
## CV Fit # 180 of 200
##
## Round # 19 of 20
## CV Fit # 181 of 200
## CV Fit # 182 of 200
## CV Fit # 183 of 200
## CV Fit # 184 of 200
## CV Fit # 185 of 200
## CV Fit # 186 of 200
## CV Fit # 187 of 200
## CV Fit # 188 of 200
## CV Fit # 189 of 200
## CV Fit # 190 of 200
##
## Round # 20 of 20
## CV Fit # 191 of 200
## CV Fit # 192 of 200
## CV Fit # 193 of 200
## CV Fit # 194 of 200
## CV Fit # 195 of 200
## CV Fit # 196 of 200
## CV Fit # 197 of 200
## CV Fit # 198 of 200
## CV Fit # 199 of 200
## CV Fit # 200 of 200
#print the results
results$stat
## R2 RMSE
## 0.2732753 2060.9933560
results$stat.se
## R2 RMSE
## 0.01652384 50.07422698
Power Law
Finding the best Power Law model
#Power Law all covariates (note any covariates with zeros were not considered)
fit <- lm(Biomass~Height_Max+Height_40th+Height_50th+Height_60th+Height_70th+Height_80th+Height_90th,data=LogMastersheet)
summary(fit)
##
## Call:
## lm(formula = Biomass ~ Height_Max + Height_40th + Height_50th +
## Height_60th + Height_70th + Height_80th + Height_90th, data = LogMastersheet)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.2742 -0.3321 0.1641 0.6426 1.6132
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.357 3.022 0.449 0.655
## Height_Max 2.848 1.734 1.643 0.106
## Height_40th 1.053 2.627 0.401 0.690
## Height_50th -7.843 11.180 -0.702 0.486
## Height_60th 14.196 14.997 0.947 0.348
## Height_70th -1.607 9.105 -0.177 0.861
## Height_80th -8.134 5.070 -1.604 0.115
## Height_90th 1.546 2.656 0.582 0.563
##
## Residual standard error: 0.8835 on 53 degrees of freedom
## Multiple R-squared: 0.4759, Adjusted R-squared: 0.4067
## F-statistic: 6.876 on 7 and 53 DF, p-value: 8.077e-06
Stepwise AIC to determine best model
step <- stepAIC(fit, direction="both")
## Start: AIC=-7.69
## Biomass ~ Height_Max + Height_40th + Height_50th + Height_60th +
## Height_70th + Height_80th + Height_90th
##
## Df Sum of Sq RSS AIC
## - Height_70th 1 0.02432 41.393 -9.6533
## - Height_40th 1 0.12545 41.494 -9.5044
## - Height_90th 1 0.26457 41.633 -9.3002
## - Height_50th 1 0.38418 41.753 -9.1252
## - Height_60th 1 0.69936 42.068 -8.6665
## <none> 41.369 -7.6891
## - Height_80th 1 2.00918 43.378 -6.7962
## - Height_Max 1 2.10584 43.475 -6.6604
##
## Step: AIC=-9.65
## Biomass ~ Height_Max + Height_40th + Height_50th + Height_60th +
## Height_80th + Height_90th
##
## Df Sum of Sq RSS AIC
## - Height_40th 1 0.1178 41.511 -11.4798
## - Height_50th 1 0.6426 42.036 -10.7136
## - Height_90th 1 0.7420 42.135 -10.5695
## <none> 41.393 -9.6533
## - Height_Max 1 2.2877 43.681 -8.3719
## - Height_60th 1 2.4337 43.827 -8.1682
## + Height_70th 1 0.0243 41.369 -7.6891
## - Height_80th 1 5.8845 47.278 -3.5451
##
## Step: AIC=-11.48
## Biomass ~ Height_Max + Height_50th + Height_60th + Height_80th +
## Height_90th
##
## Df Sum of Sq RSS AIC
## - Height_90th 1 0.7323 42.243 -12.4131
## <none> 41.511 -11.4798
## + Height_40th 1 0.1178 41.393 -9.6533
## + Height_70th 1 0.0167 41.494 -9.5044
## - Height_Max 1 3.3991 44.910 -8.6788
## - Height_80th 1 5.8043 47.315 -5.4965
## - Height_50th 1 8.0369 49.548 -2.6840
## - Height_60th 1 8.4759 49.987 -2.1459
##
## Step: AIC=-12.41
## Biomass ~ Height_Max + Height_50th + Height_60th + Height_80th
##
## Df Sum of Sq RSS AIC
## <none> 42.243 -12.4131
## + Height_90th 1 0.7323 41.511 -11.4798
## + Height_70th 1 0.1460 42.097 -10.6243
## + Height_40th 1 0.1082 42.135 -10.5695
## - Height_Max 1 4.0934 46.337 -8.7713
## - Height_80th 1 6.0438 48.287 -6.2562
## - Height_50th 1 7.3151 49.558 -4.6710
## - Height_60th 1 7.7462 49.990 -4.1427
step$anova # display results
## Stepwise Model Path
## Analysis of Deviance Table
##
## Initial Model:
## Biomass ~ Height_Max + Height_40th + Height_50th + Height_60th +
## Height_70th + Height_80th + Height_90th
##
## Final Model:
## Biomass ~ Height_Max + Height_50th + Height_60th + Height_80th
##
##
## Step Df Deviance Resid. Df Resid. Dev AIC
## 1 53 41.36883 -7.689118
## 2 - Height_70th 1 0.02432391 54 41.39315 -9.653262
## 3 - Height_40th 1 0.11784775 55 41.51100 -11.479840
## 4 - Height_90th 1 0.73232772 56 42.24333 -12.413074
Power law model with the lowest AIC
AIC(powerlaw<-lm(Biomass ~ Height_Max + Height_50th+Height_60th+Height_80th ,data=LogMastersheet))
## [1] 162.6974
summary(powerlaw)
##
## Call:
## lm(formula = Biomass ~ Height_Max + Height_50th + Height_60th +
## Height_80th, data = LogMastersheet)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.1754 -0.3851 0.1825 0.6311 1.6760
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.397 2.746 0.509 0.61299
## Height_Max 3.237 1.390 2.329 0.02347 *
## Height_50th -3.343 1.074 -3.114 0.00291 **
## Height_60th 8.705 2.717 3.204 0.00223 **
## Height_80th -6.541 2.311 -2.831 0.00644 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8685 on 56 degrees of freedom
## Multiple R-squared: 0.4648, Adjusted R-squared: 0.4266
## F-statistic: 12.16 on 4 and 56 DF, p-value: 3.5e-07
10 Fold Cross Validation for Powerlaw
# set seed
set.seed(100)
# create a function for cross valdidated R^2 and RMSE
plfun <- function(train.x, train.y, test.x, test.y)
{pl.fit <- lm(train.y ~ ., data=train.x)
R2 <- cor(test.x, test.y) ^ 2
predbio <- predict(pl.fit, test.x )
predbio<-exp(predbio)
RMSE <- rmse(predbio,test.y)
stats<-data.frame(R2,RMSE)
return(stats)
}
# dataframe of lidar predictors from the model with the lowest AIC
x <- LogMastersheet[c( "Height_Max", "Height_50th", "Height_60th", "Height_80th")]
# vector of biomass
y <-LogMastersheet$Biomass
# apply the crossval function
results <- crossval(plfun,x,y, K=10)
## Number of folds: 10
## Total number of CV fits: 200
##
## Round # 1 of 20
## CV Fit # 1 of 200
## CV Fit # 2 of 200
## CV Fit # 3 of 200
## CV Fit # 4 of 200
## CV Fit # 5 of 200
## CV Fit # 6 of 200
## CV Fit # 7 of 200
## CV Fit # 8 of 200
## CV Fit # 9 of 200
## CV Fit # 10 of 200
##
## Round # 2 of 20
## CV Fit # 11 of 200
## CV Fit # 12 of 200
## CV Fit # 13 of 200
## CV Fit # 14 of 200
## CV Fit # 15 of 200
## CV Fit # 16 of 200
## CV Fit # 17 of 200
## CV Fit # 18 of 200
## CV Fit # 19 of 200
## CV Fit # 20 of 200
##
## Round # 3 of 20
## CV Fit # 21 of 200
## CV Fit # 22 of 200
## CV Fit # 23 of 200
## CV Fit # 24 of 200
## CV Fit # 25 of 200
## CV Fit # 26 of 200
## CV Fit # 27 of 200
## CV Fit # 28 of 200
## CV Fit # 29 of 200
## CV Fit # 30 of 200
##
## Round # 4 of 20
## CV Fit # 31 of 200
## CV Fit # 32 of 200
## CV Fit # 33 of 200
## CV Fit # 34 of 200
## CV Fit # 35 of 200
## CV Fit # 36 of 200
## CV Fit # 37 of 200
## CV Fit # 38 of 200
## CV Fit # 39 of 200
## CV Fit # 40 of 200
##
## Round # 5 of 20
## CV Fit # 41 of 200
## CV Fit # 42 of 200
## CV Fit # 43 of 200
## CV Fit # 44 of 200
## CV Fit # 45 of 200
## CV Fit # 46 of 200
## CV Fit # 47 of 200
## CV Fit # 48 of 200
## CV Fit # 49 of 200
## CV Fit # 50 of 200
##
## Round # 6 of 20
## CV Fit # 51 of 200
## CV Fit # 52 of 200
## CV Fit # 53 of 200
## CV Fit # 54 of 200
## CV Fit # 55 of 200
## CV Fit # 56 of 200
## CV Fit # 57 of 200
## CV Fit # 58 of 200
## CV Fit # 59 of 200
## CV Fit # 60 of 200
##
## Round # 7 of 20
## CV Fit # 61 of 200
## CV Fit # 62 of 200
## CV Fit # 63 of 200
## CV Fit # 64 of 200
## CV Fit # 65 of 200
## CV Fit # 66 of 200
## CV Fit # 67 of 200
## CV Fit # 68 of 200
## CV Fit # 69 of 200
## CV Fit # 70 of 200
##
## Round # 8 of 20
## CV Fit # 71 of 200
## CV Fit # 72 of 200
## CV Fit # 73 of 200
## CV Fit # 74 of 200
## CV Fit # 75 of 200
## CV Fit # 76 of 200
## CV Fit # 77 of 200
## CV Fit # 78 of 200
## CV Fit # 79 of 200
## CV Fit # 80 of 200
##
## Round # 9 of 20
## CV Fit # 81 of 200
## CV Fit # 82 of 200
## CV Fit # 83 of 200
## CV Fit # 84 of 200
## CV Fit # 85 of 200
## CV Fit # 86 of 200
## CV Fit # 87 of 200
## CV Fit # 88 of 200
## CV Fit # 89 of 200
## CV Fit # 90 of 200
##
## Round # 10 of 20
## CV Fit # 91 of 200
## CV Fit # 92 of 200
## CV Fit # 93 of 200
## CV Fit # 94 of 200
## CV Fit # 95 of 200
## CV Fit # 96 of 200
## CV Fit # 97 of 200
## CV Fit # 98 of 200
## CV Fit # 99 of 200
## CV Fit # 100 of 200
##
## Round # 11 of 20
## CV Fit # 101 of 200
## CV Fit # 102 of 200
## CV Fit # 103 of 200
## CV Fit # 104 of 200
## CV Fit # 105 of 200
## CV Fit # 106 of 200
## CV Fit # 107 of 200
## CV Fit # 108 of 200
## CV Fit # 109 of 200
## CV Fit # 110 of 200
##
## Round # 12 of 20
## CV Fit # 111 of 200
## CV Fit # 112 of 200
## CV Fit # 113 of 200
## CV Fit # 114 of 200
## CV Fit # 115 of 200
## CV Fit # 116 of 200
## CV Fit # 117 of 200
## CV Fit # 118 of 200
## CV Fit # 119 of 200
## CV Fit # 120 of 200
##
## Round # 13 of 20
## CV Fit # 121 of 200
## CV Fit # 122 of 200
## CV Fit # 123 of 200
## CV Fit # 124 of 200
## CV Fit # 125 of 200
## CV Fit # 126 of 200
## CV Fit # 127 of 200
## CV Fit # 128 of 200
## CV Fit # 129 of 200
## CV Fit # 130 of 200
##
## Round # 14 of 20
## CV Fit # 131 of 200
## CV Fit # 132 of 200
## CV Fit # 133 of 200
## CV Fit # 134 of 200
## CV Fit # 135 of 200
## CV Fit # 136 of 200
## CV Fit # 137 of 200
## CV Fit # 138 of 200
## CV Fit # 139 of 200
## CV Fit # 140 of 200
##
## Round # 15 of 20
## CV Fit # 141 of 200
## CV Fit # 142 of 200
## CV Fit # 143 of 200
## CV Fit # 144 of 200
## CV Fit # 145 of 200
## CV Fit # 146 of 200
## CV Fit # 147 of 200
## CV Fit # 148 of 200
## CV Fit # 149 of 200
## CV Fit # 150 of 200
##
## Round # 16 of 20
## CV Fit # 151 of 200
## CV Fit # 152 of 200
## CV Fit # 153 of 200
## CV Fit # 154 of 200
## CV Fit # 155 of 200
## CV Fit # 156 of 200
## CV Fit # 157 of 200
## CV Fit # 158 of 200
## CV Fit # 159 of 200
## CV Fit # 160 of 200
##
## Round # 17 of 20
## CV Fit # 161 of 200
## CV Fit # 162 of 200
## CV Fit # 163 of 200
## CV Fit # 164 of 200
## CV Fit # 165 of 200
## CV Fit # 166 of 200
## CV Fit # 167 of 200
## CV Fit # 168 of 200
## CV Fit # 169 of 200
## CV Fit # 170 of 200
##
## Round # 18 of 20
## CV Fit # 171 of 200
## CV Fit # 172 of 200
## CV Fit # 173 of 200
## CV Fit # 174 of 200
## CV Fit # 175 of 200
## CV Fit # 176 of 200
## CV Fit # 177 of 200
## CV Fit # 178 of 200
## CV Fit # 179 of 200
## CV Fit # 180 of 200
##
## Round # 19 of 20
## CV Fit # 181 of 200
## CV Fit # 182 of 200
## CV Fit # 183 of 200
## CV Fit # 184 of 200
## CV Fit # 185 of 200
## CV Fit # 186 of 200
## CV Fit # 187 of 200
## CV Fit # 188 of 200
## CV Fit # 189 of 200
## CV Fit # 190 of 200
##
## Round # 20 of 20
## CV Fit # 191 of 200
## CV Fit # 192 of 200
## CV Fit # 193 of 200
## CV Fit # 194 of 200
## CV Fit # 195 of 200
## CV Fit # 196 of 200
## CV Fit # 197 of 200
## CV Fit # 198 of 200
## CV Fit # 199 of 200
## CV Fit # 200 of 200
#print the results
results$stat
## R2 RMSE
## 0.3737641 2452.9323400
results$stat.se
## R2 RMSE
## 0.02211976 56.33047884
Random forest
Random forest variable importance
RandysForest<-randomForest(Biomass~ ., data= Mastersheet)
varImpPlot(RandysForest)

10 Fold Cross Validation for Random Forest
# set seed
set.seed(100)
# create a function for cross valdidated R^2 and RMSE
rffun <- function(train.x, train.y, test.x, test.y)
{rf.fit <- randomForest(train.y ~ ., data=train.x,type="eps-regression")
R2 <- cor(test.x, test.y) ^ 2
predbio <- predict(rf.fit, test.x )
RMSE <- rmse(predbio,test.y)
stats<-data.frame(R2,RMSE)
return(stats)
}
# dataframe of all lidar predictors from the model
x <- Mastersheet[c( "Height_Max", "Height_Min","Height_90th","Height_10th","Height_20th")]
# vector of biomass
y <- Mastersheet$Biomass
# apply the crossval function
results <- crossval(rffun,x,y, K=10)
## Number of folds: 10
## Total number of CV fits: 200
##
## Round # 1 of 20
## CV Fit # 1 of 200
## CV Fit # 2 of 200
## CV Fit # 3 of 200
## CV Fit # 4 of 200
## CV Fit # 5 of 200
## CV Fit # 6 of 200
## CV Fit # 7 of 200
## CV Fit # 8 of 200
## CV Fit # 9 of 200
## CV Fit # 10 of 200
##
## Round # 2 of 20
## CV Fit # 11 of 200
## CV Fit # 12 of 200
## CV Fit # 13 of 200
## CV Fit # 14 of 200
## CV Fit # 15 of 200
## CV Fit # 16 of 200
## CV Fit # 17 of 200
## CV Fit # 18 of 200
## CV Fit # 19 of 200
## CV Fit # 20 of 200
##
## Round # 3 of 20
## CV Fit # 21 of 200
## CV Fit # 22 of 200
## CV Fit # 23 of 200
## CV Fit # 24 of 200
## CV Fit # 25 of 200
## CV Fit # 26 of 200
## CV Fit # 27 of 200
## CV Fit # 28 of 200
## CV Fit # 29 of 200
## CV Fit # 30 of 200
##
## Round # 4 of 20
## CV Fit # 31 of 200
## CV Fit # 32 of 200
## CV Fit # 33 of 200
## CV Fit # 34 of 200
## CV Fit # 35 of 200
## CV Fit # 36 of 200
## CV Fit # 37 of 200
## CV Fit # 38 of 200
## CV Fit # 39 of 200
## CV Fit # 40 of 200
##
## Round # 5 of 20
## CV Fit # 41 of 200
## CV Fit # 42 of 200
## CV Fit # 43 of 200
## CV Fit # 44 of 200
## CV Fit # 45 of 200
## CV Fit # 46 of 200
## CV Fit # 47 of 200
## CV Fit # 48 of 200
## CV Fit # 49 of 200
## CV Fit # 50 of 200
##
## Round # 6 of 20
## CV Fit # 51 of 200
## CV Fit # 52 of 200
## CV Fit # 53 of 200
## CV Fit # 54 of 200
## CV Fit # 55 of 200
## CV Fit # 56 of 200
## CV Fit # 57 of 200
## CV Fit # 58 of 200
## CV Fit # 59 of 200
## CV Fit # 60 of 200
##
## Round # 7 of 20
## CV Fit # 61 of 200
## CV Fit # 62 of 200
## CV Fit # 63 of 200
## CV Fit # 64 of 200
## CV Fit # 65 of 200
## CV Fit # 66 of 200
## CV Fit # 67 of 200
## CV Fit # 68 of 200
## CV Fit # 69 of 200
## CV Fit # 70 of 200
##
## Round # 8 of 20
## CV Fit # 71 of 200
## CV Fit # 72 of 200
## CV Fit # 73 of 200
## CV Fit # 74 of 200
## CV Fit # 75 of 200
## CV Fit # 76 of 200
## CV Fit # 77 of 200
## CV Fit # 78 of 200
## CV Fit # 79 of 200
## CV Fit # 80 of 200
##
## Round # 9 of 20
## CV Fit # 81 of 200
## CV Fit # 82 of 200
## CV Fit # 83 of 200
## CV Fit # 84 of 200
## CV Fit # 85 of 200
## CV Fit # 86 of 200
## CV Fit # 87 of 200
## CV Fit # 88 of 200
## CV Fit # 89 of 200
## CV Fit # 90 of 200
##
## Round # 10 of 20
## CV Fit # 91 of 200
## CV Fit # 92 of 200
## CV Fit # 93 of 200
## CV Fit # 94 of 200
## CV Fit # 95 of 200
## CV Fit # 96 of 200
## CV Fit # 97 of 200
## CV Fit # 98 of 200
## CV Fit # 99 of 200
## CV Fit # 100 of 200
##
## Round # 11 of 20
## CV Fit # 101 of 200
## CV Fit # 102 of 200
## CV Fit # 103 of 200
## CV Fit # 104 of 200
## CV Fit # 105 of 200
## CV Fit # 106 of 200
## CV Fit # 107 of 200
## CV Fit # 108 of 200
## CV Fit # 109 of 200
## CV Fit # 110 of 200
##
## Round # 12 of 20
## CV Fit # 111 of 200
## CV Fit # 112 of 200
## CV Fit # 113 of 200
## CV Fit # 114 of 200
## CV Fit # 115 of 200
## CV Fit # 116 of 200
## CV Fit # 117 of 200
## CV Fit # 118 of 200
## CV Fit # 119 of 200
## CV Fit # 120 of 200
##
## Round # 13 of 20
## CV Fit # 121 of 200
## CV Fit # 122 of 200
## CV Fit # 123 of 200
## CV Fit # 124 of 200
## CV Fit # 125 of 200
## CV Fit # 126 of 200
## CV Fit # 127 of 200
## CV Fit # 128 of 200
## CV Fit # 129 of 200
## CV Fit # 130 of 200
##
## Round # 14 of 20
## CV Fit # 131 of 200
## CV Fit # 132 of 200
## CV Fit # 133 of 200
## CV Fit # 134 of 200
## CV Fit # 135 of 200
## CV Fit # 136 of 200
## CV Fit # 137 of 200
## CV Fit # 138 of 200
## CV Fit # 139 of 200
## CV Fit # 140 of 200
##
## Round # 15 of 20
## CV Fit # 141 of 200
## CV Fit # 142 of 200
## CV Fit # 143 of 200
## CV Fit # 144 of 200
## CV Fit # 145 of 200
## CV Fit # 146 of 200
## CV Fit # 147 of 200
## CV Fit # 148 of 200
## CV Fit # 149 of 200
## CV Fit # 150 of 200
##
## Round # 16 of 20
## CV Fit # 151 of 200
## CV Fit # 152 of 200
## CV Fit # 153 of 200
## CV Fit # 154 of 200
## CV Fit # 155 of 200
## CV Fit # 156 of 200
## CV Fit # 157 of 200
## CV Fit # 158 of 200
## CV Fit # 159 of 200
## CV Fit # 160 of 200
##
## Round # 17 of 20
## CV Fit # 161 of 200
## CV Fit # 162 of 200
## CV Fit # 163 of 200
## CV Fit # 164 of 200
## CV Fit # 165 of 200
## CV Fit # 166 of 200
## CV Fit # 167 of 200
## CV Fit # 168 of 200
## CV Fit # 169 of 200
## CV Fit # 170 of 200
##
## Round # 18 of 20
## CV Fit # 171 of 200
## CV Fit # 172 of 200
## CV Fit # 173 of 200
## CV Fit # 174 of 200
## CV Fit # 175 of 200
## CV Fit # 176 of 200
## CV Fit # 177 of 200
## CV Fit # 178 of 200
## CV Fit # 179 of 200
## CV Fit # 180 of 200
##
## Round # 19 of 20
## CV Fit # 181 of 200
## CV Fit # 182 of 200
## CV Fit # 183 of 200
## CV Fit # 184 of 200
## CV Fit # 185 of 200
## CV Fit # 186 of 200
## CV Fit # 187 of 200
## CV Fit # 188 of 200
## CV Fit # 189 of 200
## CV Fit # 190 of 200
##
## Round # 20 of 20
## CV Fit # 191 of 200
## CV Fit # 192 of 200
## CV Fit # 193 of 200
## CV Fit # 194 of 200
## CV Fit # 195 of 200
## CV Fit # 196 of 200
## CV Fit # 197 of 200
## CV Fit # 198 of 200
## CV Fit # 199 of 200
## CV Fit # 200 of 200
#print the results
results$stat
## R2 RMSE
## 0.2798815 2074.9385785
results$stat.se
## R2 RMSE
## 0.01727912 58.60331380
SVR
10 Fold Cross Validation for SVR
# set seed
set.seed(100)
# create a function for cross valdidated R^2 and RMSE
svrfun <- function(train.x, train.y, test.x, test.y)
{svr.fit <- svm(train.y ~ ., data=train.x)
R2 <- cor(test.x, test.y) ^ 2
predbio <- predict(svr.fit, test.x )
RMSE <- rmse(predbio,test.y)
stats<-data.frame(R2,RMSE)
return(stats)
}
# dataframe of all lidar predictors from the model
x <- Mastersheet[c( "Height_Max","Height_Min","Height_10th")]
# vector of biomass
y <- Mastersheet$Biomass
# apply the crossval function
results <- crossval(svrfun,x,y, K=10)
## Number of folds: 10
## Total number of CV fits: 200
##
## Round # 1 of 20
## CV Fit # 1 of 200
## CV Fit # 2 of 200
## CV Fit # 3 of 200
## CV Fit # 4 of 200
## CV Fit # 5 of 200
## CV Fit # 6 of 200
## CV Fit # 7 of 200
## CV Fit # 8 of 200
## CV Fit # 9 of 200
## CV Fit # 10 of 200
##
## Round # 2 of 20
## CV Fit # 11 of 200
## CV Fit # 12 of 200
## CV Fit # 13 of 200
## CV Fit # 14 of 200
## CV Fit # 15 of 200
## CV Fit # 16 of 200
## CV Fit # 17 of 200
## CV Fit # 18 of 200
## CV Fit # 19 of 200
## CV Fit # 20 of 200
##
## Round # 3 of 20
## CV Fit # 21 of 200
## CV Fit # 22 of 200
## CV Fit # 23 of 200
## CV Fit # 24 of 200
## CV Fit # 25 of 200
## CV Fit # 26 of 200
## CV Fit # 27 of 200
## CV Fit # 28 of 200
## CV Fit # 29 of 200
## CV Fit # 30 of 200
##
## Round # 4 of 20
## CV Fit # 31 of 200
## CV Fit # 32 of 200
## CV Fit # 33 of 200
## CV Fit # 34 of 200
## CV Fit # 35 of 200
## CV Fit # 36 of 200
## CV Fit # 37 of 200
## CV Fit # 38 of 200
## CV Fit # 39 of 200
## CV Fit # 40 of 200
##
## Round # 5 of 20
## CV Fit # 41 of 200
## CV Fit # 42 of 200
## CV Fit # 43 of 200
## CV Fit # 44 of 200
## CV Fit # 45 of 200
## CV Fit # 46 of 200
## CV Fit # 47 of 200
## CV Fit # 48 of 200
## CV Fit # 49 of 200
## CV Fit # 50 of 200
##
## Round # 6 of 20
## CV Fit # 51 of 200
## CV Fit # 52 of 200
## CV Fit # 53 of 200
## CV Fit # 54 of 200
## CV Fit # 55 of 200
## CV Fit # 56 of 200
## CV Fit # 57 of 200
## CV Fit # 58 of 200
## CV Fit # 59 of 200
## CV Fit # 60 of 200
##
## Round # 7 of 20
## CV Fit # 61 of 200
## CV Fit # 62 of 200
## CV Fit # 63 of 200
## CV Fit # 64 of 200
## CV Fit # 65 of 200
## CV Fit # 66 of 200
## CV Fit # 67 of 200
## CV Fit # 68 of 200
## CV Fit # 69 of 200
## CV Fit # 70 of 200
##
## Round # 8 of 20
## CV Fit # 71 of 200
## CV Fit # 72 of 200
## CV Fit # 73 of 200
## CV Fit # 74 of 200
## CV Fit # 75 of 200
## CV Fit # 76 of 200
## CV Fit # 77 of 200
## CV Fit # 78 of 200
## CV Fit # 79 of 200
## CV Fit # 80 of 200
##
## Round # 9 of 20
## CV Fit # 81 of 200
## CV Fit # 82 of 200
## CV Fit # 83 of 200
## CV Fit # 84 of 200
## CV Fit # 85 of 200
## CV Fit # 86 of 200
## CV Fit # 87 of 200
## CV Fit # 88 of 200
## CV Fit # 89 of 200
## CV Fit # 90 of 200
##
## Round # 10 of 20
## CV Fit # 91 of 200
## CV Fit # 92 of 200
## CV Fit # 93 of 200
## CV Fit # 94 of 200
## CV Fit # 95 of 200
## CV Fit # 96 of 200
## CV Fit # 97 of 200
## CV Fit # 98 of 200
## CV Fit # 99 of 200
## CV Fit # 100 of 200
##
## Round # 11 of 20
## CV Fit # 101 of 200
## CV Fit # 102 of 200
## CV Fit # 103 of 200
## CV Fit # 104 of 200
## CV Fit # 105 of 200
## CV Fit # 106 of 200
## CV Fit # 107 of 200
## CV Fit # 108 of 200
## CV Fit # 109 of 200
## CV Fit # 110 of 200
##
## Round # 12 of 20
## CV Fit # 111 of 200
## CV Fit # 112 of 200
## CV Fit # 113 of 200
## CV Fit # 114 of 200
## CV Fit # 115 of 200
## CV Fit # 116 of 200
## CV Fit # 117 of 200
## CV Fit # 118 of 200
## CV Fit # 119 of 200
## CV Fit # 120 of 200
##
## Round # 13 of 20
## CV Fit # 121 of 200
## CV Fit # 122 of 200
## CV Fit # 123 of 200
## CV Fit # 124 of 200
## CV Fit # 125 of 200
## CV Fit # 126 of 200
## CV Fit # 127 of 200
## CV Fit # 128 of 200
## CV Fit # 129 of 200
## CV Fit # 130 of 200
##
## Round # 14 of 20
## CV Fit # 131 of 200
## CV Fit # 132 of 200
## CV Fit # 133 of 200
## CV Fit # 134 of 200
## CV Fit # 135 of 200
## CV Fit # 136 of 200
## CV Fit # 137 of 200
## CV Fit # 138 of 200
## CV Fit # 139 of 200
## CV Fit # 140 of 200
##
## Round # 15 of 20
## CV Fit # 141 of 200
## CV Fit # 142 of 200
## CV Fit # 143 of 200
## CV Fit # 144 of 200
## CV Fit # 145 of 200
## CV Fit # 146 of 200
## CV Fit # 147 of 200
## CV Fit # 148 of 200
## CV Fit # 149 of 200
## CV Fit # 150 of 200
##
## Round # 16 of 20
## CV Fit # 151 of 200
## CV Fit # 152 of 200
## CV Fit # 153 of 200
## CV Fit # 154 of 200
## CV Fit # 155 of 200
## CV Fit # 156 of 200
## CV Fit # 157 of 200
## CV Fit # 158 of 200
## CV Fit # 159 of 200
## CV Fit # 160 of 200
##
## Round # 17 of 20
## CV Fit # 161 of 200
## CV Fit # 162 of 200
## CV Fit # 163 of 200
## CV Fit # 164 of 200
## CV Fit # 165 of 200
## CV Fit # 166 of 200
## CV Fit # 167 of 200
## CV Fit # 168 of 200
## CV Fit # 169 of 200
## CV Fit # 170 of 200
##
## Round # 18 of 20
## CV Fit # 171 of 200
## CV Fit # 172 of 200
## CV Fit # 173 of 200
## CV Fit # 174 of 200
## CV Fit # 175 of 200
## CV Fit # 176 of 200
## CV Fit # 177 of 200
## CV Fit # 178 of 200
## CV Fit # 179 of 200
## CV Fit # 180 of 200
##
## Round # 19 of 20
## CV Fit # 181 of 200
## CV Fit # 182 of 200
## CV Fit # 183 of 200
## CV Fit # 184 of 200
## CV Fit # 185 of 200
## CV Fit # 186 of 200
## CV Fit # 187 of 200
## CV Fit # 188 of 200
## CV Fit # 189 of 200
## CV Fit # 190 of 200
##
## Round # 20 of 20
## CV Fit # 191 of 200
## CV Fit # 192 of 200
## CV Fit # 193 of 200
## CV Fit # 194 of 200
## CV Fit # 195 of 200
## CV Fit # 196 of 200
## CV Fit # 197 of 200
## CV Fit # 198 of 200
## CV Fit # 199 of 200
## CV Fit # 200 of 200
#print the results
results$stat
## R2 RMSE
## 0.2836607 2101.8948118
results$stat.se
## R2 RMSE
## 0.01721069 61.72866697