[R-sig-Geo] new function predict, package raster
Robert J. Hijmans
r.hijmans at gmail.com
Thu Dec 2 19:14:02 CET 2010
Isabelle,
If you use a factor that is represented by numbers on a grid you can
just fit the model (with the factor variable as factor), and the
predict function will then make a factor from the predictor layers
(i.e. there is nothing else you need to do). Where this can go wrong
is if you have factor levels on your raster that were not in the data
used to fit the model. You can get something like:
Error in model.frame.default(Terms, newdata, na.action = na.action,
xlev = object$xlevels) :
factor 'x' has new level(s): 2, 3, 4, 5,
Which means that you first need to remove those levels (set to NA)
from your predictor raster. (I will try to automate that problem away,
in raster::predict, eventually)
The argument "const" is for factor type variables for which you do not
have spatial data. Hence they could be considered 'constant' in some
contexts. For example, with fish observation data you might have a
model that predicts abundance from a number of variables including the
method used to catch the fish. Say a factor variable "method" with
levels "A" or "B". You can then do something like
method = factor("A")
predict(raster, model, const=method)
Robert
On Thu, Dec 2, 2010 at 9:02 AM, isabelle boulangeat
<isabelle.boulangeat at gmail.com> wrote:
> Hello,
>
> I am trying to use the recently updated function "predict" from the package
> raster. I would like to use the field "const", as one of my variable is
> categorial.
> I have an error message but I can't find where is the problem.
>
> Error message : Erreur dans `[.data.frame`(blockvals, , f[i]) : undefined
> columns selected
>
> code : Pred_fac <- predict(rasStack, model=model_fac, predict=predict.glm,
> progress='text', const=factorDF)
>
> rasStack is a RasterStack and contains only one layer with one explicative
> variable. the layer name is the same as in the model.
> factorDF is a data.frame and contains only one column with one explicative
> variable. the column name is the same as in the model.
>
> the dimensions are the same : the number of rows in the data frame
> correspond to the number of cells in the raster.
>
> Does someone succeed to use this function with the new field "const" ?
>
> Thanks for help,
>
> Cheers,
>
> Isabelle.
>
> --
> Isabelle Boulangeat, PhD student
> Ecosystem dynamics and plant traits
>
> Bureau 203, +33 (0) 476 635 733
>
> Laboratoire d'écologie Alpine (LECA)
> Grenoble, France
> lab' s website : http://www-leca.ujf-grenoble.fr/
> my website : http://j.boulangeat.free.fr/
>
> [[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
>
>
More information about the R-sig-Geo
mailing list