[R-sig-Geo] dismo predict and glm binomial error

Ben Weinstein benweinstein2010 at gmail.com
Tue Apr 24 23:14:13 CEST 2012


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)))
#Create the presence absence matrix.
> sdmdata <- data.frame(cbind(pb, rbind(presvals, absvals)))
> head(sdmdata)
 pb bio1 bio10 bio11 bio12 bio13 bio14 bio15 bio16 bio17 bio18 bio19 bio2
1  1  237   240   232  1774   250    80    34   603   270   418   529   89
2  1  237   240   232  1774   250    80    34   603   270   418   529   89
3  1  229   231   227  1433   288     7    90   806    34    96   137  114
4  1  195   196   193  1351   301     3    98   817    16    40   799  122
5  1  222   226   217  1325   311     3   103   838    17   838    43  123
6  1  213   213   210  1286   237     7    86   704    37    37   704  110

>#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


-- 
Ben Weinstein
Graduate Student
Ecology and Evolution
Stony Brook University

http://life.bio.sunysb.edu/~bweinste/index.html



More information about the R-sig-Geo mailing list