4.2 From formulas

Sometimes, you want to use a specific formula to calculate the effect size - or you just want the formula to be explicit, not hidden away inside escalc. You can transcribe the formula into R syntax, and compute the effect size manually.

For this example, we use the the dat.molloy2014 dataset, included with metafor, which contains correlations, and their sample sizes:

authors ni ri
Axelsson et al. 109 0.187
Axelsson et al. 749 0.162
Bruce et al. 55 0.340
Christensen et al. 107 0.320
Christensen & Smith 72 0.270
Cohen et al. 65 0.000
Dobbels et al. 174 0.175
Ediger et al. 326 0.050
Insel et al. 58 0.260
Jerant et al. 771 0.010
Moran et al. 56 -0.090
O’Cleirigh et al. 91 0.370
Penedo et al. 116 0.000
Quine et al. 537 0.150
Stilley et al. 158 0.240
Wiebe & Christensen 65 0.040

Because correlations are bounded by [-1, 1], they are often Fisher-transformed prior to meta-analysis. The formula for Fisher’s r-to-z transformation is:

\[ z = .5 * ln(\frac{1+r}{1-r}) \]

In R-syntax, that formula is expressed as: z <- .5 * log((1+r)/(1-r)).

We can calculate a new column in the data, using this formula, by substituting r with the column in the data that contains the correlations:

df_cor <- dat.molloy2014
# Compute new column:
df_cor$zi <- .5 * log((1+df_cor$ri)/(1-df_cor$ri))

Alternatively, we can store the calculation as a function, which makes the code a bit cleaner:

# Create function r_to_z, which takes r as input:
r_to_z <- function(r){.5 * log((1+r)/(1-r))}
# Apply the function to compute new column:
df_cor$zi <- r_to_z(df_cor$ri)

The sampling variance for the transformed correlations is:

\[ V_z = \frac{1}{n-3} \]

So by the same process, we can add the sampling variance to the data:

# Create function v_z, which takes n as input:
v_z <- function(n){1/(n-3)}
# Apply the function to compute new column:
df_cor$vi <- v_z(df_cor$ni)