Effect sizes¶
Calculation of effect sizes and sampling variances, see the user guide.
escalc ¶
escalc(
measure: str | None = None,
ai: ArrayLike | str | None = None,
bi: ArrayLike | str | None = None,
ci: ArrayLike | str | None = None,
di: ArrayLike | str | None = None,
n1i: ArrayLike | str | None = None,
n2i: ArrayLike | str | None = None,
x1i: ArrayLike | str | None = None,
x2i: ArrayLike | str | None = None,
t1i: ArrayLike | str | None = None,
t2i: ArrayLike | str | None = None,
m1i: ArrayLike | str | None = None,
m2i: ArrayLike | str | None = None,
sd1i: ArrayLike | str | None = None,
sd2i: ArrayLike | str | None = None,
xi: ArrayLike | str | None = None,
mi: ArrayLike | str | None = None,
ri: ArrayLike | str | None = None,
ti: ArrayLike | str | None = None,
fi: ArrayLike | str | None = None,
pi: ArrayLike | str | None = None,
sdi: ArrayLike | str | None = None,
r2i: ArrayLike | str | None = None,
mini: ArrayLike | str | None = None,
maxi: ArrayLike | str | None = None,
ni: ArrayLike | str | None = None,
yi: ArrayLike | str | None = None,
vi: ArrayLike | str | None = None,
sei: ArrayLike | str | None = None,
*,
data: DataFrame | Mapping[str, ArrayLike] | None = None,
slab: ArrayLike | str | None = None,
flip: ArrayLike | str | None = None,
subset: ArrayLike | str | None = None,
include: ArrayLike | str | None = None,
add: float | None = None,
to: Literal['all', 'only0', 'if0all', 'none'] = 'only0',
drop00: bool = False,
vtype: str | Sequence[str] = 'LS',
correct: bool | str = True,
cutoff: float | None = None,
var_names: Sequence[str] = ('yi', 'vi'),
add_measure: bool = False,
append: bool = True,
replace: bool = True,
digits: int | Sequence[int] | None = None,
onlyo1: bool = False,
addyi: bool = True,
addvi: bool = True,
) -> DataFrame
Calculate effect sizes yi and sampling variances vi (metafor's escalc).
The metafor reference (last section) lists the measures, the arguments each one needs and the vtype options.
add defaults to 1/2, except for the measures where metafor uses 0 (AS, PHI, ZPHI, RTET, ZTET, IRSD, PAS, PFT, IRS, IRFT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
str | None
|
Effect size or outcome measure to compute, a metafor code such as |
None
|
ai
|
ArrayLike | str | None
|
2x2 table frequencies (upper left cell). |
None
|
bi
|
ArrayLike | str | None
|
2x2 table frequencies (upper right cell). |
None
|
ci
|
ArrayLike | str | None
|
2x2 table frequencies (lower left cell). |
None
|
di
|
ArrayLike | str | None
|
2x2 table frequencies (lower right cell). |
None
|
n1i
|
ArrayLike | str | None
|
Group sizes or row totals (first group or row). |
None
|
n2i
|
ArrayLike | str | None
|
Group sizes or row totals (second group or row). |
None
|
x1i
|
ArrayLike | str | None
|
Number of events (first group). |
None
|
x2i
|
ArrayLike | str | None
|
Number of events (second group). |
None
|
t1i
|
ArrayLike | str | None
|
Total person-times (first group). |
None
|
t2i
|
ArrayLike | str | None
|
Total person-times (second group). |
None
|
m1i
|
ArrayLike | str | None
|
Means (first group or time point). |
None
|
m2i
|
ArrayLike | str | None
|
Means (second group or time point). |
None
|
sd1i
|
ArrayLike | str | None
|
Standard deviations (first group or time point). |
None
|
sd2i
|
ArrayLike | str | None
|
Standard deviations (second group or time point). |
None
|
xi
|
ArrayLike | str | None
|
Frequencies of the event of interest. |
None
|
mi
|
ArrayLike | str | None
|
Frequencies of the complement of the event of interest, or the group means. |
None
|
ri
|
ArrayLike | str | None
|
Raw correlation coefficients. |
None
|
ti
|
ArrayLike | str | None
|
Total person-times or t-test statistics. |
None
|
fi
|
ArrayLike | str | None
|
F-test statistics. |
None
|
pi
|
ArrayLike | str | None
|
(Signed) p-values. |
None
|
sdi
|
ArrayLike | str | None
|
Standard deviations. |
None
|
r2i
|
ArrayLike | str | None
|
|
None
|
mini
|
ArrayLike | str | None
|
Minimum values. |
None
|
maxi
|
ArrayLike | str | None
|
Maximum values. |
None
|
ni
|
ArrayLike | str | None
|
Sample or group sizes. |
None
|
yi
|
ArrayLike | str | None
|
Effect size estimates, for |
None
|
vi
|
ArrayLike | str | None
|
Sampling variances matching |
None
|
sei
|
ArrayLike | str | None
|
Standard errors matching |
None
|
data
|
DataFrame | Mapping[str, ArrayLike] | None
|
Data frame (or mapping of columns) holding the variables named in the data arguments. Each of
the arguments above is then an array or
the name of a column of |
None
|
slab
|
ArrayLike | str | None
|
Study labels, as a sequence or a column name. Stored in |
None
|
flip
|
ArrayLike | str | None
|
Flip the sign of the estimates: a boolean (or a boolean per study), or a numeric multiplier (one per study), or the name of a column of
|
None
|
subset
|
ArrayLike | str | None
|
Studies to keep in the returned frame: a boolean array, 0-based indices or an expression string evaluated on |
None
|
include
|
ArrayLike | str | None
|
Studies for which the measure is computed (the others get missing values), given like |
None
|
add
|
float | None
|
Non-negative amount to add to zero cells, counts or frequencies. Default |
None
|
to
|
Literal['all', 'only0', 'if0all', 'none']
|
When |
'only0'
|
drop00
|
bool
|
Drop studies with no cases or events (or only cases) in both groups from the calculations (set their values to missing). Used for the
2x2 table measures and |
False
|
vtype
|
str | Sequence[str]
|
Type of sampling variance: one of |
'LS'
|
correct
|
bool | str
|
Apply the bias correction to the estimates (default |
True
|
cutoff
|
float | None
|
Absolute value above which a computed estimate is flagged with a warning. The default is 2 for |
None
|
var_names
|
Sequence[str]
|
Names of the estimate and sampling variance columns of the result ( |
('yi', 'vi')
|
add_measure
|
bool
|
Add a column recording the measure computed (named |
False
|
append
|
bool
|
Return |
True
|
replace
|
bool
|
Replace existing |
True
|
digits
|
int | Sequence[int] | None
|
Number of decimals used when the frame is printed (stored in |
None
|
onlyo1
|
bool
|
For the 2x2 table measures: |
False
|
addyi
|
bool
|
|
True
|
addvi
|
bool
|
The same for the sampling variances |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The columns |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
ArgumentError
|
an argument has the wrong type or is not accepted. |
NotSupportedError
|
the requested combination is not implemented. |
InternalError
|
an internal invariant does not hold. |
summary_escalc ¶
summary_escalc(
object: DataFrame,
out_names: Sequence[str] = (
'sei',
'zi',
'pval',
'ci.lb',
'ci.ub',
),
var_names: Sequence[str] | None = None,
H0: ArrayLike = 0,
append: bool = True,
replace: bool = True,
level: float = 95,
olim: Sequence[float] | None = None,
digits: int | Sequence[int] | None = None,
transf: Callable[..., Any] | None = None,
**kwargs: Any,
) -> DataFrame
Add standard errors, test statistics, p-values and confidence intervals to the output of escalc.
Mirrors metafor's summary.escalc. With yi and vi the
effect sizes and sampling variances, it computes sei = sqrt(vi), zi = (yi - H0) / sei, the two-sided p-value pval and the Wald-type
interval yi -/+ z_crit * sei. With transf, yi and the bounds are transformed (the bounds are put in increasing order) and
vi, sei, zi and pval are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object
|
DataFrame
|
data frame returned by escalc (or a frame with the effect sizes and sampling variances as columns). |
required |
out_names
|
Sequence[str]
|
names of the five new columns, in the order standard error, test statistic, p-value, lower and upper bound (default 'sei', 'zi', 'pval', 'ci.lb', 'ci.ub'). |
('sei', 'zi', 'pval', 'ci.lb', 'ci.ub')
|
var_names
|
Sequence[str] | None
|
names of the columns with the effect sizes and the sampling variances (two names). Default None: taken from the
attributes of |
None
|
H0
|
ArrayLike
|
value of the effect under the null hypothesis for |
0
|
append
|
bool
|
whether the new columns are appended to |
True
|
replace
|
bool
|
whether existing columns with the names in |
True
|
level
|
float
|
confidence level in percent, between 0 and 100 (default 95). |
95
|
olim
|
Sequence[float] | None
|
(lower, upper) limits to which |
None
|
digits
|
int | Sequence[int] | None
|
number of decimals used when the frame is printed; stored in |
None
|
transf
|
Callable[..., Any] | None
|
function applied to the effect sizes and the bounds, for example |
None
|
**kwargs
|
Any
|
additional arguments passed on to |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A data frame with the columns of |
DataFrame
|
|
DataFrame
|
does not carry |
Raises:
| Type | Description |
|---|---|
InputError
|
|
cmicalc ¶
Small-sample bias correction factor for standardized mean differences.
Mirrors metafor's cmicalc.
The factor c(m) of Hedges (1981, doi:10.3102/10769986006002107) multiplies a standardized mean difference
to remove its small-sample bias. escalc uses it for the measures SMD, SMD1, SMDH, SMD1H, SMN, SMCC, SMCR, SMCRH, SMCRP and
SMCRPH, passing its argument correct as method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mi
|
ArrayLike
|
degrees of freedom |
required |
method
|
bool | str
|
'exact' | 'approx' | True | False. 'exact' (or True, the default) uses the gamma-function form, 'approx' the approximation
|
'exact'
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of the factors |
Raises:
| Type | Description |
|---|---|
InputError
|
|
cbind_escalc ¶
Combine data frames and further columns side by side and keep the escalc attributes.
Mirrors metafor's cbind() for escalc objects. The names of the effect size, sampling variance, standard error, test statistic, p-value
and confidence interval columns of all frames are collected (those of later frames first, as in R), digits is that of the last
frame, and measure, slab and ni come from the first frame that has them. Column names are not made unique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
DataFrame | Series
|
data frames (usually from escalc or summary_escalc) or named Series, all with the same number of rows. |
()
|
**columns
|
Any
|
further columns, named by the keyword; a vector becomes one column and a data frame has its columns prefixed with
|
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The combined data frame, with the columns of all arguments in order and the index of the first. |
Raises:
| Type | Description |
|---|---|
InputError
|
nothing is given, or the arguments have different numbers of rows. |
ArgumentError
|
an argument is neither a data frame nor a named Series. |
rbind_escalc ¶
Stack data frames on top of each other and keep the escalc attributes.
Mirrors metafor's rbind() for escalc objects. The columns are matched by name and the attributes of the first frame (measure,
digits, the names of the effect size columns, ...) are kept. ni is the concatenation of the sample sizes of all frames (missing if
one has none) and slab the concatenation of the study labels made unique as metafor does (repeats get .1, .2, ...), or missing
if one frame has none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
DataFrame
|
the data frames to stack, usually from escalc; they must have the same columns. |
()
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The stacked data frame. If all frames have the default index, a fresh 0-based index is made, else the row names are made unique. |
Raises:
| Type | Description |
|---|---|
InputError
|
nothing is given, or the numbers or names of the columns differ. |
ArgumentError
|
an argument is not a data frame. |