[GRASS-user] grass/stats mapping/prediction question

andrew haywood ahaywood3 at gmail.com
Tue Dec 18 21:22:49 EST 2007


Dear List,

I am having some problems analysing some ecoligical models in grass using
the spgrass package through R.

I have 130 plot locations where i have observed presence/absence  of a
species.
I have followed a similar framework to the BUGSITE modelling example from
Markus's 2003 grass gis handouts (Grass 5)
I have no problems constructing the model based on the 130 plots and the
environmental layers from grass.

However, I am having problems bringing all the maps through into R so I can
make a prediction map.
The region isnt too large 1600 by 800 cells at 10m resolution
I can bring all the environmental layers through to R using readRAST6()
which doesnt take too much time at all.

However i assume I must convert the spatial grid objects into dataframes to
apply the predicted model function.
So I then coerce them into dataframes using as.dataframe (this takes ages)
I then merge all the dataframes into a single dataframe. (this takes ages)

I then apply the model predict to the new data frame.

I am unsure how to then move the 'outmap' back across to grass.
How can i convert the df to a spatial grid object.

Im thinking i must be doing something wrong. As it quite quick to pull
through the layers . But seems to take quite a lot of processing to get the
layers into a datframe appropppriate for applying the predictions.

Any help would be greatly appreciated.

Andy


#pull through environmental layers
#FAST
anmax <- readRAST6("anmax", ignore.stderr=TRUE)
anmin <- readRAST6("anmin", ignore.stderr=TRUE)
aspect <- readRAST6("aspect", ignore.stderr=TRUE)
dem10_lidar <- readRAST6("dem10_lidar", ignore.stderr=TRUE)

#coerce to dataframe
#SLOW
mypred_anmaxDF<-as.data.frame(anmax)
mypred_anminDF<-as.data.frame(anmin)
mypred_aspectDF<-as.data.frame(aspect)
mypred_dem10_lidarDF<-as.data.frame(dem10_lidar)

#merge into single dataframe
#VERY SLOW
merge_tmp<-merge(mypred_anmaxDF,mypred_anminDF)
rm(mypred_anmaxDF,mypred_anminDF)
merge_tmp1<-merge(merge_tmp,mypred_aspectDF)
rm(merge_tmp,mypred_aspectDF)
mypredDF<-merge(merge_tmp1,mypred_dem10_lidarDF)

#apply model
outmap   <- predict(tree,newdata=mypredDF, type="class")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20071219/8d44aa41/attachment.html


More information about the grass-user mailing list