Ben,

It would be easier to respond if you provided a self-contained example,
using data from help files. Anyway, I think the problem may be that rather
than:

p <- predict(predictors,m1)

you should do

p <- predict(predictors, m1, type='response')

see  ?predict.glm


As for the second problem, it should work if you do:

m1 = glm(pb ~ bio1 , data=sdmdata,family=binomial(link="logit"))
p <- predict(predictors, m1)
# or
p <- predict(predictors, m1[[1:2]])

# but not
p <- predict(predictors, m1[[1]])
# I shall fix that.

Robert



On Tue, Apr 24, 2012 at 2:14 PM, Ben Weinstein
<benweinstein2010@gmail.com>wrote:

> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

