Biasfile with maxent in dismo

2,456 views
Skip to first unread message

Julie

unread,
Mar 13, 2013, 4:55:09 PM3/13/13
to max...@googlegroups.com
Hi All,

Does anyone know how to incorporate a biasfile into a maxent run set up from the R package dismo?

Or is it even possible to run dismo's maxent command with a bias file?

Here's what I've tried:

mybias<-raster(file.choose())  # load bias grid of same extent and resolution as raster layers

## Attempt 1
test1<-maxent(rasters,localities,removeDuplicates=TRUE, args="biasfile=mybias")

# Result
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/var/folders/rm/kftt7_jj5h70d5kgypw6njwr0000gn/T/R_raster_tmp/maxent/7322841707/species.lambdas': No such file or directory

## Attempt 2
test2<-maxent(rasters,localities,removeDuplicates=TRUE, args="biasfile=/Users/Documents/mybias.asc") # use path name instead

# Result
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/var/folders/rm/kftt7_jj5h70d5kgypw6njwr0000gn/T/R_raster_tmp/maxent/02810774444/species.lambdas': No such file or directory


## Attempt 3

test4<-maxent(rasters,localities,removeDuplicates=TRUE, biasfile=mybias)

# This runs but the bias file seems to be ignored. That is, the bias file isn't listed as a parameter in the html file of the results (when running maxent directly the output html file mentions the bias file under the "Raw data output and control parameters" section)

Thanks!

Julie


Maxent Newbie

unread,
Mar 14, 2013, 7:17:34 AM3/14/13
to max...@googlegroups.com
Hello Julie,

Some quick ideas, although I've got no idea if they solve your problem:

1. Try to create models from the Maxent GUI with your data. Is the bias file correctly included in the models?

2. For your ## Attempt 2: Try to provide the full path to your bias raster file (like "c://users//document//...), instead of a relative path. 

Also, you could first try to create a working batch file to run Maxent from the command line. If this works, you could run Maxent from within R with the "system" command. 

Good luck!

Angela P. Cuervo-Robayo

unread,
Mar 14, 2013, 10:36:38 AM3/14/13
to max...@googlegroups.com
Hi Julie.

Yes you can. 

If you creat your own background sample from a target group (Birds, Mammals, or the group that you are working with), you can incorporated it instead of creating a random sample of the background. 

Best regards.


2013/3/14 Maxent Newbie <sxmvtebioe...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Maxent" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maxent+un...@googlegroups.com.
To post to this group, send email to max...@googlegroups.com.
Visit this group at http://groups.google.com/group/maxent?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
M. en C. Angela P. Cuervo-Robayo
Estudiante de Doctorado
Laboratorio de Biología Evolutiva
Universidad Autónoma del Estado de México
México

John Baumgartner

unread,
Mar 14, 2013, 8:05:24 PM3/14/13
to maxent

I haven't tried using bias grids with dismo, so can't answer your question, but one solution is to sample your own background, e.g. with:

bg <- xyFromCell(xbias, sample(ncell(xbias), 10000, prob=values(xbias)))

Where xbias is your bias raster object. If your enviro grids have NAs, then you probably want to prevent those cells from being sampled, e.g.

bg <- xyFromCell(xbias, sample(which(!is.na(values(xbias))), 10000, prob=values(xbias)[!is.na(values(xbias))]))

Untested and typing this on my phone with arg names from memory, so might not be quite right, but hopefully you get the gist ;)

You can then extract predictor values at the points and provide data to the maxent function as swd. Benefit of this approach is that maxent doesn't need to spend time sampling the background every time you run the model.


Laurens Geffert

unread,
Dec 3, 2013, 1:22:27 PM12/3/13
to max...@googlegroups.com
Hi Julie!
In case you are still looking for an answer on this:
I created biased pseudo-absences / background data using rasterToPoints and a subsequent sample(points, prob="bias").
Once you got your biased points you can pass them on to the maxent dismo function using "a":
maxent(x=predictors, p=records, a=points)
Hope this helps
Laurens

gomezcatalina

unread,
Jul 3, 2015, 12:52:03 PM7/3/15
to max...@googlegroups.com
Hello, 

I created a bias file (via Target Group Sampling) that I would like to include to run a model in MaxEnt. I am able to run it without any problems when using the bias option file directly on MaxEnt. However, I have not been successful to set up a MaxEnt run from the R package dismo using the exact same biasfile. Does the bias file need to be in a different format to run it through R? Thank you.


model <- maxent(x = predictors, p = response, removeDuplicates=TRUE, args = c("-P", "-J", biasfile=biasfile"))


Error: Bias grid cannot be used with SWD-format background

  

class       : RasterLayer 
dimensions  : 3014, 4033, 12155462  (nrow, ncol, ncell)
resolution  : 0.005785418, 0.005785418  (x, y)
extent      : -67.74363, -44.41104, 40.04867, 57.48592  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : D:\GIS\Data\MarMammData\bias_file.tif 
names       : bias_file 
values      : 1, 1  (min, max)
 
> predictors
class       : RasterStack 
dimensions  : 3014, 4033, 12155462, 2  (nrow, ncol, ncell, nlayers)
resolution  : 0.005785418, 0.005785418  (x, y)
extent      : -67.74363, -44.41104, 40.04867, 57.48592  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
names       : bath, slope 

Kevin Morelle

unread,
Nov 11, 2018, 7:03:14 PM11/11/18
to Maxent
Dear Catalina,

Was wondering whether you ever found a solution to your issue...since I'm facing similar one.
Thanks for your feedback,

Best 

Kevin

Matthew Nelsen

unread,
Dec 5, 2018, 7:16:42 PM12/5/18
to Maxent
Hi Everyone,

so if I understand correctly, there is no way to directly introduce a bias layer (in raster format) as an argument (ie. args="biasfile=bias")?  And bias should instead be accounted for in the bg argument?  Thanks much for any help.

-Matt.
Reply all
Reply to author
Forward
0 new messages