richarddmorey / BayesFactor

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

Difficulty Obtaining Bayesfactor for Bayesian Correlation (correlationBF) #173

Closed Jakob-Kasper closed 2 months ago

Jakob-Kasper commented 3 months ago

I am trying to compute a Bayesian correlation between two variables (val_pvv, ther_pvv) within my dataset (df_clean), using the correlationBF function:

cor_pvv_ther_val <- correlationBF(df_clean$val_pvv, df_clean$ther_pvv)

This results in the following warning: Warning message: In genhypergeo_series_pos(U = c((n - 1)/2, (n - 1)/2), L = ((n + : Series not converged.

The describe_posterior function provides a summary of the posterior distribution, but not the Bayes Factor (BF):

Summary of Posterior Distribution Parameter | Median | 95% CI | pd | ROPE | % in ROPE | BF | Prior ----------------------------------------------------------------------------------------- rho | 0.92 | [0.90, 0.93] | 100% | [-0.05, 0.05] | 0% | | Beta (1 +- 1)

As can also be seen here: > extractBF(cor_pvv_ther_val)
bf error time code Alt., r=0.333 NA 0 Fri Apr 5 11:10:22 2024 504709623a0

Interestingly, JASP allows me to obtain the BF = 8.251*10^191.

Given the high median, I suspect the issue with the BF calculation might be related to the extremely high correlation. To give a reproducible example: the same happens when I simulate two variables that are very highly correlated (correlationBF(c(1,2,3,4,5,6,7,8,9), c(0.7, 2.3, 2.5, 3.8, 5.2, 5.8, 7.5, 8.4, 8.8))). I have the same issue when modifying the rscale argument (e.g., to wide or ultrawide).

I would be very happy about some further information on the warning and about some suggestions on how to solve the issue.

Thank you very much in advance!

Jakob-Kasper commented 2 months ago

This seems to be the solution to the issue: https://stats.stackexchange.com/questions/644203/difficulty-obtaining-bayesfactor-in-baysian-correlation-in-r-correlationbf-from/644954