Skip to content

Commit

Permalink
fix metaBMA unit tests (MCMC changes due to Stan?)
Browse files Browse the repository at this point in the history
  • Loading branch information
FBartos committed Sep 19, 2023
1 parent 6817806 commit 0398e17
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 94 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 33 additions & 37 deletions tests/testthat/test-bayesianmetaanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ options$inverseGammaShape <- 1
options$inverseGammaScale <- 0.15
options$chains <- 4
options$seed <- 1
options$.meta <- list(effectSizeCi = list(containsColumn = TRUE),
effectSize = list(containsColumn = TRUE),
effectSizeSe = list(containsColumn = TRUE),
options$.meta <- list(effectSizeCi = list(containsColumn = TRUE),
effectSize = list(containsColumn = TRUE),
effectSizeSe = list(containsColumn = TRUE),
studyLabel = list(containsColumn = TRUE))
options$effectSizeCi <- list()
set.seed(1)
Expand All @@ -49,40 +49,38 @@ results <- jaspTools::runAnalysis("BayesianMetaAnalysis", "BCG Vaccine.csv", opt
##############################################################

test_that("Posterior Estimates per Model table results match", {
testthat::skip_on_os(c("mac", "linux", "solaris"))
table <- results[["results"]][["bmaTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list("TRUE", 4.70377989938849e+21, -0.434254495375077, 0.0413386758998794,
-0.51661689869485, "Fixed effects", "<unicode><unicode>", -0.354044245070268,
"TRUE", 46.1842149375581, -0.700934189539198, 0.191389586956929,
-1.09512063075207, "Random effects", "<unicode><unicode>", -0.313314935687268,
1, "FALSE", 8.63965964148833e+26, 0.587415453102927, 0.174455537927642,
0.341965384464118, "Random effects", "<unicode><unicode>", 0.977068560913425,
2, "TRUE", 46.184214937558, -0.70093422222471, 0.192829673436622,
-1.10318957647626, "Averaged", "<unicode><unicode>", -0.322201994073094,
3, "FALSE", 8.82672917711143e+26, "", "", "", "Averaged", "<unicode><unicode>",
list("TRUE", 4.70377989938849e+21, -0.434254495375077, 0.0413386758998794,
-0.516616898694849, "Fixed effects", "<unicode>", -0.35404424507026,
"TRUE", 46.1842149375581, -0.691684127331745, 0.194674438261359,
-1.05371165363577, "Random effects", "<unicode>", -0.29988113833234,
1, "FALSE", 8.63965964148833e+26, 0.585325517009774, 0.167159875616352,
0.343234248728213, "Random effects", "<unicode>", 0.993677396740531,
2, "TRUE", 46.184214937558, -0.691684144187806, 0.195426184793392,
-1.05915644399236, "Averaged", "<unicode>", -0.277506371377729,
3, "FALSE", 8.82672917711143e+26, "", "", "", "Averaged", "<unicode>",
""))
})

test_that("Effect Sizes per Study table results match", {
testthat::skip_on_os(c("mac", "linux", "solaris"))
table <- results[["results"]][["effectSizePerStudy"]][["data"]]
jaspTools::expect_equal_tables(table,
list(-0.810675161337492, -1.68394255502823, 0.00390957421349684, -0.9387,
"Study 1", -1.28269463814809, -2.02557257455892, -0.578076727966483,
-1.6662, "Study 2", -0.996207535379598, -1.91697987764739, -0.137535263863821,
-1.3863, "Study 3", -1.40296899560657, -1.68366211044064, -1.12263629534387,
-1.4564, "Study 4", -0.291114685435556, -0.70248689247515, 0.129769093323344,
-0.2191, "Study 5", -0.948970505192553, -1.14550800371907, -0.75676856452674,
-0.9581, "Study 6", -1.23621664010226, -2.02727979088307, -0.506882158451203,
-1.6338, "Study 7", 0.00212364835628054, -0.121206326357141,
0.126228703001128, 0.012, "Study 8", -0.50606742399599, -0.934996647644956,
-0.0771038611477936, -0.4717, "Study 9", -1.25397766949404,
-1.74487198539962, -0.762447203053708, -1.4012, "Study 10",
-0.355110794879739, -0.573286768149591, -0.141056308764899,
-0.3408, "Study 11", -0.266903956259088, -1.19606414841548,
0.753566949784523, 0.4466, "Study 12", -0.148194690282786, -0.628570090461296,
0.345693436706941, -0.0173, "Study 13"))
list(-0.809128072433214, -1.65195861984318, 0.0291494666483802, -0.9387,
"Study 1", -1.27392183924008, -2.04585172754217, -0.550502001072192,
-1.6662, "Study 2", -0.987605843372775, -1.89764125756983, -0.131147744375098,
-1.3863, "Study 3", -1.4025680591068, -1.67918997790265, -1.13439697200656,
-1.4564, "Study 4", -0.292551414527035, -0.713785940836336,
0.150204176975293, -0.2191, "Study 5", -0.948574718058429, -1.14002067256022,
-0.754825669673909, -0.9581, "Study 6", -1.23879932796539, -2.02118617092247,
-0.514836725420342, -1.6338, "Study 7", 0.00199996360424655,
-0.11868785432434, 0.121531187105811, 0.012, "Study 8", -0.511556112765042,
-0.939053440577442, -0.0814585678966693, -0.4717, "Study 9",
-1.25406731815491, -1.76606641390657, -0.751053323311322, -1.4012,
"Study 10", -0.354049282748894, -0.568645513271642, -0.143878543957096,
-0.3408, "Study 11", -0.264061608492473, -1.16024809868433,
0.690555229532794, 0.4466, "Study 12", -0.147144689281277, -0.643591471297769,
0.355581782256767, -0.0173, "Study 13"))
})

test_that("Observed study effects plot matches", {
Expand Down Expand Up @@ -110,13 +108,11 @@ test_that("Model Probabilities table results match", {
if (Sys.info()["sysname"] == "Darwin")
testthat::skip("this test doesn't work on macOS + maybe a reason for future us to look at")

table <- results[["results"]][["modelProbability"]][["data"]]
jaspTools::expect_equal_tables(table,
list("Fixed H<unicode><unicode><unicode>", 2.40853635687008e-49, 0.25,
"Fixed H<unicode><unicode><unicode>", 1.13292249023919e-27,
0.25, "Random H<unicode><unicode><unicode>", 0.0211935284146057,
0.25, "Random H<unicode><unicode><unicode>", 0.978806471585394,
0.25))
table <- results[["results"]][["modelProbability"]][["data"]]
jaspTools::expect_equal_tables(table,
list("Fixed H<unicode>", 2.40853635687009e-49, 0.25, "Fixed H<unicode>",
1.13292249023919e-27, 0.25, "Random H<unicode>", 0.0211935284146057,
0.25, "Random H<unicode>", 0.978806471585394, 0.25))
})

test_that("Effect Size plot matches", {
Expand All @@ -131,4 +127,4 @@ test_that("Heterogeneity plot matches", {
plotName <- results[["results"]][["priorContainer"]][["collection"]][["priorContainer_SE"]][["data"]]
testPlot <- results[["state"]][["figures"]][[plotName]][["obj"]]
jaspTools::expect_equal_plots(testPlot, "heterogeneity-2")
})
})

0 comments on commit 0398e17

Please sign in to comment.