variable dll not found in modelValues

25 views
Skip to first unread message

Samuel Bisilki

unread,
Sep 8, 2022, 3:40:06 PM9/8/22
to nimble-users

The error is variable dll not found in modelValues. I have attached both the log and my code below:

 

Log.

Show in New Window

 

nc.sds> if (requireNamespace("sf", quietly = TRUE)) {

nc.sds+   if (requireNamespace("spdep", quietly = TRUE)) {

nc.sds+     library(spdep)

nc.sds+     nc.sids <- sf::st_read(system.file("shapes/sids.shp", package="spData")[1])

nc.sds+     nc.sids <- as(nc.sids, "Spatial")

nc.sds+     proj4string(nc.sids) <- CRS("+proj=longlat +ellps=clrk66")

nc.sds+     row.names(nc.sids) <- as.character(nc.sids$FIPS)

nc.sds+     rn <- row.names(nc.sids)

nc.sds+     ncCC89_nb <- read.gal(system.file("weights/ncCC89.gal", package="spData")[1],

nc.sds+                           region.id=rn)

nc.sds+     ncCR85_nb <- read.gal(system.file("weights/ncCR85.gal", package="spData")[1],

nc.sds+                           region.id=rn)

nc.sds+                          

nc.sds+     plot(nc.sids, border="grey")

nc.sds+     plot(ncCR85_nb, coordinates(nc.sids), add=TRUE, col="blue")

nc.sds+     plot(nc.sids, border="grey")

nc.sds+     plot(ncCC89_nb, coordinates(nc.sids), add=TRUE, col="blue")

nc.sds+   }

nc.sds+ }

Reading layer `sids' from data source `C:\Users\governors\AppData\Local\Programs\R\R-4.2.1\library\spData\shapes\sids.shp' using driver `ESRI Shapefile'

Simple feature collection with 100 features and 22 fields

Geometry type: MULTIPOLYGON

Dimension:     XY

Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965

CRS:           NA

OGR data source with driver: ESRI Shapefile

Source: "C:\Users\governors\AppData\Local\Programs\R\R-4.2.1\library\spData\shapes\sids.shp", layer: "sids"

with 100 features

It has 22 fields

R Console

 

 

 

Show in New Window

 

Show in New Window

Defining model

Building model

Setting data and initial values

Running calculate on model

  [Note] Any error reports that follow may simply reflect missing values in model variables.

Checking model sizes and dimensions

Compiling

  [Note] This may take a minute.

  [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.

Reference class 'Cnc.sids.co_MID_2' [package ".GlobalEnv"] with 44 fields

 $ modelDef                                           : NULL

 $ nodes                                              :<environment: 0x000002506dd92ef8>

 $ vars                                               :List of 10

  ..$ lifted_d1_over_sqrt_oPtau_cP                  : num(0)

  ..$ theta                                         : int 100

  ..$ lifted_n_oBi_cB_times_exp_oPtheta_oBi_cB_cP_L3: num 100

  ..$ y                                             : int 100

  ..$ mu                                            : num(0)

  ..$ tau                                           : num(0)

  ..$ logProb_theta                                 : num 100

  ..$ logProb_y                                     : num 100

  ..$ logProb_mu                                    : num(0)

  ..$ logProb_tau                                   : num(0)

 $ graph                                              : NULL

 $ defaultModelValues                                 :

 Error in object[[ch]] : variable dll not found in modelValues

 

 

And this is my code:

 

 

nc.sids.code = nimbleCode(

  {

    for (i in 1:k){

      theta[i] ~ dnorm(mu, tau)

      y[i] ~ dpois(n[i] *exp(theta[i]))

    }

   

    #prior for hyperparameters

   

    mu ~ dnorm(-6, 0.001)

    tau ~ dgamma(1, 0.001)

  }

)

 

k= 100

n= nc.sids$BIR79

y= nc.sids$SID79

 

nc.sids.Consts = list(k = k, n = n)

nc.sids.Data= list(y = y)

nc.sids.Inits = list(mu = -2, tau = 12, theta = rep(0.002, k))

 

nc.sids.Model = nimbleModel( nc.sids.code,

                             data= nc.sids.Data,

                             constants = nc.sids.Consts,

                             inits= nc.sids.Inits)

 

 

compile.nc.sids.Model = compileNimble(nc.sids.Model)

str(compile.nc.sids.Model)

 

 

nc.sids.conf = configureMCMC(nc.sids.Model, print= T)

nc.sids.conf$addMonitors(c("mu", "tau", "theta"))

 

 

nc.sids.MCMC = buildMCMC(nc.sids.conf)

compile.nc.sids.MCMC = compileNimble(nc.sids.MCMC, project= nc.sids.Model)

 

 

niter = 55000

nburn = 5000

 

set.seed(1)

 

inits = list(mu = -2, tau =12, theta = rep(0.002, k))

start.time = proc.time()

samples = runMCMC( compile.nc.sids.MCMC, niter = niter, nburnin = nburn,

                   inits = inits, nchains = 1, samplesAsCodaMCMC = TRUE)

 

stop.time = proc.time()

time.elapsed = stop.time - start.time

 

print(time.elapsed)

Daniel Turek

unread,
Sep 8, 2022, 4:17:30 PM9/8/22
to Samuel Bisilki, nimble-users
Samuel, it looks like the error is coming from your use of the str() function on the compiled model object:

str(compile.nc.sids.Model)

That's what's causing the error.  It turns out nimble's compiled objects (which are wrappers to invoke a call to compiled C++ code) do not play nicely with str(), and that's something we can address in a future release.  But for now,

(1) You can get additional information about the model object by querying the model using the model API functions, such as:

nc.sids.Model$initializeInfo()
nc.sids.Model$getNodeNames()
nc.sids.Model$getDependencies("tau")

(2) If you omit the call to str(), then the rest of your code seems to execute without any problems.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/47125bc6-64ed-42cf-98ef-15fcc1d9af46n%40googlegroups.com.

Samuel Bisilki

unread,
Sep 8, 2022, 8:16:43 PM9/8/22
to nimble-users
Hello Daniel,

I'm able to run the code and generate maps when I comment out the str(compile.nc.sids.Model. However,  when I knit my work in rmarkdown I get the error I have attached to this email, which seems to suggest that argument is missing, with no default.

I appreciate your help.

Thanks.
error when knitting in rmarkdown.PNG

Daniel Turek

unread,
Sep 8, 2022, 9:14:17 PM9/8/22
to Samuel Bisilki, nimble-users
I'm sorry, Samuel, it's impossible to diagnose the problem from the error message you sent.  One approach to figuring it out would be progressively commenting out code in your Rmarkdown file, until it successfully knits, and then you can identify the offending line(s) of code.


Reply all
Reply to author
Forward
0 new messages