[R-sig-Geo] Extrapolating SDM with random forest to past climatic scenarios

Robert J. Hijmans r.hijmans at gmail.com
Wed May 1 18:43:02 CEST 2013


Mariana,

predict is the function to use. Please provide the exact error message
you are getting, preceded by the lines of the script that caused it.
Also include the result of  traceback( ) when run just after the error
occurs, and, as always, your sessionInfo(). I am guessing that the
problem is that the variable names do not match those of your model.
See names(predictors_6k) and change them if necessary.

By the way, it is odd (to put it mildly) to use elevation in a model
of climate change effects. And you probably meant to do filename =
"6k_results.asc" (but using ascii files is not recommended for their
sluggish performance).

Robert

On Tue, Apr 30, 2013 at 8:43 PM, Mariana Vasconcellos
<marianamv at utexas.edu> wrote:
> Hi all,
> I am trying to extrapolate my species distribution model generated using randomForest to past and future climate scenarios. Using the predict function is not working for a raster stack that was NOT used to fit the model. It gives me an error message saying that my raster stack and my variables are not of the same size. I think the predict function might not be the best way to extrapolate my model, but I don't know which function I would use for extrapolating my model in time.
>
> My script looks more or less like this:
>
> # fitting Random Forest SDM model with current climate data
>
> files <- list.files(path="./WorldClim/0k", pattern='asc', full.names=TRUE)
> predictors <-stack(files)
> pres <- read.csv('pres_H_lundii.csv')
> backgr <- randomPoints(predictors, 500)
> presclim <- extract(predictors, pres)
> absclim <- extract(predictors, backgr)
> presabs <- c(rep(1, nrow(presclim)), rep(0, nrow(absclim)))
> sdm_data <- data.frame(cbind(presabs, rbind(presclim, absclim)))
> model <- factor(presabs) ~ alt + bio3 + bio4 + bio7 + bio10 + bio11 + bio14 + bio15 + bio16 + bio17
> RF <- randomForest(model, data=sdm_data)
>
> # extrapolating to past scenario 6kya
>
> files_6k <- list.files(path="./WorldClim/6k", pattern='asc', full.names=TRUE)
> predictors_6k <-stack(files_6k)
> pred <- predict(predictors_6k, RF, type="response", filename = "0k_results.asc", format = "ascii",
> + progress='window', overwrite=TRUE)
>
>
> Any help on this would be much appreciated!
> Thanks,
>
> ----------------------
> Mariana Vasconcellos
> The University of Texas at Austin
>
>
>
>
>         [[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