[R-sig-Geo] rare events logistic regression with ASCII files
Roger Bivand
Roger.Bivand at nhh.no
Wed Mar 21 11:12:24 CET 2012
On Wed, 21 Mar 2012, Robert Pazur wrote:
> Dear all,
>
> i would like to perform rare events logistic regression with ASCII Grid
> files.
> For this purpose selected the *relogit* function from Zelig package.
>
> I imported data into the R>
>
> library(maptools)
> landcover <- data.frame(readAsciiGrid("
> http://www.geography.sav.sk/personal/pazur/data/ab.asc"))
> temperature <- data.frame(readAsciiGrid("
> http://www.geography.sav.sk/personal/pazur/data/tem.asc"))
> precipitation <- data.frame(readAsciiGrid("
> http://www.geography.sav.sk/personal/pazur/data/zr.asc"))
Your problem is not reading the documentation: ?readAsciiGrid says that it
returns a SpatialGridDataFrame. You cannot use data.frame() to coerce this
object to a data frame with just the data, as it takes care to return the
coordinates as well. Isn't it simpler to do:
library(maptools)
site <- "http://www.geography.sav.sk/personal/pazur/data/"
landcover <- readAsciiGrid(paste(site, "ab.asc", sep=""))
temperature <- readAsciiGrid(paste(site, "tem.asc", sep=""))
precipitation <- readAsciiGrid(paste(site, "zr.asc", sep=""))
SGDF <- cbind(landcover, temperature, precipitation)
summary(SGDF)
form <- formula(ab.asc ~ tem.asc + zr.asc)
l.out <- glm(form, data=SGDF, family=binomial(link = "logit"))
summary(l.out)
SGDF$lfit <- fitted(l.out)
library(Zelig)
z.out <- zelig(form, data=SGDF, model="relogit")
summary(z.out)
SGDF$zfit <- c(fitted(z.out))
spplot(SGDF, c("lfit", "zfit"), col.regions=bpy.colors(20))
because the SpatialGridDataFrame object behaves just like a data.frame?
Hope this clarifies,
Roger
>
> But it seems that this package (Zelig) cant handle spatial data. Is there
> some straight way for transformation?
>
> Thanks in advance,
> Kind regards,
>
> Robert Pazur
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list