richarddmorey / BayesFactor

BayesFactor R package for Bayesian data analysis with common statistical models.
https://richarddmorey.github.io/BayesFactor/
132 stars 49 forks source link

Posterior sampling error in lmBF with just interaction term #155

Closed 0xSMT closed 3 years ago

0xSMT commented 3 years ago

Very related to issue #96, reproducible example (essentially copied and modified from the aforementioned issue) attached below:

library(BayesFactor)

Data_sub <- data.frame( Ypred = c( 10, 14, 19, 22, 15, 17, 15, 17, 18, 18, 18,
                                   19, 20, 30, 18, 19, 21, 26, 28, 27, 40, 16 ),
                        Xcont = c( 84, 42, 20, 42, 16, 20, 58, 6, 135, 58, 201,
                                   22, 20, 147, 10, 20, 30, 35, 9, 22, 9, 44 ),
                        Xcat = c( 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2,
                                  1, 2, 1, 2, 2, 2, 2 ) )

Data_sub$Xcat <- factor( Data_sub$Xcat )

lm.1 <- lmBF( Ypred ~ Xcont:Xcat, data = Data_sub )

# Error occurs here!
posterior(lm.1, iterations = 10000)
Error in if (length(continuous) != P) stop("argument continuous must have same length as number of predictors") : 
  argument is of length zero

Specifically, it seems to be the same issue from #96, but the problem persists if the model is just an interaction term with a binary factor (the example in #96 has a ternary factor -- in this case, the Xcat variable has been modified from the original to only have 1 and 2).

Installation Details:

Package: BayesFactor
Type: Package
Version: 0.9.12-4.2
Date: 2018-5-09
License: GPL 2.0
LazyLoad: yes

Thanks in advance!

richarddmorey commented 3 years ago

Just reproduced it, thanks. I'll check this out,

richarddmorey commented 3 years ago

I've fixed this issue. You can install the latest version with devtools directly from github if you have Rtools installed. If not, let me know and I can compile a fixed version for you.

0xSMT commented 3 years ago

Works perfectly, thanks!