Hello,

I am using Boosted Regression Tree from the dismo package to model
abundance of some species and I have some doubts and problems. So any help
to solve them is welcome.

1) How Does the function "step.gbm" with argument "n.folds" breaks the
folds with continuous data in the response variable?

2) I did not find a way to get the informations about the folds of the
cross-validation. I would like the information from each fold prediction
and its respective test data (i.e the data that were not used to fit the
model) to evaluate the folds with other statistics, like Root-mean-square
deviation (RMSD), R², etc. The fellow example with the dismo data, return
"0" when I try get the object "cv.folds" from the results.

library(dismo)
data(Anguilla_train)
angaus.tc5.lr005 <- gbm.step(data=Anguilla_train, gbm.x = 3:13, gbm.y = 2,
family = "bernoulli", tree.complexity = 5, learning.rate = 0.005,
bag.fraction = 0.5 , keep.fold.models = TRUE, keep.fold.vector = TRUE,
keep.fold.fit = TRUE)
names(angaus.tc5.lr005)
angaus.tc5.lr005$cv.folds # this return "0". Why Does it happen?

3) How can I calculate the coefficient  of  determination (R²) based in the
proportion of variance explained by the model? How can I calculate the R²
to each fold and each part of the fold (i.e train and test data) and in the
final model (see question 4)? What is the apropriate statistic to measure
the goodness of fit in BRT with continuous data?
I know the R² does not make sense with binomial response, but if I have a
continuos response it make sense in BRT? Are the bellow procedure correct?
What is the correct way to measure the R² from BRT model?

Example just for show the procedure:

res.dev<-sum((angaus.tc5.lr005$residuals)^2)  #Are the residuals in the
same order of the response variable?
tot.dev<-sum(((Anguilla_train[,2])-(mean(Anguilla_train[,2])))^2)
R.sqrd1<-1-(res.dev/tot.dev)
R.sqrd1

Or

vari<-var(Anguilla_train[,2])
mse<-mean((angaus.tc5.lr005$residuals)^2)
R.sqrd2<-(vari-mse)/vari
R.sqrd2

# It is equal to the "mean residual deviance = 0.489"  from the model
summary showed in the R console
mean((angaus.tc5.lr005$residuals)^2)
# Why is it not equal to the "mean total deviance = 1.006" from the model
summary showed in the R console?
mean(((Anguilla_train[,2])-(mean(Anguilla_train[,2])))^2) #it is
equal 0.161196

4) How the dismo select the final model after the cross-validation? What
model is used in the "predict" (from {raster}) or "predict.gbm" (from
{gbm}) functions?
If I put the argument "n.trees=angaus.tc5.lr005$gbm.call$best.trees" Does
the predict use the final model?

Example:
Method=factor('electric', levels = levels(Anguilla_train$Method))
add=data.frame(Method)
p = predict(Anguilla_grids, angaus.tc5.lr005, const=add,
n.trees=angaus.tc5.lr005$gbm.call$best.trees, type="response")
p = mask(p, raster(Anguilla_grids, 1))
plot(p, main='Angaus - BRT prediction')

Thank you in advance!
Frederico

	[[alternative HTML version deleted]]

