I was calculating effect sizes for an analysis and noticed by chance that Pearson's $r$ calculated from Cohen's $d$ with a conversion formula is not the same as when I calculate the correlation given the raw data. Does anyone have an idea why it is like this? I've tried with random numbers several times and the two $r$'s are not even close, I've also tried to calculate manually and looked up which formulas are used by the packages (so this does not seem like a problem with the package), I can't make sense of this.
np.random.seed(10)
df = pd.DataFrame(np.random.randint(0,100,size=(100, 2)), columns=list('AB'))
d = pg.compute_effsize(df['A'],df['B'], paired=False, eftype='cohen')
r_calc = pg.compute_effsize(df['A'],df['B'], paired=False, eftype='r')
r_conv = pg.convert_effsize(d,'cohen','r')
EDIT: The formulas I tried for $d$ are $d = \frac{\bar{x}_{1} - \bar{x}_{2}}{s}$.
With $s = \sqrt{\frac{(n_1 - 1)s^2_1 + (n_2 - 1)s^2_2}{n_1 + n_2 - 2}}$, or $s = \sqrt{\frac{(n_1 - 1)s^2_1 + (n_2 - 1)s^2_2}{n_1 + n_2}}$.
(pg.compute_effsize
uses the first version with -2 in the denominator).
I get $d = 0,206012$ (or $0,207049$ for the second formula) and $r = 0,1029749$ when I convert $d$ with the formula used by pg.convert_effsize
$r = \frac{d}{\sqrt{d^2 + \frac{(n_x + n_y)^2 - 2(n_x+ n_y)}{n_x n_y}}}$
(using the alternative $d$, I get $r = 0,103488$).
When I calculate $r$ as the Pearson correlation, I get $0,157920$.
This was already asked here but not answered unfortunately: Why does Pearson's $r$ differ from the converted value of $r$ from Cohen's $d$
pg.convert_effsize
might be using. $\endgroup$