richarddmorey / BayesFactor

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

anovaBF error with particular dataset #18

Closed jonathon-love closed 10 years ago

jonathon-love commented 10 years ago

running the following, with the dataset "Bugs Long Form.csv":

data <- read.table("Bugs Long Form.csv", sep=",", header=TRUE)

data$Frightening <- as.factor(data$Frightening)
data$Disgusting <- as.factor(data$Disgusting)

anovaBF(Rating ~ Frightening * Disgusting, data)`

produces:

> anovaBF(Rating ~ Frightening * Disgusting, data)
|+++++++++++++++++++++++++                         |  50%
Error in optim(qs, Qg, gr = dQg, control = list(fnscale = -1), method = "BFGS",  :
initial value in 'vmmin' is not finite
|++++++++++++++++++++++++++++++++++++++            |  75%
Error in optim(qs, Qg, gr = dQg, control = list(fnscale = -1), method = "BFGS",  :
initial value in 'vmmin' is not finite
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100%
Bayes factor analysis
--------------
[1] Frightening                                       :     0.7731011
±0.25%
[2] Disgusting                                        :     5.342204e+39
±0.01%
[3] Frightening + Disgusting                          : NA           ±NaN%
[4] Frightening + Disgusting + Frightening:Disgusting : NA           ±NaN%

Against denominator:
  Intercept only

---
Bayes factor type: BFlinearModel, JZS
richarddmorey commented 10 years ago

There is missing data in the dependent variable. This is not allowed. I will add a warning in the next version. Try removing rows with missing data:

data = data[!is.na(data$Rating),]
anovaBF(Rating ~ Frightening * Disgusting, data) 

which will return a Bayes factor, as expected.

 Bayes factor analysis
 --------------
 [1] Frightening                                       : 0.7745435    ±0%
 [2] Disgusting                                        : 5.296542e+39 ±0%
 [3] Frightening + Disgusting                          : 4.665278e+39 ±0.98%
 [4] Frightening + Disgusting + Frightening:Disgusting : 4.563757e+43 ±1.34%

Against denominator:
  Intercept only 
---
Bayes factor type: BFlinearModel, JZS
jonathon-love commented 10 years ago

cheers, but isn't it suspicious that it does generate BFs for some models? i would expect all of them to fail.

richarddmorey commented 10 years ago

The BayesFactor package uses test statistics where possible (that is, where sampling is unnecessary), computed from R's own statistical routines. So it is inheriting R's behavior in some cases, but not others. In the next version the data will be checked first thing, so that won't occur. [but yes, you are right that it is suspicious. I was thinking the same thing at first.]

jonathon-love commented 10 years ago

How would you feel about adding an option to allow the BayesFactor package to ignore missing values? This would save us the time of copying the whole column each time we call the package (unless, that's all you'd be doing under the hood anyway)

richarddmorey commented 10 years ago

Yes, that's what I'd be doing under the hood (removing the missing data). The BayesFactor package creates a copy of the data for the BayesFactor object (to check for consistency between analyses, so that the c() method and /-operator methods disallow people doing impossible analyses). I'd be uncomfortable if the data that is saved in the object differs from the data that was explicitly passed to the function by the user.