[R] Biomod model access

Sarah Goslee sarah.goslee at gmail.com
Wed Feb 12 23:24:12 CET 2014


Accessing BIOMOD2 model output is possible, but a bit convoluted.
Here's a whole chunk of code that creates a reproducible example; the
most important part is at the end.

I hope this is enough to let you get going.

Sarah

### First use a slightly modified version of the example from the help file
     # species occurrences
     DataSpecies <-
read.csv(system.file("external/species/mammals_table.csv",
package="biomod2"))
     # the name of studied species
     myRespName <- 'GuloGulo'

     # the presence/absences data for our species
     myResp <- as.numeric(DataSpecies[,myRespName])

     # the XY coordinates of species data
     myRespXY <- DataSpecies[,c("X_WGS84","Y_WGS84")]


     # Environmental variables extracted from BIOCLIM (bio_3, bio_4,
bio_7, bio_11 & bio_12)
     myExpl = stack( system.file( "external/bioclim/current/bio3.grd",
package="biomod2"),
                     system.file( "external/bioclim/current/bio4.grd",
package="biomod2"),
                     system.file( "external/bioclim/current/bio7.grd",
package="biomod2"),
                     system.file(
"external/bioclim/current/bio11.grd", package="biomod2"),
                     system.file(
"external/bioclim/current/bio12.grd", package="biomod2"))

     # 1. Formatting Data
     myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
                                          expl.var = myExpl,
                                          resp.xy = myRespXY,
                                          resp.name = myRespName)

     # 2. Defining Models Options using default options.
     myBiomodOption <- BIOMOD_ModelingOptions()

     # 3. Doing Modelisation

     myBiomodModelOut <- BIOMOD_Modeling( myBiomodData,
                                            models = c('SRE','RF', 'GAM'),
                                            models.options = myBiomodOption,
                                            NbRunEval=2,
                                            DataSplit=80,
                                            VarImport=0,
                                            models.eval.meth = c('ROC'),
                                            do.full.models=FALSE,
                                            modeling.id="test")

### assume we quit without saving the workspace, since everything is
on disk anyway
### q("no") ## commented out for your protection

### here's the access code

### come back later
### everything is stored in GuloGulo, and all thing are R objects
R
> library(biomod2)
# R objects can be imported with load()
R> load("GuloGulo/models/test/GuloGulo_AllData_RUN1_GAM")
R> ls()
[1] "GuloGulo_AllData_RUN1_GAM"
R> GuloGulo_AllData_RUN1_GAM
# various outputs deleted

## here's how to get the GAM itself
R> get_formal_model(GuloGulo_AllData_RUN1_GAM)

Family: binomial
Link function: logit

Formula:
GuloGulo ~ 1 + s(bio3, k = -1) + s(bio4, k = -1) + s(bio7, k = -1) +
    s(bio11, k = -1) + s(bio12, k = -1)
<environment: 0x9a5e918>

Estimated degrees of freedom:
3.04 6.51 6.07 5.78 5.08  total = 27.47

UBRE score: -0.6562

## and it can be summarized
R> summary(get_formal_model(GuloGulo_AllData_RUN1_GAM))

Family: binomial
Link function: logit

Formula:
GuloGulo ~ 1 + s(bio3, k = -1) + s(bio4, k = -1) + s(bio7, k = -1) +
    s(bio11, k = -1) + s(bio12, k = -1)
<environment: 0x9a5e918>

Parametric coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   -11.14       4.23   -2.63   0.0085

Approximate significance of smooth terms:
          edf Ref.df Chi.sq p-value
s(bio3)  3.04   3.74   15.9  0.0027
s(bio4)  6.51   6.98  151.1 < 2e-16
s(bio7)  6.07   6.77  107.6 < 2e-16
s(bio11) 5.78   6.46  130.5 < 2e-16
s(bio12) 5.08   6.06   59.2 7.3e-11

R-sq.(adj) =  0.738   Deviance explained = 72.2%
UBRE score = -0.65625  Scale est. = 1         n = 2488

On Wed, Feb 12, 2014 at 12:22 PM, Matthew Bayly <matt.j.bayly at gmail.com> wrote:
> I have been struggling with this same problem. I always have to re-run.
> PLEASE HELP!!
>
> I have however figured out the whole data-format issue & am now able to
> save grid files for use in other GIS programs after they are re-exported.
>
> On Thursday, August 15, 2013 1:32:31 AM UTC-7, Jenny Williams wrote:
>>
>> I am still trying to get my head around biomod2. I have run through the
>> tutorial a few times, which works really well in a linear format.
>>
>> But, I want to see the models and assess them at every part of the
>> process. So, I need to:
>>
>> 1: be able to re-access all the files from /.BIOMOD_DATA/ once R is closed
>> and all the file links are lost.
>> e.g myBiomodModelOut
>>
>> 2: call the summary parameters for the models e.g GLM, I can see the files
>> but not sure how to access them.
>> e.g
>> >myGLMs <- BIOMOD_LoadModels(myBiomodModelOut, models='GLM')
>> #just produces a list
>> >summary(myGLMs[1])
>>    Length     Class      Mode
>>    1 character character
>> #summary(GLM) doesn't work, but is the output that I am looking to find.
>>
>> 3. find the split datasets used for each of the iterations BIOMOD_Modeling
>> options; NbRunEval for DataSplit
>>
>> Any help or pointers in the right direction would be greatly appreciated.
>> FYI the vignette does not seem to work:
>> http://127.0.0.1:15505/library/biomod2/doc/index.html
>>
>>




More information about the R-help mailing list