I have a random forests model with which I am trying to predict species presence or absence.
This is my code:
#read in dataframe containing observations of species presence/absence & predictor variables
mydata <- read.csv('mydata.csv')
#fit random forests model
fitmodelA <- randomForest(SPECIESA ~ var1 + var2 + var3 + var4 + var5 +var6 + var7 + var8 +
var9 + var10, data=mydata, mytry=3, ntrees=500, replace=T, importance=T, keep.forest=T)
#predict to new data
predictmodelA <- predict(fitmodelA, newdata, type="prob")
# save as raster image
writeRaster(predictmodelA,"predictSPECIESA.tif")
Apparently I should get back a matrix that has the probability for both classes, i.e., in two columns. Do I understand correctly that it is also possible to add the "index" argument to predict only one class?
With my code the way it is, my output raster produced one layer with probabilities 0 to 1, but no other attributes – what class is this predicting? I am more interested that my map show predictions of presence rather than absence. Probably a simple solution to this...? Thanks!