[R-sig-eco] problem with Dismo package!

Robert J. Hijmans r.hijmans at gmail.com
Tue May 11 01:38:43 CEST 2010


Dear Liliana,

This error:

> # predict the maxent model to the predictor stack
> mep <- predict(me, predictors)
> Error in .local(object, ...) : missing layers (or wrong names)

occurs when all variables that were used to build the model are not
also available in the RasterStack (at least not under the same names)

#This needs to be TRUE
all(colnames(train) %in% layerNames(predictors))

colnames(train)
layerNames(predictors)
colnames(train) %in% layerNames(predictors)

If necessary, you can set the layerNames
layerNames(predictors) <- c(     )

Best,
Robert



On Mon, May 10, 2010 at 1:30 PM, Claudia liliana Ballesteros Mejia
<lailaliana78 at yahoo.com> wrote:
> Dear list,
>
> I'm using the dismo package from R-forge to model the distribution of a invasive sp of moth.
> I have to use the stack function with the 14 asci files that are my predictor variables, and this is the code.
> predictors <- stack(list.files("America", "*.asc$", full.names=TRUE))
> then when I ask for predictors it says:
> class       : RasterStack
> filename    :
> nlayers     : 14
> nrow        : 3426
> ncol        : 3671
> ncell       : 12576846
> projection  : NA
> min value   : NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> max value   : NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> xmin        : -179.1807
> xmax        : -26.22232
> ymin        : -59.5
> ymax        : 83.25
> xres        : 0.04166667
> yres        : 0.04166667
>
> But then when I try to make the prediction with any of the methods available (maxent, randomForest or boost regression trees) it gives an error
>
> Error in .local(object, ...) : missing layers (or wrong names)
>
> even with the example code.. it says the same. I have checked all the names, in the folder and in the file and all the names are correctly spelled, and they are all in the same folder, same order.
>
>
> This is the code I'm using
>
> Agcingu <- read.csv("swd/Ag_cinswd.csv")
> background <- read.csv("swd/background_swd.csv")
> vars <- names(Agcingu)[4:17]
> head(vars)
> vars
>
> # combine presence and background data
> train <- rbind(Agcingu, background)[,vars]
> head(train)
>
> # vector indicating presence or absence
> p <- c(rep(1, nrow(Agcingu)), rep(0, nrow(background)))
>
> # fit maxent model
> me <- maxent(x=train, p=p)
>
> # make a stack of predictor rasters
> predictors <- stack(list.files("America", "*.asc$", full.names=TRUE))
> predictors
>
> # predict the maxent model to the predictor stack
> mep <- predict(me, predictors)
> Error in .local(object, ...) : missing layers (or wrong names)
>
> #brt data
> brttrain <- rbind(Agcingu, backg)[,vars ]
> p <- c(rep(1, nrow(Agcingu)), rep(0, nrow(backg)))
> #makes the sum of the weight of the presence points equal the sum f the weights of the background points
> weights <- c(rep(1, nrow(Agcingu)), rep(nrow(Agcingu)/nrow(backg), nrow(backg)))
>
> # make brt model
> brt <- gbm.step(cbind(p,brttrain), 1:length(train)+1, 1, site.weights=weights)
> brtp <- predict(predictors, brt, n.trees=brt$n.trees, progress='text', type="response")
> here it stops at 2% and gives
> In addition: Warning message:
> closing unused connection 3 (C:/DOCUME~1/balleste/LOCALS~1/Temp/R_raster_tmp/raster_tmp_83109427816.gri)
>
>
> Can anybody help me? Any idea to solve this problem will be very welcome and appreciated.
>
> Thanks a lot in advanced,
>
> Cheers,
>
> Liliana Ballesteros.
>
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>



More information about the R-sig-ecology mailing list