I am trying to compare the outputs of species distribution models. My current code uses the following function to calculate TSS scores.
TSS_Score<-function(TrueBinary, Raster) {
Raster[]<-as.numeric(Raster[] > 0.5)
ConfusionMatrix<-crosstab(TrueBinary,Raster)
a<-ConfusionMatrix[2,2]
b<-ConfusionMatrix[2,1]
c<-ConfusionMatrix[1,2]
d<-ConfusionMatrix[1,1]
Sensitivity<-a/(a+c)
Specificity<-d/(b+d)
TSS<-Sensitivity+Specificity-1
return(TSS)
}
This code works but I need a raster as the model output for it to work. I have run a ppm
model from spatstat
and then used the predict.ppm
function. However the output of predict.ppm
is an image
class.
Is there anyway to get a Raster as a predict output?
Or to convert the image into a raster?
EDIT: Here is the code for my ppm model. The covariates are images files as the function doesn't seem to take rasters?
PPMmodel<-ppm(PointsPPP, ~slope, covariates = list(slope =
AMtemp,MDRtemp,Isotherm,AMprecip,SeasonPrecip, TreeCover50))
predictPPM<-predict(PPMmodel)
predictPPM
real-valued pixel image
128 x 128 pixel array (ny, nx)
enclosing rectangle: [92.192, 141.01] x [-10.999, 28.549] units
as.matrix
and get the coordinates from the object too, which is sufficient to create raster classes.