Skip to content

scoping issue with user-defined distributions and nimbleMCMC #1541

@paciorek

Description

@paciorek

This must have worked at one point as it involves a manual example. Probably caused by me making some lookup/scoping more strict at some point. I can take a look before next release.

dmyexp <- nimbleFunction(
    run = function(x = double(0), rate = double(0, default = 1), 
        log = integer(0, default = 0)) {
        returnType(double(0))
        logProb <- log(rate) - x*rate
        if(log) return(logProb)
        else return(exp(logProb)) 
    })

code <- nimbleCode({
    y ~ dmyexp(x)

    # priors
    x ~ dunif(0,1)
  })

  constants <- list()
  data <- list(y=0)
  initial_values <- list(x=0.5)

  nimbleMCMC(code=code,
                         constants=constants,
                         data=data,
                         inits=initial_values)
Error: In sizeAssignAfterRecursing: 'rmyexp' 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: model_y[1] <<- rmyexp(=1,rate=model_x[1])
 This was part of the call:  {
  model_y[1] <<- rmyexp(=1,rate=model_x[1])
}
Execution halted

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions