richarddmorey / BayesFactor

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

Error in anovaBF with multicore = TRUE #103

Closed crsh closed 7 years ago

crsh commented 7 years ago

Hi,

I'm experiencing problems when I try to run an ANOVA model in parallel on my dataset. I'm having a hard time understanding what is causing the problem.

Here is what I'm trying to do.

mean_expectancies <- source("https://gist.githubusercontent.com/crsh/fb1080b919a80821308eb0181c27bbd3/raw/df9e2158e9bad467607b4a0b4cdc7d2bc920d68e/data.R")[[1]]

library("BayesFactor")

# Works
aov_bf <- anovaBF(
  expectancy ~ repetition2 * valence * condition * context + subject_nr
  , data = mean_expectancies
  , whichRandom = "subject_nr"
  , whichModels = "top"
)

# Does not work
aov_bf <- anovaBF(
  expectancy ~ repetition2 * valence * condition * context + subject_nr
  , data = mean_expectancies
  , whichRandom = "subject_nr"
  , whichModels = "top"
  , multicore = TRUE
)

When I set multicore = TRUE I get the following error:

Error in mclapply(argsList, FUN, mc.preschedule = preschedule, mc.set.seed = set.seed,  :
                     attempt to select more than one element in integerOneIndex

It seems this issue may be related to some data points in the set but I don't understand what is causing the problem.

# Works
aov_bf <- anovaBF(
  expectancy ~ repetition2 * valence * condition * context + subject_nr
  , data = subset(mean_expectancies, as.numeric(as.character(subject_nr)) < 280)
  , whichRandom = "subject_nr"
  , whichModels = "top"
  , multicore = TRUE
)

# Doesn't work
aov_bf <- anovaBF(
  expectancy ~ repetition2 * valence * condition * context + subject_nr
  , data = subset(mean_expectancies, as.numeric(as.character(subject_nr)) < 281)
  , whichRandom = "subject_nr"
  , whichModels = "top"
  , multicore = TRUE
)

Here I get the following error:

Error in c.BFBayesFactor(<S4 object of class "BFBayesFactor">, <S4 object of class "BFBayesFactor">,  :
                            Cannot concatenate Bayes factor with non-Bayes factor.

Any ideas, what might be going on here?

Session info -----------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.3 (2017-03-06)
 system   x86_64, darwin15.6.0        
 ui       RStudio (1.0.143)           
 language (EN)                        
 collate  de_DE.UTF-8                 
 tz       Europe/Berlin               
 date     2017-05-22                  

Packages ---------------------------------------------------------------------------
 package      * version   date       source                        
 assertthat     0.1       2013-12-06 CRAN (R 3.3.0)                
 base         * 3.3.3     2017-03-19 local                         
 BayesFactor  * 0.9.12-2  2015-09-19 CRAN (R 3.3.3)                
 coda         * 0.19-1    2016-12-08 cran (@0.19-1)                
 codetools      0.2-15    2016-10-05 CRAN (R 3.3.3)                
 compiler       3.3.3     2017-03-19 local                         
 datasets     * 3.3.3     2017-03-19 local                         
 DBI            0.5       2016-08-11 CRAN (R 3.3.1)                
 devtools       1.13.0    2017-05-08 CRAN (R 3.3.3)                
 digest         0.6.11    2017-01-03 url                           
 doMC           1.3.4     2015-10-13 CRAN (R 3.3.1)                
 dplyr          0.5.0     2016-06-24 CRAN (R 3.3.2)                
 foreach        1.4.3     2015-10-13 CRAN (R 3.3.1)                
 graphics     * 3.3.3     2017-03-19 local                         
 grDevices    * 3.3.3     2017-03-19 local                         
 grid           3.3.3     2017-03-19 local                         
 gtools         3.5.0     2015-05-29 CRAN (R 3.3.1)                
 iterators      1.0.8     2015-10-13 CRAN (R 3.3.1)                
 lattice        0.20-35   2017-03-25 CRAN (R 3.3.3)                
 magrittr       1.5       2014-11-22 CRAN (R 3.3.0)                
 Matrix       * 1.2-10    2017-04-28 CRAN (R 3.3.3)                
 MatrixModels   0.4-1     2015-08-22 CRAN (R 3.3.0)                
 memoise        1.0.0     2016-01-29 CRAN (R 3.3.1)                
 methods      * 3.3.3     2017-03-19 local                         
 mvtnorm        1.0-6     2017-03-02 cran (@1.0-6)                 
 parallel       3.3.3     2017-03-19 local                         
 pbapply        1.3-2     2017-03-01 cran (@1.3-2)                 
 R6             2.2.0     2016-10-05 cran (@2.2.0)                 
 Rcpp           0.12.10.4 2017-05-10 Github (RcppCore/Rcpp@4e0f79c)
 rstudioapi     0.6       2016-06-27 CRAN (R 3.3.1)                
 stats        * 3.3.3     2017-03-19 local                         
 stringi        1.1.2     2016-10-01 CRAN (R 3.3.2)                
 stringr        1.2.0     2017-02-18 cran (@1.2.0)                 
 tibble         1.3.0     2017-04-01 cran (@1.3.0)                 
 tools          3.3.3     2017-03-19 local                         
 utils        * 3.3.3     2017-03-19 local                         
 withr          1.0.2     2016-06-20 CRAN (R 3.3.1) 
richarddmorey commented 7 years ago

I cannot replicate this error on my end (R 3.3.1, OSX), though you have some more recent versions of some packages than I do. It is possible that one of the dependencies' updates broke something. I'll do some poking around.

richarddmorey commented 7 years ago

I have upgraded R and all my packages; I still cannot replicate. I'm guessing it is something idiosyncratic with your setup. I'm going to close this; you can reopen it of you learn more.