Hello all,
I'm developing ecological niche models and i'd like to use a
simple glm framework, following the vignette published for the package
"dismo".
Everything works fine, except the predict function creates cell values
that vary from -5 to 1, which is impossible for a binomial variable.
Should the predict function not be used for binomial glm?
#Extract values of the bioclimatic variables to my point localities, loc
presvals <- extract(predictors,loc)
backgr <- randomPoints(predictors, 800)
absvals <- extract(predictors, backgr)
pb <- c(rep(1, nrow(presvals)), rep(0, nrow(absvals)))
#Fit generalized linear model
m1 = glm(pb ~ bio1 + bio2 + bio12 + bio15 , data=sdmdata,family="binomial")
#Check fitted values - they should be from 0-1
range(m1$fitted)
[1] 0.009706557 0.553194264
#Use the predict function to fit the bbox of the predictor variables.
p <- predict(predictors,m1)
#Error! bizarre range of data.
cellStats(p,range)
? ? ? ? ? [,1]
[1,] -5.0485812
[2,] ?0.5138158
I suspect the error has to do with that although the presence/absence
datamatrix contains all bioclimatic variables, i only choose ?4
predictors to use.
I tried to follow this idea by fitting just one bioclimatic variable,
and using only that rasterlayer in the predict function as shown
below.
m1 = glm(pb ~ bio1 , data=sdmdata,family=binomial(link="logit"))
range(m1$fitted)
p <- predict(predictors[[1]],m1)
cellStats(p,range)
however i recieve the error
Error in eval(expr, envir, enclos) : object 'bio1' not found
I appreciate all help,
Best,
Ben Weinstein
Thanks for your help
Ben Weinstein
--
Ben Weinstein
Graduate Student
Ecology and Evolution
Stony Brook University
http://life.bio.sunysb.edu/~bweinste/index.html