FBartos / RoBMA

RoBMA R package for estimating robust Bayesian meta-analyses
https://fbartos.github.io/RoBMA/
8 stars 3 forks source link

Error: missing values not allowed when using `prior_scale = "r"` #18

Closed JeffreyRStevens closed 2 years ago

JeffreyRStevens commented 2 years ago

First, thank you for this awesome package! I'm working with correlational data for a meta-analysis, so I would prefer the output of RoBMA() to be in correlation coefficients. When I set prior_scale = "r", I receive the following error:

Error in quantile.default(model_samples[, par], 0.025) : missing values and NaN's not allowed if 'na.rm' is FALSE In addition: Warning message: In sqrt(1 - x^2) : NaNs produced

When I do not set prior_scale or set it to "fishers_z", I do not receive the error. Here is a reproducible example using just a few chains/samples/etc. to shorten runtime:

library(RoBMA)
r <- c(-0.46, -0.61, -0.053, 0.01, -0.10, 0.04)
n <- c(23, 13, 24, 48, 65, 43)
fit_r <- RoBMA(r = r, n = n, prior_scale = "r", chains = 2, sample = 100, burnin = 100, adapt = 100, seed = 1)
fit_z <- RoBMA(r = r, n = n, prior_scale = "fishers_z", chains = 2, sample = 100, burnin = 100, adapt = 100, seed = 1)

fit_r results in the error, whereas fit_z runs fine.

I'm running {RoBMA} version 2.2.2 in R version 4.2.0 on Ubuntu 20.04. I also reinstalled {BayesTools}.

FBartos commented 2 years ago

Hi Jeffrey,

Thanks for the kind words and for reporting the issue!

The prior_scale argument controls the effect size scale which is used for specifying prior distributions. The default prior specification (used in our simulation studies etc) is set on Cohen's d. The effect size input can be, however, on different scales as the package internally transforms both the effect size and prior distributions to Fisher's z scale. The reason for this is that Fisher's z has much better statistical properties. I would not recommend changing these defaults as they were tested across many settings and specifying prior distributions on a different effect size scale than Cohen's d can be much trickier.

That leads us to the cause of the error: the default prior distribution on the effect size - a Normal(0, 1) prior distribution often leads to effect sizes |r| > 1, causing this cryptic error message. I shall add a better error message that clarifies the issue and checks whether the prior distribution is compatible with the correlation scale.

I think that you actually want to summarize the results on the correlation scale. That can be done even if the prior distributions are specified on Cohen's d scale (as default). To do so, you need to add the output_scale = "r" argument to the summary() function.

E.g.,

summary(fit_z, output_scale = "r")

Which produces the output on the correlation scale. (The summary function internally transforms the posterior samples.)

Hope this solves the issue, Frantisek

JeffreyRStevens commented 2 years ago

Frantisek, This is incredibly helpful and now the error totally makes sense. So, to be clear, when I input the correlation coefficients in to the r argument, they are transformed to Fisher's z scale. If I were to alter the prior distributions, they are in a Cohen's d scale, which is transformed to Fisher's z scale also. Then the computations are run on this. Then, if I include output_scale = "r" in the summary() call, the values are back transformed to correlation coefficients for presentation. Is that correct? Again, many thanks for this! Jeff

FBartos commented 2 years ago

Hi Jeff,

Yes, that's correct indeed. (If you don't specify the output scale explicitly in the summary function, the summary will be produced on the same scale that was used for specifying prior distributions.)

Feel free to reopen the issue if you have any other questions.

Cheers, Frantisek