FlexBayes library Help Files for bhpm() has a bug.

FlexBayes library Help Files for bhpm() has a bug.

book

Article ID: KB0082780

calendar_today

Updated On:

Products Versions
Spotfire S+ All supported versions

Description

There is a bug in the FlexBayes library Help Files.  If you run one of the examples from the bhpm() Help File:

##########################################
# Use bhpm to fit an overdispersed Poisson model to the
# pumps data

xi.prior = bayes.uniformShrinkage (0.5)
random.var.prior = bayes.invWishart( df = 3, scale = diag( c(1,1) ) )

pump.prior = bhpm.prior ( xi = xi.prior,
  random.var =  random.var.prior,
  common.glm = 2 )

# Specify the control parameters (burn-in length,
# etc.) and the initial values for the parameters.  
pump.sampler <- bhpm.sampler( nSamples=1000, nThin= 50,
  nChains = 1, nBurnin = 1000,
  init.point = "prior", update.cov = 0 )

pump.exposure <- ~ e
pump.random <- z ~ 1 + x

## call bhpm to fit a gamma-conjugate model
pump.bhpm <- bhpm( random.formula = pump.random,
  exposure.formula = pump.exposure, data = pumps,
  prior = pump.prior, sampler = pump.sampler,
  overdispersion = "gamma-conj" )

# check convergence
autocorr.plot(pump.bhpm)

# summarize the posterior distribution
summary(pump.bhpm)

##########################################

> pump.bhpm <- bhpm(random.formula = pump.random, exposure.formula = pump.exposure, data = pumps, prior = pump.prior,
        sampler = pump.sampler, overdispersion = "gamma-conj")
Problem in mcmc: argument burnin= not matched: mcmc(data = post.samples, thin = sampleFrequency, burnin = burnInLength)
Use traceback() to see the call stack

> traceback()
10: eval(action, sys.parent())
9: doErrorAction("Problem in mcmc: argument burnin= not matched: mcmc(data = post.samples, thin = sampleFrequency, burnin = burnInLength)",
8: mcmc(data = post.samples, thin = sampleFrequency, burnin = burnInLength)
7: fit.bayeshpm(n.groups, n.responses, dim.random, dim.fixed, dim.level2, exposure.in.model, response.names,
6: bhpm(random.formula = pump.random, exposure.formula = pump.exposure, data = pumps, prior = pump.prior, sampler =
5: eval(i, local)
4: source(auto.print = auto.print, exprs = substitute(exprs.literal))
3: script.run(exprs.literal = {
2: eval(expression(script.run(exprs.literal = {
1:
Message: Problem in mcmc: argument burnin= not matched: mcmc(data = post.samples, thin = sampleFrequency, burnin = burnInLength)

###########################################


 

Issue/Introduction

FlexBayes library Help Files for bhpm() has a bug.

Environment

Product: TIBCO Spotfire S+ Version: 8.2 OS: All supported Operating Systems

Resolution

The problem is coming from the Coda library being higher in the search path than flexBayes.  If you do a quick command to see where the mcmc() function is located at (this is the function causing the error message you are encountering), you can see that it exists in both Coda and flexBayes:

> find("mcmc")
[1] "flexbayes" "coda"

This means that it is finding the mcmc() function in the Coda library and using it instead of finding and using the mcmc() function in the flexBayes library.  To fix this issue, remove your Coda library and then run the code again.  For example:

> detach("coda")
> search()
[1] "D:\\Program Files\\Tibco\\splus81\\users\\rflodin"
[2] "finmetrics"                                      
[3] "robust"                                          
[4] "splus"                                            
[5] "stat"                                            
[6] "data"                                            
[7] "trellis"                                          
[8] "curl"                                            
[9] "nlme3"                                            
[10] "menu"                                            
[11] "sgui"                                            
[12] "MASS"                                            
[13] "pkgutils"                                        
[14] "flexbayes"                                        
[15] "main"                                            
> myPostX <- bhlm( fixed.formula = SDF3$veh.mean ~ 1, data = SDF3,prior
> = myPrior )
Loading required package coda
> myPostX
*** Posterior Distribution from the Bayesian Model ***
Call:  
bhlm(fixed.formula = SDF3$veh.mean ~ 1, data = SDF3, prior = myPrior)


# of Chains:  1
Starting Iteration:  1001
Ending Iteration:  2000
Thinning:  1
# of Samples:  1000

1. Summary statistics:

              Mean  S.D.
(Intercept) 136.70 8.070
      SIGMA  18.39 7.136

2. Quantiles:

             2.5 %   25 %   50 %   75 % 97.5 %
(Intercept) 121.20 132.40 136.70 141.00 152.70
      SIGMA  10.03  13.67  16.85  20.83  37.32
>

If this does not work, try detaching both Coda and flexBayes and then load flexBayes from the command prompt:

> detach("coda")
> detach("flexBayes")
> library(flexBayes)

There is also a known bug that occurs when loading flexBayes from the GUI (File -> Load Library...).  The problem is that it is not loaded in the correct position in the search path.  By loading the library at the command prompt using:

> library(flexBayes)

it is loaded into the correct position.