Simple Use of BayesMaxEnt

library(BayesMaxEnt)
library(disdat)
library(bayesplot)

Set up the data

CAN <- disData("CAN")
EnvPO <- c("alt", "asp2", "ontprec", "ontprec4", "ontprecsd", "ontslp", 
           "onttemp", "onttempsd", "onttmin4", "ontveg", "watdist")
Species <- "can02"

SpData <- rbind(CAN$po[CAN$po$spid==Species,c("occ", EnvPO)], CAN$bg[,c("occ", EnvPO)])
SpData[,EnvPO] <- apply(SpData[,EnvPO], 2, scale) # scale covariates

Because Nimble wants the data in its own format, we have a function to do the conversion. here we just use linear features, rather than everything.

ToNimble <- SetUpMaxEnt(p=SpData$occ, data=SpData[,EnvPO], 
                        regmult = 1, lambda=0.1, classes="l")

Unfortunately when we run the code below we currently get an an error (it works when copying and pasting the code, but not when rendering the vignette).

output <- FitMaxEnt(maxdat=ToNimble, parallel = FALSE, adaptInterval=50,
                    nchains=2, nburnin = 50, niter=150, thin=1)
#> Error:
#> ! In sizeAssignAfterRecursing: 'rbern_vec' is not available or its output type is unknown. This may occur if a user-defined function name is the same as the name of a function in a package that `nimble` uses.
#>  This occurred for: eigenBlock(model_y,1:11477) <<- rbern_vec(=1,p=model_Prob[1:11477],wt=model_W[1:11477])
#>  This was part of the call:  {
#>   eigenBlock(model_y,1:11477) <<- rbern_vec(=1,p=model_Prob[1:11477],wt=model_W[1:11477])
#> }

With 100 iterations we cannot see much, and at the moment this code is parked until the error above is sorted out.

mcmc_trace(output, pars = c("alpha", "beta[1]"))