Plots¶
Plot functions, see Plots. They draw with matplotlib.
forest ¶
Forest plots (metafor's forest.rma, forest.default, addpoly.rma and addpoly.default).
The layout logic follows the R code line by line: study rows are numbered k:1 from the top,
the summary polygon sits at row -1 (prediction interval at -2), the axis limits are
alim/xlim with the label and annotation areas reserved left and right of the plot, and the
sizes of the arrow heads, CI end caps and summary polygons are fractions of the plot height.
See https://wviechtb.github.io/metafor/reference/forest.rma.html and https://wviechtb.github.io/metafor/reference/addpoly.html, and Viechtbauer (2010), doi:10.18637/jss.v036.i03.
ForestResult
dataclass
¶
ForestResult(
ax: Axes,
xlim: tuple[float, float],
alim: tuple[float, float],
at: FloatArray,
ylim: tuple[float, float],
rows: FloatArray,
cex: float,
cex_lab: float,
cex_axis: float,
ilab_xpos: FloatArray | None,
ilab_pos: list[int] | None,
textpos: tuple[float, float],
areas: tuple[float, float, float] | None = None,
)
What metafor's forest() returns invisibly, plus the axes drawn on.
xlim/ylim are the limits of the plot region, alim the limits of the x axis,
at the tick locations, rows the row of each plotted estimate, textpos the x
positions of the study labels and annotations, areas the relative widths of the
label, plot and annotation areas (forest of a fitted model only).
TransfRule
dataclass
¶
How the density of a prediction is carried over to the scale of a back-transformation (the change of variables of metafor's funlist).
PredCurve
dataclass
¶
PredCurve(
xs: FloatArray,
ys: FloatArray,
l0: BoolArray,
g0: BoolArray,
lower_tail: bool,
limited: bool = False,
)
The density of the predictive distribution on the plotted scale: xs, ys, the parts below (l0) and above (g0) predtail.
limited is whether predlim was given ('dist' then keeps the whole density instead of dropping the part below 0.5% of the peak).
PredGeometry
dataclass
¶
PredGeometry(
alim: tuple[float, float],
ciendheight: float,
arrowwidth: float,
arrowheight: float,
barheight: float,
pipolheight: float,
ef4: float,
olim: tuple[float, float] | None = None,
)
The sizes and limits used to draw a prediction interval (see :func:draw_pred).
expand ¶
R's .expand1() followed by the length check.
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
pervec ¶
A per-study argument of a fitted model: a scalar is recycled, a vector may have one entry per supplied study.
compress_rows ¶
Close the gaps left by omitted (missing) estimates, as the na.omit branch of forest does.
strheight ¶
strheight("O") in user coordinates (cap height of 12pt-scaled text relative to the axes height).
anno_symbol ¶
The five symbols of the annotations (opening, separator, closing, minus, space); tabfig 1 to 3 replaces them with those for tabular figures.
Raises:
| Type | Description |
|---|---|
InputError
|
|
build_annotext ¶
build_annotext(
est: NDArray[float64],
lb: NDArray[float64],
ub: NDArray[float64],
digits: Sequence[int],
annosym: list[str],
width: Sequence[int] | int | None,
weights: NDArray[float64] | None,
pi_row: bool,
atransf: Callable[..., Any] | None,
targs: Any,
weight_pad_rows: tuple[int, ...] = (),
) -> tuple[list[str], list[int]]
The annotation strings (est [lb, ub]) and their column widths.
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
ftxt ¶
ftxt(
ax: Axes,
x: float,
y: float,
s: str,
fnt: tuple[str, int],
*,
bold: bool = False,
**kw: Any,
) -> Text
text() in the font (family, font) of fonts; bold=True is an explicit font=2, which wins over the font in fnt.
check_pred ¶
The validated predstyle; like R's match.arg() an unambiguous abbreviation ('l', 'p', 'b', 's', 'd') is accepted.
Raises:
| Type | Description |
|---|---|
InputError
|
the style is not one of the allowed names. |
transf_rule ¶
transf_rule(
transf: Callable[..., Any] | None,
) -> TransfRule | None
The :class:TransfRule of transf (None without a transformation).
Raises:
| Type | Description |
|---|---|
InputError
|
the transformation is not one metafor can draw a prediction distribution for. |
parse_predtail ¶
metafor's predtail (a number or a string such as '<2'/'>2') as (value, lower_tail).
Raises:
| Type | Description |
|---|---|
InputError
|
the value cannot be interpreted. |
parse_preddist ¶
parse_preddist(
preddist: tuple[ArrayLike, ArrayLike]
| Mapping[str, Any]
| None,
) -> (
tuple[
NDArray[float64], NDArray[float64], dict[str, Any]
]
| None
)
A user-supplied predictive distribution as (xs, ys, extras) (extras may hold pi_lb, pi_ub and level).
Raises:
| Type | Description |
|---|---|
InputError
|
the distribution is invalid. |
pred_curve ¶
pred_curve(
style: str,
pred: float,
pi_se: float | None,
pi_dist: str,
pi_ddf: float | None,
pi_level: float,
transf: Callable[..., Any] | None,
predlim: Sequence[float] | None,
preddist: tuple[NDArray[float64], NDArray[float64]]
| None,
predtail: float | str | None,
) -> PredCurve
The predictive distribution to draw for predstyle='shade' and 'dist' (metafor's code in forest.rma and addpoly.default).
pred is the (untransformed) predicted value, pi_se, pi_dist ('norm' or 't') and pi_ddf describe the distribution,
pi_level is the alpha level of the prediction interval, predlim the limits of the distribution to draw (on the plotted scale),
preddist a distribution supplied by the user (the values and the densities) and predtail the cut for the shading of 'dist'.
Raises:
| Type | Description |
|---|---|
InputError
|
the distribution cannot be drawn. |
ramp_colors ¶
R's colorRamp(c(col_from, col_to)) applied to intensity and written with rgb(..., maxColorValue = 255) (which truncates).
draw_shade ¶
draw_shade(
ax: Axes,
curve: PredCurve,
row: float,
barheight: float,
alim: tuple[float, float],
olim: tuple[float, float] | None,
col_from: str | None,
col_to: str | None,
) -> None
predstyle='shade': rectangles along the prediction interval, shaded from col_from (the centre) to col_to (the ends).
Raises:
| Type | Description |
|---|---|
InputError
|
a colour is missing. |
draw_dist ¶
draw_dist(
ax: Axes,
curve: PredCurve,
drow: float,
pi_lb: float,
pi_ub: float,
alim: tuple[float, float],
olim: tuple[float, float] | None,
ef4: float,
col: Sequence[str | None],
border: Sequence[str | None],
) -> None
predstyle='dist': the predictive density, the tails beyond the interval and the parts either side of predtail shaded.
forest ¶
forest(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult
| CumulResult
| ArrayLike,
vi: ArrayLike | None = None,
sei: ArrayLike | None = None,
ci_lb: ArrayLike | None = None,
ci_ub: ArrayLike | None = None,
annotate: bool = True,
addfit: bool | None = None,
addpred: bool
| str
| int
| Sequence[str | int]
| None = None,
predstyle: str | None = None,
preddist: tuple[ArrayLike, ArrayLike]
| Mapping[str, Any]
| None = None,
showweights: bool | None = None,
header: bool | str | Sequence[str] = True,
xlim: Sequence[float] | None = None,
alim: Sequence[float] | None = None,
olim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
predlim: Sequence[float] | None = None,
at: ArrayLike | None = None,
steps: int = 5,
level: float | None = None,
refline: float | None = 0,
digits: int | Sequence[float] | NDArray[floating] = 2,
width: int | Sequence[int] | None = None,
xlab: str | Sequence[str] | None = None,
slab: Sequence[Any] | float | None = None,
mlab: str | Sequence[str] | None = None,
ilab: Any = None,
ilab_lab: str | Sequence[str] | None = None,
ilab_xpos: ArrayLike | None = None,
ilab_pos: int | Sequence[int] | None = None,
order: str | ArrayLike | None = None,
subset: ArrayLike | None = None,
transf: Callable[..., Any] | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
rows: ArrayLike | float | None = None,
efac: float | Sequence[float] = 1,
pch: int | Sequence[int] = 15,
psize: float | ArrayLike | None = None,
plim: Sequence[float] = (0.5, 1.5),
colout: str | Sequence[str] | None = None,
colci: str | Sequence[str] | None = None,
col: str | Sequence[str] | None = None,
border: str | Sequence[str] | None = None,
shade: bool | str | ArrayLike | None = None,
colshade: str | None = None,
lty: str | Sequence[str] | None = None,
fonts: str
| tuple[str, int]
| Sequence[str | tuple[str, int]]
| Mapping[str, int]
| None = None,
cex: float | None = None,
cex_lab: float | None = None,
cex_axis: float | None = None,
*,
ax: Axes | None = None,
predtail: float | str | None = None,
annosym: Sequence[str] | None = None,
tabfig: int | None = None,
textpos: Sequence[float] | None = None,
rowadj: float | Sequence[float] | None = None,
top: float = 3,
at_lab: Sequence[str] | None = None,
xlabadj: float | Sequence[float] | None = None,
xlabfont: int | Sequence[int] = 1,
decreasing: bool = False,
measure: str | None = None,
slab_null: bool | None = None,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
predtype: str | None = None,
pi_type: str | None = None,
addcred: bool
| str
| int
| Sequence[str | int]
| None = None,
clim: Sequence[float] | None = None,
) -> ForestResult
Forest plot of a fitted model (forest.rma), a cumulative analysis or of estimates with their variances (forest.default).
Mirrors metafor's forest() and forest.rma(). Each study is drawn as a marker with a confidence interval. For a fitted
model the summary estimate is added as a polygon below the studies (with an optional prediction interval); for a model with moderators
the fitted value of each study is added as a polygon on its row. Arguments follow metafor's names (. becomes _). Indices are
0-based where they refer to studies (subset); rows and the numeric form of shade are plot rows as in R.
Vector arguments of a fitted model (slab, ilab, pch, psize, colout, colci, order, a logical shade) must have one
entry per study used in the fit or one per row of the original data (the entries of studies dropped for missing values are then removed,
as in metafor). For a vector x they must have one entry per estimate.
The differences from metafor are that predstyle='line2' is not available, that refline takes a single value, that predtail
must be a number or a string such as '<2' and that slab=nan is only accepted for a vector x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult | CumulResult | ArrayLike
|
A fitted model (from rma_uni and the other fitting functions), the result of cumul or a vector
of estimates. A cumulative analysis is passed on to forest_cumul; the arguments |
required |
vi
|
ArrayLike | None
|
Sampling variances of the estimates in |
None
|
sei
|
ArrayLike | None
|
Standard errors of the estimates in |
None
|
ci_lb
|
ArrayLike | None
|
Lower confidence interval bounds of the estimates in |
None
|
ci_ub
|
ArrayLike | None
|
Upper confidence interval bounds of the estimates in |
None
|
annotate
|
bool
|
Add the annotations (estimate and confidence interval) on the right of the plot. Default: |
True
|
addfit
|
bool | None
|
Fitted model only: add the polygon of the pooled estimate (a model without moderators) or the polygon of the fitted value of
each study (a model with moderators). Default: |
None
|
addpred
|
bool | str | int | Sequence[str | int] | None
|
Add the prediction interval to the summary polygon (or, for a model with moderators, use the prediction instead of the
confidence interval for the polygon of each study). |
None
|
predstyle
|
str | None
|
Style of the prediction interval: |
None
|
preddist
|
tuple[ArrayLike, ArrayLike] | Mapping[str, Any] | None
|
Predictive distribution to draw for |
None
|
showweights
|
bool | None
|
None
|
|
header
|
bool | str | Sequence[str]
|
|
True
|
xlim
|
Sequence[float] | None
|
Horizontal limits |
None
|
alim
|
Sequence[float] | None
|
Limits of the x axis (the axis and the polygons are drawn within them; intervals beyond them end in an arrow).
Default: the range of |
None
|
olim
|
Sequence[float] | None
|
Limits |
None
|
ylim
|
Sequence[float] | None
|
Vertical limits of the plot region. A single value sets the lower limit only. Default: from the rows of the studies, |
None
|
predlim
|
Sequence[float] | None
|
Limits |
None
|
at
|
ArrayLike | None
|
Positions of the x-axis tick marks, on the scale that is plotted (after |
None
|
steps
|
int
|
Number of tick marks of the x axis: exact when |
5
|
level
|
float | None
|
Level of the confidence (and prediction) intervals: 95, 0.95 and 0.05 all give a 95% interval. Default: that of the model, or
95 for a vector |
None
|
refline
|
float | None
|
Position of the dotted vertical reference line, or |
0
|
digits
|
int | Sequence[float] | NDArray[floating]
|
Number of decimals of the annotations, of the x-axis labels and of the weights, in this order. A single value is used for all
three; two values give the third the value of the first. An integer (such as |
2
|
width
|
int | Sequence[int] | None
|
Minimum width (number of characters) of the annotation columns: one value for all columns or one per column. A column is never narrower than its longest entry. Default: the width of the longest entry. |
None
|
xlab
|
str | Sequence[str] | None
|
Label of the x axis, or three (left end, centre, right end) or two (left and right end) labels. Default: the name of the measure
(for example |
None
|
slab
|
Sequence[Any] | float | None
|
Study labels, one per study. Default: the labels of the model, else |
None
|
mlab
|
str | Sequence[str] | None
|
Label of the summary polygon of a fitted model, or with a prediction interval drawn by a style other than |
None
|
ilab
|
Any
|
Extra columns of information on the left of the plot: a vector, a matrix or a data frame with one row per study. |
None
|
ilab_lab
|
str | Sequence[str] | None
|
Headings of the |
None
|
ilab_xpos
|
ArrayLike | None
|
X positions of the |
None
|
ilab_pos
|
int | Sequence[int] | None
|
Alignment of the |
None
|
order
|
str | ArrayLike | None
|
Order of the studies. A string, for a fitted model |
None
|
subset
|
ArrayLike | None
|
Vector form only (a fitted model raises an error): which estimates to show, a boolean array or 0-based indices (R: 1-based). |
None
|
transf
|
Callable[..., Any] | None
|
Function applied to the estimates and to the confidence and prediction interval bounds (for example |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the x-axis labels and to the annotations (the plot stays on the original scale, so |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
rows
|
ArrayLike | float | None
|
Rows (vertical positions) of the studies, one per study, or a single value for the row of the first study (the others follow
below it). Default: |
None
|
efac
|
float | Sequence[float]
|
Vertical expansion factors, |
1
|
pch
|
int | Sequence[int]
|
Plotting symbol of the study markers, an R code (0 to 6 and 15 to 25 are drawn; another code gives a filled circle); one value or one per study. Default: 15 (a filled square). |
15
|
psize
|
float | ArrayLike | None
|
Sizes of the study markers: one value or one per study. Default: scaled by the square root of the weights of the model (for a
vector |
None
|
plim
|
Sequence[float]
|
|
(0.5, 1.5)
|
colout
|
str | Sequence[str] | None
|
Fitted model: colour of the study markers and, unless |
None
|
colci
|
str | Sequence[str] | None
|
Colour of the confidence interval lines; one value or one per study. Default: that of the markers. |
None
|
col
|
str | Sequence[str] | None
|
Fitted model: colour of the summary polygon (without moderators: up to four values for the polygon and the prediction interval, see
below) or of the polygons of the fitted values (default |
None
|
border
|
str | Sequence[str] | None
|
Border colour of the summary polygon ( |
None
|
shade
|
bool | str | ArrayLike | None
|
Shade rows. |
None
|
colshade
|
str | None
|
Colour of the shading. Default: |
None
|
lty
|
str | Sequence[str] | None
|
Line types: for a fitted model |
None
|
fonts
|
str | tuple[str, int] | Sequence[str | tuple[str, int]] | Mapping[str, int] | None
|
Font family and font of the study labels, the annotations and the |
None
|
cex
|
float | None
|
Character expansion factor of the text and symbols. Default: 1, reduced when the number of rows would not fit on the axes
(so the returned |
None
|
cex_lab
|
float | None
|
Character expansion factor of the x-axis label. Default: the value of |
None
|
cex_axis
|
float | None
|
Character expansion factor of the x-axis tick labels. Default: the value of |
None
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
predtail
|
float | str | None
|
Cut point of the shading for |
None
|
annosym
|
Sequence[str] | None
|
Symbols of the annotations: left bracket, separator and right bracket (default |
None
|
tabfig
|
int | None
|
|
None
|
textpos
|
Sequence[float] | None
|
|
None
|
rowadj
|
float | Sequence[float] | None
|
Vertical adjustment of the study labels, the annotations and the |
None
|
top
|
float
|
Number of rows above the first study (for the headings). Default: 3. |
3
|
at_lab
|
Sequence[str] | None
|
Labels of the tick marks, one per position. Default: the ( |
None
|
xlabadj
|
float | Sequence[float] | None
|
Alignment of the left and right x-axis labels when two or three labels are given: 0 (left aligned), 1 (right aligned) or another value (centred), for the left label, the right label getting 1 minus that; or a pair for the two labels. Default: centred. |
None
|
xlabfont
|
int | Sequence[int]
|
Font (1 to 4 as in |
1
|
decreasing
|
bool
|
Sort in decreasing order when |
False
|
measure
|
str | None
|
Vector form only: the measure used for the axis label and the header. Default: the |
None
|
slab_null
|
bool | None
|
Vector form only: whether the labels are the default ones (which gives the study labels less room). Default: |
None
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with studies dropped for missing values (metafor's |
'omit'
|
predtype
|
str | None
|
Type of prediction interval passed on to predict: |
None
|
pi_type
|
str | None
|
Old spelling of |
None
|
addcred
|
bool | str | int | Sequence[str | int] | None
|
Old spelling of |
None
|
clim
|
Sequence[float] | None
|
Old spelling of |
None
|
Returns:
| Type | Description |
|---|---|
ForestResult
|
A |
ForestResult
|
|
ForestResult
|
annotation areas; |
Raises:
| Type | Description |
|---|---|
NotSupportedError
|
|
InputError
|
summary_cols ¶
summary_cols(
col: Any, border: Any, predstyle: str = 'line'
) -> tuple[list[str | None], list[str | None]]
The colours of a summary polygon and its prediction interval: col (polygon, interval, shade end or below predtail, above it) and border.
draw_pred ¶
draw_pred(
ax: Axes,
style: Literal[
'line', 'polygon', 'bar', 'shade', 'dist'
],
lb: float,
ub: float,
mid: float,
row: float,
geo: PredGeometry,
lty: str,
col: Sequence[str | None],
border: Sequence[str | None],
curve: PredCurve | None = None,
) -> None
The prediction interval of a summary (line, polygon, bar, shade or dist; col and border from :func:summary_cols).
Raises:
| Type | Description |
|---|---|
InputError
|
|
forest_summary ¶
forest_summary(
model: Any,
level: float,
addpred: bool,
pred_levels: list[str | int] | None,
predtype: str | None = None,
pi_type: str | None = None,
) -> PredictResult
The summary estimate (and prediction interval) drawn below the studies, as forest.rma computes it.
For an rma.mv model with several tau2 (or gamma2) values the prediction interval needs the levels of the
inner factor(s), given via addpred; without them the first values are used (and only the CI is drawn).
Raises:
| Type | Description |
|---|---|
InputError
|
|
widen ¶
a spread over k rows, at the positions at and missing elsewhere (the studies of a fit among those dropped for missing values).
per_study ¶
Select the entries of a per-study argument that correspond to the studies used in the fit.
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
addpoly ¶
addpoly(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult
| PredictResult
| ArrayLike,
vi: ArrayLike | None = None,
sei: ArrayLike | None = None,
ci_lb: ArrayLike | None = None,
ci_ub: ArrayLike | None = None,
pi_lb: ArrayLike | None = None,
pi_ub: ArrayLike | None = None,
rows: ArrayLike | float | None = None,
row: float = -2,
level: float | None = None,
annotate: bool | None = None,
addpred: bool = False,
predstyle: str | None = None,
predlim: Sequence[float] | None = None,
digits: int | Sequence[float] | None = None,
width: int | Sequence[int] | None = None,
mlab: str | Sequence[str] | None = None,
transf: Callable[..., Any] | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
efac: float | Sequence[float] | None = None,
col: str | Sequence[str] | None = None,
border: str | Sequence[str] | None = None,
lty: str | Sequence[str] | None = None,
fonts: str
| tuple[str, int]
| Sequence[str | tuple[str, int]]
| Mapping[str, int]
| None = None,
cex: float | None = None,
constarea: bool = False,
*,
ax: Axes | None = None,
preddist: tuple[ArrayLike, ArrayLike]
| Mapping[str, Any]
| None = None,
predtail: float | str | None = None,
pi_se: float | None = None,
pi_dist: str = 'norm',
pi_ddf: float | None = None,
pi_level: float | None = None,
alim: Sequence[float] | None = None,
olim: Sequence[float] | None = None,
annosym: Sequence[str] | None = None,
textpos: Sequence[float] | None = None,
rowadj: float | Sequence[float] | None = None,
lcol: str | Sequence[str] | None = None,
predtype: str | None = None,
pi_type: str | None = None,
addcred: bool | None = None,
cr_lb: ArrayLike | None = None,
cr_ub: ArrayLike | None = None,
) -> Axes
Add polygons (summary estimates) to a forest plot (addpoly.rma, addpoly.predict.rma and addpoly.default).
Mirrors metafor's addpoly(). Options not given (alim, digits,
width, annotate, transf, atransf, targs, efac, fonts, cex, annosym, textpos, rowadj, olim, ...) are
taken from the last forest call on the same axes; without one the limits of the axes are used. Unlike R there is no
predstyle='line2' and no tabfig argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult | PredictResult | ArrayLike
|
A fitted model without moderators (its pooled estimate and confidence interval are drawn at |
required |
vi
|
ArrayLike | None
|
Sampling variances of the estimates in |
None
|
sei
|
ArrayLike | None
|
Standard errors of the estimates in |
None
|
ci_lb
|
ArrayLike | None
|
Lower confidence interval bounds (vector form only; used with |
None
|
ci_ub
|
ArrayLike | None
|
Upper confidence interval bounds (vector form only). |
None
|
pi_lb
|
ArrayLike | None
|
Lower prediction interval bounds (vector form only). The prediction intervals of a vector |
None
|
pi_ub
|
ArrayLike | None
|
Upper prediction interval bounds (vector form only). |
None
|
rows
|
ArrayLike | float | None
|
Rows (vertical positions) of the polygons, one per estimate, or a single value for the first (the others follow below it).
Default: |
None
|
row
|
float
|
Row of the polygon of a fitted model. Default: -2. |
-2
|
level
|
float | None
|
Confidence interval level: 95, 0.95 and 0.05 all give a 95% interval. Default: that of the model; for a vector |
None
|
annotate
|
bool | None
|
Add the annotation (estimate and interval) on the right. Default: as in the last forest call, else |
None
|
addpred
|
bool
|
Fitted model or |
False
|
predstyle
|
str | None
|
Style of the prediction interval: |
None
|
predlim
|
Sequence[float] | None
|
Limits |
None
|
digits
|
int | Sequence[float] | None
|
Number of decimals of the annotation; only the first value of a sequence is used. Default: as in the last forest call, else 2. |
None
|
width
|
int | Sequence[int] | None
|
Minimum width (number of characters) of the annotation columns. Default: the widths of the last forest call (so the annotations line up with those of the studies). |
None
|
mlab
|
str | Sequence[str] | None
|
Label of the polygon(s), one string per polygon (a fitted model: one string). Default: the label for the method of a fitted
model, none for a vector |
None
|
transf
|
Callable[..., Any] | None
|
Function applied to the estimates and interval bounds before drawing. Default: as in the last forest call. |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the annotations only (the axis is not touched). Default: as in the last forest call. Cannot be used together
with |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
efac
|
float | Sequence[float] | None
|
Vertical expansion factors, |
None
|
col
|
str | Sequence[str] | None
|
Colour of the polygon: one value per polygon. For a single polygon up to four values as for |
None
|
border
|
str | Sequence[str] | None
|
Border colour of the polygon (one value per polygon; for a single polygon a second value is the border colour of the prediction interval). Default: black. |
None
|
lty
|
str | Sequence[str] | None
|
Line types of the prediction interval for |
None
|
fonts
|
str | tuple[str, int] | Sequence[str | tuple[str, int]] | Mapping[str, int] | None
|
Fonts of the labels and annotations, as in forest (the first entry for the labels, the second for the annotations). Default: those of the last forest call. |
None
|
cex
|
float | None
|
Character expansion factor. Default: that of the last forest call, else 1 or less, as small as the height of the axes needs. |
None
|
constarea
|
bool
|
Draw the polygons with a constant area (the height shrinks as the interval widens) rather than a constant height.
Default: |
False
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
preddist
|
tuple[ArrayLike, ArrayLike] | Mapping[str, Any] | None
|
Predictive distribution for |
None
|
predtail
|
float | str | None
|
Cut point of the shading for |
None
|
pi_se
|
float | None
|
Vector form only: standard error of the predictive distribution, for |
None
|
pi_dist
|
str
|
Vector form only: the predictive distribution, |
'norm'
|
pi_ddf
|
float | None
|
Vector form only: degrees of freedom of the |
None
|
pi_level
|
float | None
|
Vector form only: level of the prediction interval, as |
None
|
alim
|
Sequence[float] | None
|
Limits of the x axis: polygons are cut off at them. Default: taken from the last forest call, else the limits of the axes. |
None
|
olim
|
Sequence[float] | None
|
Limits |
None
|
annosym
|
Sequence[str] | None
|
Symbols of the annotations, as in forest (three, four or five strings). Default: as in the last forest call. |
None
|
textpos
|
Sequence[float] | None
|
|
None
|
rowadj
|
float | Sequence[float] | None
|
Vertical adjustment of the labels and of the annotations; one value for both, or two. Default: as in the last forest call. |
None
|
lcol
|
str | Sequence[str] | None
|
Colour of the prediction interval line, its end bars and arrows for |
None
|
predtype
|
str | None
|
Type of prediction interval passed on to predict for a fitted model: |
None
|
pi_type
|
str | None
|
Old spelling of |
None
|
addcred
|
bool | None
|
Old spelling of |
None
|
cr_lb
|
ArrayLike | None
|
Old spelling of |
None
|
cr_ub
|
ArrayLike | None
|
Old spelling of |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The matplotlib axes drawn into. |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid: a fitted model with moderators; a |
addpoly ¶
addpoly(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult
| PredictResult
| ArrayLike,
vi: ArrayLike | None = None,
sei: ArrayLike | None = None,
ci_lb: ArrayLike | None = None,
ci_ub: ArrayLike | None = None,
pi_lb: ArrayLike | None = None,
pi_ub: ArrayLike | None = None,
rows: ArrayLike | float | None = None,
row: float = -2,
level: float | None = None,
annotate: bool | None = None,
addpred: bool = False,
predstyle: str | None = None,
predlim: Sequence[float] | None = None,
digits: int | Sequence[float] | None = None,
width: int | Sequence[int] | None = None,
mlab: str | Sequence[str] | None = None,
transf: Callable[..., Any] | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
efac: float | Sequence[float] | None = None,
col: str | Sequence[str] | None = None,
border: str | Sequence[str] | None = None,
lty: str | Sequence[str] | None = None,
fonts: str
| tuple[str, int]
| Sequence[str | tuple[str, int]]
| Mapping[str, int]
| None = None,
cex: float | None = None,
constarea: bool = False,
*,
ax: Axes | None = None,
preddist: tuple[ArrayLike, ArrayLike]
| Mapping[str, Any]
| None = None,
predtail: float | str | None = None,
pi_se: float | None = None,
pi_dist: str = 'norm',
pi_ddf: float | None = None,
pi_level: float | None = None,
alim: Sequence[float] | None = None,
olim: Sequence[float] | None = None,
annosym: Sequence[str] | None = None,
textpos: Sequence[float] | None = None,
rowadj: float | Sequence[float] | None = None,
lcol: str | Sequence[str] | None = None,
predtype: str | None = None,
pi_type: str | None = None,
addcred: bool | None = None,
cr_lb: ArrayLike | None = None,
cr_ub: ArrayLike | None = None,
) -> Axes
Add polygons (summary estimates) to a forest plot (addpoly.rma, addpoly.predict.rma and addpoly.default).
Mirrors metafor's addpoly(). Options not given (alim, digits,
width, annotate, transf, atransf, targs, efac, fonts, cex, annosym, textpos, rowadj, olim, ...) are
taken from the last forest call on the same axes; without one the limits of the axes are used. Unlike R there is no
predstyle='line2' and no tabfig argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult | PredictResult | ArrayLike
|
A fitted model without moderators (its pooled estimate and confidence interval are drawn at |
required |
vi
|
ArrayLike | None
|
Sampling variances of the estimates in |
None
|
sei
|
ArrayLike | None
|
Standard errors of the estimates in |
None
|
ci_lb
|
ArrayLike | None
|
Lower confidence interval bounds (vector form only; used with |
None
|
ci_ub
|
ArrayLike | None
|
Upper confidence interval bounds (vector form only). |
None
|
pi_lb
|
ArrayLike | None
|
Lower prediction interval bounds (vector form only). The prediction intervals of a vector |
None
|
pi_ub
|
ArrayLike | None
|
Upper prediction interval bounds (vector form only). |
None
|
rows
|
ArrayLike | float | None
|
Rows (vertical positions) of the polygons, one per estimate, or a single value for the first (the others follow below it).
Default: |
None
|
row
|
float
|
Row of the polygon of a fitted model. Default: -2. |
-2
|
level
|
float | None
|
Confidence interval level: 95, 0.95 and 0.05 all give a 95% interval. Default: that of the model; for a vector |
None
|
annotate
|
bool | None
|
Add the annotation (estimate and interval) on the right. Default: as in the last forest call, else |
None
|
addpred
|
bool
|
Fitted model or |
False
|
predstyle
|
str | None
|
Style of the prediction interval: |
None
|
predlim
|
Sequence[float] | None
|
Limits |
None
|
digits
|
int | Sequence[float] | None
|
Number of decimals of the annotation; only the first value of a sequence is used. Default: as in the last forest call, else 2. |
None
|
width
|
int | Sequence[int] | None
|
Minimum width (number of characters) of the annotation columns. Default: the widths of the last forest call (so the annotations line up with those of the studies). |
None
|
mlab
|
str | Sequence[str] | None
|
Label of the polygon(s), one string per polygon (a fitted model: one string). Default: the label for the method of a fitted
model, none for a vector |
None
|
transf
|
Callable[..., Any] | None
|
Function applied to the estimates and interval bounds before drawing. Default: as in the last forest call. |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the annotations only (the axis is not touched). Default: as in the last forest call. Cannot be used together
with |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
efac
|
float | Sequence[float] | None
|
Vertical expansion factors, |
None
|
col
|
str | Sequence[str] | None
|
Colour of the polygon: one value per polygon. For a single polygon up to four values as for |
None
|
border
|
str | Sequence[str] | None
|
Border colour of the polygon (one value per polygon; for a single polygon a second value is the border colour of the prediction interval). Default: black. |
None
|
lty
|
str | Sequence[str] | None
|
Line types of the prediction interval for |
None
|
fonts
|
str | tuple[str, int] | Sequence[str | tuple[str, int]] | Mapping[str, int] | None
|
Fonts of the labels and annotations, as in forest (the first entry for the labels, the second for the annotations). Default: those of the last forest call. |
None
|
cex
|
float | None
|
Character expansion factor. Default: that of the last forest call, else 1 or less, as small as the height of the axes needs. |
None
|
constarea
|
bool
|
Draw the polygons with a constant area (the height shrinks as the interval widens) rather than a constant height.
Default: |
False
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
preddist
|
tuple[ArrayLike, ArrayLike] | Mapping[str, Any] | None
|
Predictive distribution for |
None
|
predtail
|
float | str | None
|
Cut point of the shading for |
None
|
pi_se
|
float | None
|
Vector form only: standard error of the predictive distribution, for |
None
|
pi_dist
|
str
|
Vector form only: the predictive distribution, |
'norm'
|
pi_ddf
|
float | None
|
Vector form only: degrees of freedom of the |
None
|
pi_level
|
float | None
|
Vector form only: level of the prediction interval, as |
None
|
alim
|
Sequence[float] | None
|
Limits of the x axis: polygons are cut off at them. Default: taken from the last forest call, else the limits of the axes. |
None
|
olim
|
Sequence[float] | None
|
Limits |
None
|
annosym
|
Sequence[str] | None
|
Symbols of the annotations, as in forest (three, four or five strings). Default: as in the last forest call. |
None
|
textpos
|
Sequence[float] | None
|
|
None
|
rowadj
|
float | Sequence[float] | None
|
Vertical adjustment of the labels and of the annotations; one value for both, or two. Default: as in the last forest call. |
None
|
lcol
|
str | Sequence[str] | None
|
Colour of the prediction interval line, its end bars and arrows for |
None
|
predtype
|
str | None
|
Type of prediction interval passed on to predict for a fitted model: |
None
|
pi_type
|
str | None
|
Old spelling of |
None
|
addcred
|
bool | None
|
Old spelling of |
None
|
cr_lb
|
ArrayLike | None
|
Old spelling of |
None
|
cr_ub
|
ArrayLike | None
|
Old spelling of |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
The matplotlib axes drawn into. |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid: a fitted model with moderators; a |
funnel ¶
Funnel plots (metafor's funnel.rma and funnel.default).
Plots the observed effects against a measure of their precision (standard error, variance, their
inverses, sample size, weight, ...); for sei, vi, seinv and vinv the pseudo
confidence-interval regions around the reference line are drawn (level may be a vector for
contour-enhanced funnel plots, with shade the colours of the regions). For a fitted model with
moderators the residuals are plotted; a trim-and-fill result (an :class:~metafopy.RMAResult with a
boolean fill attribute) shows the imputed studies as open symbols.
See https://wviechtb.github.io/metafor/reference/funnel.html, Sterne & Egger (2001), doi:10.1016/S0895-4356(01)00377-8 and Peters et al. (2008), doi:10.1016/j.jclinepi.2007.11.010.
FunnelResult
dataclass
¶
FunnelResult(
ax: Axes,
x: FloatArray,
y: FloatArray,
slab: tuple[str, ...],
fill: NDArray[bool_] | None = None,
)
The plotted coordinates (what metafor's funnel() returns invisibly) and the axes drawn on.
x holds the observed outcomes (or residuals), y the values on the vertical axis,
fill marks imputed studies of a trim-and-fill result (None otherwise).
yvalues ¶
yvalues(
yaxis: str,
sei: NDArray[float64],
vi: NDArray[float64],
ni: NDArray[float64] | None,
weights: NDArray[float64] | None,
) -> NDArray[float64]
The values plotted on the vertical axis.
funnel ¶
funnel(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult
| ArrayLike,
vi: ArrayLike | None = None,
sei: ArrayLike | None = None,
ni: ArrayLike | None = None,
subset: ArrayLike | None = None,
yaxis: str = 'sei',
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
xlab: str | None = None,
ylab: str | None = None,
slab: Sequence[Any] | None = None,
steps: int = 5,
at: ArrayLike | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
digits: int | Sequence[int] | None = None,
level: float | Sequence[float] | None = None,
addtau2: bool = False,
type: str = 'rstandard',
back: str | None = None,
shade: str | Sequence[str] | None = None,
hlines: str | None = None,
refline: float | None = None,
lty: Any = 3,
pch: int | Sequence[int] | None = None,
pch_fill: int = 21,
col: str | Sequence[str] | None = None,
bg: str | Sequence[str] | None = None,
label: bool | int | str = False,
offset: float = 0.4,
legend: bool | str | dict[str, Any] = False,
*,
ax: Axes | None = None,
refline2: float | None = None,
level2: float | None = None,
lty2: Any = 3,
ci_res: int = 1000,
colref: str | None = None,
colci: str | None = None,
colbox: str | None = None,
at_lab: Sequence[str] | None = None,
measure: str | None = None,
main: str | None = None,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
transf: Any = None,
) -> FunnelResult
Funnel plot of a fitted model (funnel.rma) or of estimates with their variances (funnel.default).
Mirrors metafor's funnel().
yaxis is one of 'sei' (default), 'vi', 'seinv', 'vinv', 'ni',
'ninv', 'sqrtni', 'sqrtninv', 'lni' or 'wi'. level (a percentage; a
vector draws several CI regions, a contour-enhanced funnel plot) defaults to the confidence
level of the model (95 for the numeric form), shade colours the regions (back the
background of the plotting region), refline is the reference line (the pooled estimate, or 0 for models
with moderators and the numeric form), addtau2 adds the model's tau^2 to the sampling
variances in the CI regions, label (True/'all', 'out' or the number of the
most extreme studies) labels points with slab, and type selects the residuals plotted
for models with moderators ('rstandard' or 'rstudent'). Pass ni (or fit the model with
ni) for the sample-size axes. For a trim-and-fill result the imputed studies are drawn
with symbol pch_fill (by default a circle with a grey fill). main is the title of the plot. legend is only approximated (a matplotlib legend).
transf only warns, as in metafor (use atransf).
na_action stands for R's options(na.action=): estimates with missing values are left out, except for 'fail', which stops; it has no effect
on a fitted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult | ArrayLike
|
A fitted model ( |
required |
vi
|
ArrayLike | None
|
Sampling variances of the effect sizes in |
None
|
sei
|
ArrayLike | None
|
Standard errors of the effect sizes in |
None
|
ni
|
ArrayLike | None
|
Sample sizes, for the sample-size |
None
|
subset
|
ArrayLike | None
|
Which of the effect sizes to plot: a boolean array or an array of 0-based indices (vector form only, ignored for a fitted model). |
None
|
yaxis
|
str
|
Quantity on the vertical axis: |
'sei'
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis as (low, high). Default: wide enough for the confidence region at the bottom of the plot and the points, extended by 10 percent on each side. |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high), in either order; they must be >= 0 (> 0 for |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: derived from the effect size measure, or |
None
|
ylab
|
str | None
|
Label of the vertical axis. Default: derived from |
None
|
slab
|
Sequence[Any] | None
|
Study labels (for |
None
|
steps
|
int
|
Number of tick marks of the vertical axis (and of the horizontal grid lines). Default: 5. |
5
|
at
|
ArrayLike | None
|
Positions of the tick marks of the horizontal axis (those outside its range are dropped). Default: chosen automatically. |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the horizontal-axis tick labels only (for example |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
digits
|
int | Sequence[int] | None
|
Number of decimals of the tick labels: one integer for both axes or two (horizontal axis, vertical axis). Default: 2 and 3 (2 and 0
for |
None
|
level
|
float | Sequence[float] | None
|
Confidence level(s) in percent of the pseudo confidence regions (95 or 0.95 for 95 percent). A vector draws several regions, for a contour-enhanced funnel plot. Default: the level of the model (95 for the vector form). |
None
|
addtau2
|
bool
|
Add the model's |
False
|
type
|
str
|
Residuals plotted for models with moderators: |
'rstandard'
|
back
|
str | None
|
Colour of the plotting-region background. Default: light grey. (metafor's |
None
|
shade
|
str | Sequence[str] | None
|
Colour of the confidence regions; one colour per |
None
|
hlines
|
str | None
|
Colour of the horizontal lines at the vertical-axis ticks. Default: white. |
None
|
refline
|
float | None
|
Position of the vertical reference line, around which the confidence region is centred. Default: the pooled estimate, or 0 for models with moderators (where residuals are plotted) and the vector form. |
None
|
lty
|
Any
|
Line type of the confidence region boundaries and of the reference line: one value for both or a pair (boundaries, reference line).
Default: 3, dotted. Accepts R names ( |
3
|
pch
|
int | Sequence[int] | None
|
Plotting symbol of the points (R's |
None
|
pch_fill
|
int
|
Plotting symbol of the imputed studies of a trim-and-fill result. Default: 21, a circle with border |
21
|
col
|
str | Sequence[str] | None
|
Border colour of the points, or one per study (a matplotlib colour). For a trim-and-fill result a pair (observed, imputed); a single colour then applies to the observed studies. Default: black. |
None
|
bg
|
str | Sequence[str] | None
|
Fill colour of the points for symbols with a separate fill, or one per study; a pair (observed, imputed) for a trim-and-fill result. Default: light grey (a darker grey for the observed studies of a trim-and-fill result). |
None
|
label
|
bool | int | str
|
Label points with the study labels: |
False
|
offset
|
float
|
Distance of the labels from the points, as a fraction of the character size (R's |
0.4
|
legend
|
bool | str | dict[str, Any]
|
Add a legend: |
False
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
refline2
|
float | None
|
Position of a second reference line, with its own confidence region for the four confidence-region |
None
|
level2
|
float | None
|
Confidence level in percent of the region around |
None
|
lty2
|
Any
|
Line type of the second reference line and its region. Default: 3, dotted. |
3
|
ci_res
|
int
|
Number of points used to draw the confidence region boundaries. Default: 1000. |
1000
|
colref
|
str | None
|
Colour of the reference line(s). Default: grey. |
None
|
colci
|
str | None
|
Colour of the confidence region boundaries. Default: grey. |
None
|
colbox
|
str | None
|
Colour of the left and bottom axis lines (metafor's L-shaped box). Default: grey. |
None
|
at_lab
|
Sequence[str] | None
|
Labels for the horizontal-axis tick marks, replacing the computed labels (give one per mark of |
None
|
measure
|
str | None
|
Vector form only: the effect size measure, used for the default horizontal-axis label. Default: the measure stored with |
None
|
main
|
str | None
|
Title of the plot. Default: none. |
None
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with missing values (R's |
'omit'
|
transf
|
Any
|
Not available, as in metafor: only gives a warning (use |
None
|
Returns:
| Type | Description |
|---|---|
FunnelResult
|
The plotted coordinates and the axes ( |
Raises:
| Type | Description |
|---|---|
InputError
|
|
NotSupportedError
|
|
funnel_legend ¶
funnel_legend(
ax: Axes,
legend: bool | str | dict[str, Any],
level: list[float],
shade: list[str],
back: str,
yaxis: str,
trimfill: bool,
pch: list[Any],
col: list[Any],
bg: list[Any],
pch_fill: int,
pch_vec: bool,
col_vec: bool,
bg_vec: bool,
colci: str,
) -> None
An approximation of metafor's funnel legend (CI-region p-value/CI entries and the study symbols).
labbe ¶
L'Abbe plot (metafor's labbe.rma).
Plots the arm-level outcomes (log risks, log odds, risks, arcsine-transformed risks or the corresponding incidence rate measures) of the two groups of each study against each other, with a line for the estimated effect, see L'Abbe et al. (1987), doi:10.7326/0003-4819-107-2-224 and https://wviechtb.github.io/metafor/reference/labbe.html.
LabbeResult
dataclass
¶
LabbeResult(
ax: Axes,
x: FloatArray,
y: FloatArray,
cex: FloatArray,
pch: tuple[int, ...],
col: tuple[str, ...],
bg: tuple[str, ...],
ids: tuple[int, ...],
slab: tuple[str, ...],
)
The plotted arm-level outcomes and point attributes (metafor's invisible return value) and the axes drawn on.
Rows
dataclass
¶
Rows(
k: int,
k_all: int,
keep: NDArray[bool_],
ids: tuple[int, ...],
slab: tuple[str, ...],
counts: dict[str, FloatArray] | None,
frame: DataFrame | None,
)
The studies a L'Abbe plot draws: k of the k_all supplied rows (keep), with their 1-based ids and labels.
counts holds the arm-level counts kept by an rma_mh, rma_peto or rma_glmm fit, or by an rma_uni fit computed from counts
(None for an rma_uni fit of yi and vi, whose counts come from its data); frame is the data the model was fitted to.
column ¶
The counts name for the studies of the model (stored in the model, a column of the model's data, or an array).
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
labbe ¶
labbe(
x: RMAResult | FixedBinaryResult | GLMMResult,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
lim: Sequence[float] | None = None,
xlab: str | None = None,
ylab: str | None = None,
flip: bool = False,
ci: bool | str = False,
pi: bool | str = False,
grid: bool | str = False,
legend: bool | str | dict[str, Any] = False,
add: float | None = None,
to: str | None = None,
transf: Callable[..., Any] | None = None,
targs: Any = None,
pch: int | Sequence[int] = 21,
psize: float | Sequence[float] | None = None,
plim: Sequence[float] = (0.5, 3.5),
col: str | Sequence[str] | None = None,
bg: str | Sequence[str] | None = None,
lty: str | Sequence[str] | None = None,
*,
ai: ArrayLike | str | None = None,
bi: ArrayLike | str | None = None,
ci_counts: ArrayLike | str | None = None,
di: ArrayLike | str | None = None,
x1i: ArrayLike | str | None = None,
x2i: ArrayLike | str | None = None,
t1i: ArrayLike | str | None = None,
t2i: ArrayLike | str | None = None,
llim: Sequence[float] | None = None,
addyi: bool = True,
addvi: bool = True,
ax: Axes | None = None,
bty: str = 'o',
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> LabbeResult
L'Abbe plot of a model without moderators fitted to 2x2 table data or incidence rates (labbe.rma).
Mirrors metafor's labbe().
x is an rma_uni, rma_mh or rma_glmm fit (rma_peto fits have measure='PETO', which has no
arm-level outcomes). rma_mh and rma_glmm fits keep the counts, and add/to default to the model's (for an rma_uni fit they
do not, unlike metafor).
The model's measure must be 'RR', 'OR', 'RD', 'AS', 'IRR', 'IRD' or 'IRSD'.
A fitted RMAResult does not keep the raw counts, so they are taken from the columns
ai, bi, ci, di (x1i, t1i, x2i, t2i for the rate measures) of the data the model
was fitted to, or passed as the keyword arguments ai, bi, ci_counts (the ci counts; ci
itself draws the confidence region as in metafor), di, x1i, x2i, t1i and t2i (column names or
arrays). ci and pi shade the confidence and prediction interval of the line of the estimated effect
(a colour string sets the colour), flip swaps the groups, psize/plim set the point sizes (default:
proportional to the precision between plim), transf is applied to the arm-level outcomes, and
add and to (see below for the defaults), lim/llim as in metafor. bty is the type of box around
the plot ('o', 'l', '7', 'c', 'u', ']' or 'n'),
which metafor passes on to plot(). na_action stands for R's options(na.action=); an unknown value
raises, as in metafor, and every valid value gives the same result (metafor sets na.pass while it computes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | FixedBinaryResult | GLMMResult
|
A model without moderators fitted by rma_uni, |
required |
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis (the outcome in group 1) as (low, high). Default: the range of all the arm-level outcomes. |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis (the outcome in group 2) as (low, high). Default: the range of all the arm-level outcomes. |
None
|
lim
|
Sequence[float] | None
|
Limits of both axes as (low, high); used instead of |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: derived from the measure, with |
None
|
ylab
|
str | None
|
Label of the vertical axis. Default: derived from the measure, with |
None
|
flip
|
bool
|
Swap the groups plotted on the two axes. Default: |
False
|
ci
|
bool | str
|
Shade the confidence region of the line of the estimated effect; a colour string sets the colour (default light grey). Default: |
False
|
pi
|
bool | str
|
Shade the prediction region of the line of the estimated effect; a colour string sets the colour (default lighter grey). Default: |
False
|
grid
|
bool | str
|
Add a grid. |
False
|
legend
|
bool | str | dict[str, Any]
|
Add a legend: |
False
|
add
|
float | None
|
Constant added to the cell counts (see escalc). Default: for |
None
|
to
|
str | None
|
Which tables get |
None
|
transf
|
Callable[..., Any] | None
|
Function applied to the arm-level outcomes (and to the lines) before they are plotted, for example |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
pch
|
int | Sequence[int]
|
Plotting symbol of the points (R's |
21
|
psize
|
float | Sequence[float] | None
|
Sizes (expansion factors) of the points, a number or one per study. Default: proportional to the precision (inverse standard error of the
difference), rescaled to |
None
|
plim
|
Sequence[float]
|
Range (min, max) of the point sizes when |
(0.5, 3.5)
|
col
|
str | Sequence[str] | None
|
Border colour of the points, or one per study (a matplotlib colour). Default: black. |
None
|
bg
|
str | Sequence[str] | None
|
Fill colour of the points for symbols with a separate fill, or one per study. Default: grey. |
None
|
lty
|
str | Sequence[str] | None
|
Line types of the line of equality (no effect) and of the line of the estimated effect, as a pair (one value serves both). Default:
|
None
|
ai
|
ArrayLike | str | None
|
Counts of the upper left cells (column name of the data the model was fitted to, or array); only needed if the model does not keep the counts
and its data have no |
None
|
bi
|
ArrayLike | str | None
|
Counts of the upper right cells (column name or array); as |
None
|
ci_counts
|
ArrayLike | str | None
|
Counts of the lower left cells (column name or array); as |
None
|
di
|
ArrayLike | str | None
|
Counts of the lower right cells (column name or array); as |
None
|
x1i
|
ArrayLike | str | None
|
Number of events in group 1 (rate measures); as |
None
|
x2i
|
ArrayLike | str | None
|
Number of events in group 2 (rate measures); as |
None
|
t1i
|
ArrayLike | str | None
|
Person-times of group 1 (rate measures); as |
None
|
t2i
|
ArrayLike | str | None
|
Person-times of group 2 (rate measures); as |
None
|
llim
|
Sequence[float] | None
|
Limits (low, high) of the line of the estimated effect that is drawn, in arm-level outcome units (length 2). Default: chosen from the measure. |
None
|
addyi
|
bool
|
Passed to escalc: apply |
True
|
addvi
|
bool
|
Passed to escalc: apply |
True
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
bty
|
str
|
Type of box around the plot: |
'o'
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
R's |
'omit'
|
Returns:
| Type | Description |
|---|---|
LabbeResult
|
A |
LabbeResult
|
colours |
Raises:
| Type | Description |
|---|---|
InputError
|
|
NotSupportedError
|
|
radial ¶
Radial (Galbraith) plot (metafor's radial.rma).
Plots the standardised effects z_i = y_i / sqrt(v_i + tau^2) against the precisions x_i = 1 / sqrt(v_i + tau^2);
the slope of the line through the origin and a point is the estimate, shown on the arc to the right. See
Galbraith (1988), doi:10.1080/00401706.1988.10488400, and
https://wviechtb.github.io/metafor/reference/radial.html.
RadialResult
dataclass
¶
RadialResult(
ax: Axes,
x: FloatArray,
y: FloatArray,
ids: tuple[int, ...],
slab: tuple[str, ...],
)
The plotted coordinates of a radial plot (metafor's invisible return value) and the axes drawn on.
arc ¶
Points on the arc of radius len_ (in the metric of the plot) at the slopes at.
radial ¶
radial(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult,
center: bool = False,
xlim: Sequence[float] | None = None,
zlim: Sequence[float] | None = None,
xlab: str | None = None,
zlab: str | None = None,
atz: ArrayLike | None = None,
aty: ArrayLike | None = None,
steps: int = 7,
level: float | None = None,
digits: int = 2,
transf: Callable[..., Any] | None = None,
targs: Any = None,
pch: int = 21,
col: str | None = None,
bg: str | None = None,
back: str | None = None,
arc_res: int | Sequence[int] = 100,
cex: float | None = None,
cex_lab: float | None = None,
cex_axis: float | None = None,
*,
ax: Axes | None = None,
) -> RadialResult
Radial (Galbraith) plot of a model without moderators (radial.rma); metafopy.plot.galbraith is an alias.
Mirrors metafor's radial().
center plots the deviations from the pooled estimate, atz/aty set the ticks of the z-axis and
the values on the arc (aty in the units of the effect sizes, transf is applied to the arc labels),
steps the number of arc ticks, level the confidence level of the shaded band (default: the model's),
digits the digits of the arc labels and arc_res the resolution of the arcs (a second number sets that
of the confidence interval arc, default a quarter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult
|
A fitted model without moderators (not a robust, |
required |
center
|
bool
|
Plot the standardized deviations from the pooled estimate, which centers the plot horizontally at the pooled estimate. Default: |
False
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis (the precision). Default: 0 to 1.3 times the largest precision. |
None
|
zlim
|
Sequence[float] | None
|
Limits of the vertical axis (the standardized effects); these are the actual limits of the plotting region. Default: derived from the data, at least -5 to 5. |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: derived from the model (a math-text label). |
None
|
zlab
|
str | None
|
Label of the vertical axis. Default: derived from the model and |
None
|
atz
|
ArrayLike | None
|
Positions of the tick marks and labels of the vertical axis (those outside |
None
|
aty
|
ArrayLike | None
|
Positions (in the units of the effect sizes, before |
None
|
steps
|
int
|
Number of tick marks on the arc. Default: 7. |
7
|
level
|
float | None
|
Confidence level of the shaded band (the z-axis error region), between 0 and 100 (95 or 0.95 for 95 percent). Default: the level of the model. |
None
|
digits
|
int
|
Number of decimals of the arc labels. Default: 2. |
2
|
transf
|
Callable[..., Any] | None
|
Function applied to the arc labels. |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
pch
|
int
|
Plotting symbol of the points (R's |
21
|
col
|
str | None
|
Border colour of the points (a matplotlib colour). Default: the foreground colour (black). |
None
|
bg
|
str | None
|
Fill colour of the points for symbols with a separate fill. Default: a grey adjusted from the background. |
None
|
back
|
str | None
|
Colour of the shaded band. Default: a light grey. (metafor's |
None
|
arc_res
|
int | Sequence[int]
|
Number of points used to draw the arc of the estimates; a second value sets that of the confidence interval arc. Default: 100 and, when one number is given, a quarter of it (rounded up) for the confidence interval arc. |
100
|
cex
|
float | None
|
Expansion factor of the point symbols only (as in metafor). Default: 1. |
None
|
cex_lab
|
float | None
|
Expansion factor of the axis labels. Default: 1. |
None
|
cex_axis
|
float | None
|
Expansion factor of the tick labels (the labels of the arc are drawn at 0.85 times this). Default: 1. |
None
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
Returns:
| Type | Description |
|---|---|
RadialResult
|
The plotted values: |
Raises:
| Type | Description |
|---|---|
InputError
|
the model has moderators, |
NotSupportedError
|
|
ArgumentError
|
|
baujat ¶
Baujat plot (metafor's baujat.rma).
Plots each study's contribution to the overall heterogeneity (squared Pearson residual) against its influence on the pooled result (the standardised squared change in the fitted value when the study is left out), see Baujat et al. (2002), doi:10.1002/sim.1221, and https://wviechtb.github.io/metafor/reference/baujat.html.
BaujatResult
dataclass
¶
BaujatResult(
ax: Axes,
x: FloatArray,
y: FloatArray,
ids: tuple[int, ...],
slab: tuple[str, ...],
)
The plotted coordinates of a Baujat plot (what metafor's baujat() returns invisibly) and the axes drawn on.
baujat ¶
baujat(
x: RMAResult | FixedBinaryResult,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
xlab: str | None = None,
ylab: str | None = None,
cex: float | None = None,
symbol: str | int | Sequence[int] = 'ids',
grid: bool | str = True,
progbar: bool = False,
*,
ax: Axes | None = None,
bty: str = 'o',
las: int | None = None,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> BaujatResult
Baujat plot of a fitted rma_uni, rma_mh or rma_peto model (baujat.rma).
Mirrors metafor's baujat().
symbol is 'ids' (the 1-based study numbers), 'slab' (the study labels) or one plotting symbol
(a number, or one per study); grid adds a grid (a colour string sets its colour). progbar=True prints a progress bar to
stderr while the studies are left out in turn. Each study is
left out in turn and the model refitted; the x-axis shows the study's squared Pearson residual and the y-axis
the squared change in its fitted value, standardised by the variance of the prediction without the study.
bty (the type of box around the plot: 'o', 'l', '7', 'c', 'u', ']' or 'n') and las (the
orientation of the tick labels, 0 to 3) are passed on to plot() by metafor.
na_action stands for R's options(na.action=): an unknown value raises, 'fail' raises when a study has missing values (in metafor the
refits stop on them and baujat() ends with "need finite 'ylim' values"), the others give the same result (metafor sets na.pass while it computes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | FixedBinaryResult
|
A model fitted by rma_uni, |
required |
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis as (low, high). Default: derived from the data. |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high). Default: derived from the data. |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: derived from the model. |
None
|
ylab
|
str | None
|
Label of the vertical axis. Default: derived from the model. |
None
|
cex
|
float | None
|
Character expansion factor of the symbols. Default: 0.8 (times the base font size, as metafor's |
None
|
symbol
|
str | int | Sequence[int]
|
Plotting symbol: |
'ids'
|
grid
|
bool | str
|
Add a grid. |
True
|
progbar
|
bool
|
Print a progress bar to stderr while the studies are left out in turn. |
False
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
bty
|
str
|
Type of box around the plot: |
'o'
|
las
|
int | None
|
Orientation of the axis tick labels, 0 to 3 as in R (0 parallel to the axis, 1 horizontal, 2 perpendicular, 3 vertical). |
None
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with missing values (R's |
'omit'
|
Returns:
| Type | Description |
|---|---|
BaujatResult
|
The plotted coordinates and the axes (x is the contribution of each study to the overall heterogeneity, y its influence). |
Raises:
| Type | Description |
|---|---|
InputError
|
|
NotSupportedError
|
|
ArgumentError
|
|
qqnorm ¶
Normal quantile-quantile plot of the (standardised or studentised) residuals (metafor's qqnorm.rma.uni).
The plot can show a simulated pseudo confidence envelope around the line of equality, obtained by simulating normal data and applying the model's hat matrix (Cook & Weisberg, 1982, as cited by metafor); see https://wviechtb.github.io/metafor/reference/qqnorm.rma.html.
QQNormResult
dataclass
¶
QQNormResult(
ax: Axes,
x: FloatArray,
y: FloatArray,
lb: FloatArray | None = None,
ub: FloatArray | None = None,
)
Theoretical (x) and sample (y) quantiles (what qqnorm() returns), the envelope (if drawn) and the axes.
qqnorm ¶
qqnorm(
y: RMAResult
| RMAMVResult
| RMALSResult
| FixedBinaryResult,
type: str = 'rstandard',
pch: int = 21,
col: str | None = None,
bg: str | None = None,
grid: bool | str = False,
envelope: bool | str = True,
level: float | None = None,
bonferroni: bool = False,
reps: int = 1000,
smooth: bool = True,
bass: float = 0,
label: bool | int | str = False,
offset: float = 0.3,
pos: int = 13,
lty: str | Sequence[str] | None = None,
*,
seed: int | None = None,
rng: RRandom | None = None,
ax: Axes | None = None,
main: str = 'Normal Q-Q Plot',
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> QQNormResult
Normal Q-Q plot of the residuals of a model (qqnorm.rma.uni, qqnorm.rma.mh and qqnorm.rma.peto).
Mirrors metafor's qqnorm.rma().
type selects 'rstandard' or 'rstudent' residuals. envelope draws the simulated pseudo CI
(a colour string sets its colour; level its confidence level, bonferroni applies a Bonferroni
correction, reps the number of simulations, smooth/bass the Friedman super smoother applied to its
bounds); seed seeds the R-compatible generator so that the envelope reproduces R's set.seed(seed).
label (True/'all', a number of the most deviating points or 'out' for the points outside the
envelope) labels points with the study labels at position pos (1-4, or 13/24 to place them depending on
the side of the line). grid adds a grid, lty the line types of the line of equality and the envelope.
main is the title of the plot. na_action stands for R's options(na.action=): 'fail' stops when studies were left out of the fit, the other
choices give the same plot. For rma_mh and rma_peto fits no envelope is drawn (so label='out' labels nothing), as in metafor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
RMAResult | RMAMVResult | RMALSResult | FixedBinaryResult
|
A fitted model (rma_uni, |
required |
type
|
str
|
Residuals to plot: |
'rstandard'
|
pch
|
int
|
Plotting symbol of the points (R's |
21
|
col
|
str | None
|
Border colour of the points (a matplotlib colour, R names such as |
None
|
bg
|
str | None
|
Fill colour of the points for symbols with a separate fill. Default: a grey adjusted from the background. |
None
|
grid
|
bool | str
|
Add a grid. |
False
|
envelope
|
bool | str
|
Draw the simulated pseudo confidence envelope; a colour string sets its colour (default: light grey). No envelope is drawn for
|
True
|
level
|
float | None
|
Confidence level of the envelope, between 0 and 100 (95 or 0.95 for 95 percent). Default: the level of the model. |
None
|
bonferroni
|
bool
|
Apply a Bonferroni correction to the envelope. |
False
|
reps
|
int
|
Number of simulations for the envelope. |
1000
|
smooth
|
bool
|
Smooth the bounds of the envelope with the Friedman super smoother. |
True
|
bass
|
float
|
Degree of smoothing of the super smoother (metafor: a number between 0 and 10, higher is smoother). |
0
|
label
|
bool | int | str
|
Label points with the study labels: |
False
|
offset
|
float
|
Distance of the labels from the points, as a fraction of the character size (R's |
0.3
|
pos
|
int
|
Position of the labels: 1 to 4 as in R (below, left, above, right); 13 places a label below the point if it is below the reference line and above otherwise; 24 places it to the left if the point is above the reference line and to the right otherwise. |
13
|
lty
|
str | Sequence[str] | None
|
Line types of the line of equality and of the envelope bounds, as a pair (one value gives both the same type). Default: |
None
|
seed
|
int | None
|
Seed of the R-compatible generator, so that the envelope reproduces R's |
None
|
rng
|
RRandom | None
|
An explicit R-compatible random number generator, used instead of |
None
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
main
|
str
|
Title of the plot (default |
'Normal Q-Q Plot'
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with missing values (R's |
'omit'
|
Returns:
| Type | Description |
|---|---|
QQNormResult
|
The plotted theoretical quantiles and residuals, the envelope and the axes. |
Raises:
| Type | Description |
|---|---|
InputError
|
|
NotSupportedError
|
|
ArgumentError
|
|
InternalError
|
an envelope is drawn for a model class that has no hat matrix. |
plot_rma ¶
plot_rma(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult,
qqplot: bool = False,
*,
seed: int | None = None,
ax: Axes | None = None,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
**kwargs: Any,
) -> PlotRmaResult | SelPlotResult
Draw the forest, funnel, radial and residual plots of a model (metafor's plot() of an rma.uni, rma.mh or rma.peto fit).
Mirrors metafor's plot.rma.uni().
For a model without moderators the panels are forest, funnel,
radial and the standardized residuals (rstandard) of the studies in order;
for a meta-regression the funnel plot shows the residuals and the radial plot is replaced by the standardized
residuals against the fitted values. qqplot=True draws qqnorm (with seed for its envelope)
instead of the last panel. The panels fill ax (default: the current axes) in a 2 x 2 grid, as
par(mfrow = c(2, 2)) does. A selection model (rma.uni.selmodel) is drawn by plot_selmodel,
which gets kwargs, as R's plot() dispatches to plot.rma.uni.selmodel. na_action stands for R's options(na.action=): with
'omit' (default) the last panel and the third panel of a meta-regression show the studies used in fitting, with 'exclude' and 'pass' every
study of the subset (a gap where a value is missing), and 'fail' stops when studies were left out of the fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult
|
A model fitted by rma_uni, |
required |
qqplot
|
bool
|
Draw the normal Q-Q plot instead of the last panel. Default: |
False
|
seed
|
int | None
|
Seed of the R-compatible generator for the envelope of the Q-Q plot (only with |
None
|
ax
|
Axes | None
|
Matplotlib axes whose area the four panels fill (2 x 2 grid). Default: the current axes. |
None
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with missing values (R's |
'omit'
|
**kwargs
|
Any
|
plot_selmodel arguments, for selection models only. (Unlike metafor's |
{}
|
Returns:
| Type | Description |
|---|---|
PlotRmaResult | SelPlotResult
|
A |
PlotRmaResult | SelPlotResult
|
meta-regression and |
PlotRmaResult | SelPlotResult
|
panel (empty with |
PlotRmaResult | SelPlotResult
|
result of plot_selmodel. |
Raises:
| Type | Description |
|---|---|
ArgumentError
|
|
InputError
|
|
NotSupportedError
|
the model is an |
plot_infl ¶
plot_infl(
x: InfluenceResult,
plotinf: bool | int | Sequence[int] = True,
plotdfbs: bool | int | Sequence[int] = False,
dfbsnew: bool = False,
logcov: bool = True,
slab_style: int = 1,
las: int = 0,
pch: int = 21,
bg: str | None = None,
bg_infl: str = 'red',
col_na: str | None = None,
*,
ids: Iterable[int | str] | None = None,
na_action: str = 'omit',
mfrow: tuple[int, int] | None = None,
ax: Axes | None = None,
layout: object = None,
) -> PlotInflResult
Plot the case-deletion diagnostics returned by influence (plot.infl.rma.uni).
Mirrors metafor's plot.infl.rma.uni().
plotinf selects the diagnostics (True for all eight, or their numbers 1-8: rstudent, dffits,
cook.d, cov.r, tau2.del, QE.del, hat and weight) and plotdfbs the DFBETAS (True
for all, or the numbers of the coefficients, starting at 1 as in metafor). Influential studies are drawn in
bg_infl. slab_style chooses the labels of the x-axis (1 = ids, 2 = study labels, 3 = abbreviated
study labels); ids defaults to 1..k. na_action is 'omit' (leave out studies with missing
diagnostics) or 'exclude'/'pass' (keep them, joining the other points with a line in col_na).
The diagnostics are drawn into a grid of panels filling ax, with the number of rows and columns of metafor's default
(par(mfrow = ...)) unless mfrow=(rows, columns) is given, e.g. (8, 1) for one column of panels; the DFBETAS are drawn on a new figure if the
diagnostics are also plotted (or dfbsnew is true), as metafor starts a new page for them. layout is accepted for old code
and ignored with a warning, as metafor does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
InfluenceResult
|
The case-deletion diagnostics returned by influence. |
required |
plotinf
|
bool | int | Sequence[int]
|
Diagnostics to plot: |
True
|
plotdfbs
|
bool | int | Sequence[int]
|
DFBETAS to plot: |
False
|
dfbsnew
|
bool
|
Has no effect here: the DFBETAS are always drawn on a new figure when the diagnostics are drawn too, and on |
False
|
logcov
|
bool
|
Plot the covariance ratios (diagnostic 4) on a log scale. Default: |
True
|
slab_style
|
int
|
Labels of the horizontal axis: 1 for the study numbers (or |
1
|
las
|
int
|
Orientation of the horizontal-axis tick labels (R's |
0
|
pch
|
int
|
Plotting symbol of the points (R's |
21
|
bg
|
str | None
|
Fill colour of the points. Default: grey. |
None
|
bg_infl
|
str
|
Fill colour of the influential studies. Default: |
'red'
|
col_na
|
str | None
|
Colour of the line joining the points around missing diagnostics ( |
None
|
ids
|
Iterable[int | str] | None
|
Study identifiers for the horizontal axis when |
None
|
na_action
|
str
|
What to do with missing diagnostics (R's |
'omit'
|
mfrow
|
tuple[int, int] | None
|
Number of rows and columns of the grid of panels for the diagnostics, e.g. |
None
|
ax
|
Axes | None
|
Matplotlib axes whose area the panels fill. Default: the current axes. |
None
|
layout
|
object
|
Accepted for old code and ignored with a warning, as metafor does. |
None
|
Returns:
| Type | Description |
|---|---|
PlotInflResult
|
A |
Raises:
| Type | Description |
|---|---|
ArgumentError
|
|
InputError
|
|
plot_profile ¶
plot_profile(
x: ProfileResult
| LSProfileResult
| Sequence[ProfileResult | LSProfileResult],
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
pch: int = 19,
xlab: str | Sequence[str] | None = None,
ylab: str | Sequence[str] | None = None,
main: str | Sequence[str] | None = None,
refline: bool = True,
cline: bool | float = False,
*,
ax: Axes | None = None,
log: str | None = None,
cex: float = 1.0,
lwd: float = 1.0,
) -> Axes | list[Axes]
Plot the profile (log-)likelihood computed by profile (plot.profile.rma).
Mirrors metafor's plot.profile.rma(), which is documented with profile.rma.
refline marks the estimate and its (log-)likelihood with dotted lines, cline (True for a significance
level of 0.05, or a number as for metafor's level arguments) adds a horizontal line at the likelihood-ratio test's critical value. The
estimate itself is added to the profile if it lies within the range of the grid. Returns the axes.
x may also be the list of profiles that profile returns for models with several variance
components (rma_mv, location-scale and selection models): one panel per component is drawn in a grid, as
par(mfrow = n2mfrow(comps)) makes it (inside ax if given), and the list of axes is returned. xlab,
ylab and main are then one string for all panels or one per panel. Unlike metafor, refline also applies to
the panels of a list. log ('x', 'y' or 'xy') draws logarithmic axes, cex is the size of the points and lwd the
width of the line, which metafor passes on through ....
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ProfileResult | LSProfileResult | Sequence[ProfileResult | LSProfileResult]
|
A profile from profile, or the list of profiles it returns for models with several variance components ( |
required |
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis as (low, high). Default: those stored in the profile ( |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high). Default: those stored in the profile ( |
None
|
pch
|
int
|
Plotting symbol of the points (R's |
19
|
xlab
|
str | Sequence[str] | None
|
Label of the horizontal axis; for a list of profiles one string for all panels or one per panel. Default: derived from the profiled
component (for example |
None
|
ylab
|
str | Sequence[str] | None
|
Label of the vertical axis; for a list of profiles one string for all panels or one per panel. Default: |
None
|
main
|
str | Sequence[str] | None
|
Title; for a list of profiles one string for all panels or one per panel. Default: |
None
|
refline
|
bool
|
Mark the estimate and its (log-)likelihood with dotted lines (unlike metafor, also applies to the panels of a list). Default: |
True
|
cline
|
bool | float
|
Add a horizontal dotted line at the critical value of the likelihood-ratio test: |
False
|
ax
|
Axes | None
|
Matplotlib axes to draw into (for a list of profiles, the area the panels fill). Default: the current axes. |
None
|
log
|
str | None
|
Logarithmic axes: |
None
|
cex
|
float
|
Size of the points relative to the default. Default: 1. |
1.0
|
lwd
|
float
|
Width of the line. Default: 1. |
1.0
|
Returns:
| Type | Description |
|---|---|
Axes | list[Axes]
|
The axes drawn into (a list of axes, one per component, for a list of profiles). |
Raises:
| Type | Description |
|---|---|
InputError
|
|
plot_gosh ¶
plot_gosh(
x: GoshResult,
het: str = 'I2',
pch: int = 16,
cex: float | None = None,
out: int | None = None,
col: str | Sequence[str] | None = None,
alpha: float | Sequence[float] | None = None,
border: str | Sequence[str] | None = None,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
xhist: bool = True,
yhist: bool = True,
hh: float | Sequence[float] = 0.3,
breaks: Any = None,
adjust: float | Sequence[float] | None = None,
lwd: float | Sequence[float] | None = None,
labels: Sequence[str] | None = None,
trim: float
| Sequence[float | Sequence[float]]
| None = None,
*,
ax: Axes | None = None,
) -> PlotGoshResult
Plot the results of gosh (plot.gosh.rma).
Mirrors metafor's plot.gosh.rma().
For a model without moderators the heterogeneity statistic het ('QE', 'I2', 'H2', 'tau2' or
'tau') is plotted against the estimate, with marginal histograms and kernel density estimates (xhist,
yhist; hh the relative sizes of the marginal plots, breaks, adjust and lwd their settings, each
a single value or a pair for the two margins); with moderators a scatterplot matrix of het and the
coefficients is drawn. out (0-based) highlights the subsets that do (col[0]) or do not include that study,
alpha gives the transparency of the points, histogram and density line, trim removes the most extreme
subsets (a proportion or a list of proportions per column). The panels fill the area of ax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
GoshResult
|
The result of gosh. |
required |
het
|
str
|
Heterogeneity statistic to plot: |
'I2'
|
pch
|
int
|
Plotting symbol of the points (R's |
16
|
cex
|
float | None
|
Expansion factor of the points. Default: 0.5. |
None
|
out
|
int | None
|
0-based index of a study to highlight (metafor's |
None
|
col
|
str | Sequence[str] | None
|
Colour of the points. Default: black. With |
None
|
alpha
|
float | Sequence[float] | None
|
Transparency (0 transparent to 1 opaque) of the points, of the histogram bars and of the density lines: one value for the points
(the histograms then get 0.5 and the density lines 0.9), two for points and histograms, or all three. Default: |
None
|
border
|
str | Sequence[str] | None
|
Border colour of the histogram bars, one for both or a pair (horizontal, vertical margin). Default: light grey. (metafor's |
None
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis as (low, high); models without moderators only. Default: the range of the histogram breaks of the estimates. |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high); models without moderators only. Default: the range of the histogram breaks of |
None
|
xhist
|
bool
|
Draw the marginal histogram and density of the estimates; models without moderators only. Default: |
True
|
yhist
|
bool
|
Draw the marginal histogram and density of the heterogeneity statistic; models without moderators only. Default: |
True
|
hh
|
float | Sequence[float]
|
Relative size of the marginal plots, between 0 and 1 (checked for models without moderators); a single value or a pair for the two margins. For models with moderators it stretches the height of the histograms on the diagonal. Default: 0.3. |
0.3
|
breaks
|
Any
|
Histogram breaks of the marginal plots, as for R's |
None
|
adjust
|
float | Sequence[float] | None
|
Bandwidth adjustment of the kernel density estimates (larger is smoother); a single value or a pair. Default: 1. |
None
|
lwd
|
float | Sequence[float] | None
|
Width of the density lines, 0 omits them; a single value or a pair. Default: 2. |
None
|
labels
|
Sequence[str] | None
|
The labels of the horizontal and vertical axes (no moderators) or the names of the variables of the scatterplot matrix. Default: derived
from the effect size measure, |
None
|
trim
|
float | Sequence[float | Sequence[float]] | None
|
Remove the most extreme subsets before plotting (an undocumented argument of metafor, passed through |
None
|
ax
|
Axes | None
|
Matplotlib axes whose area the panels fill. Default: the current axes. |
None
|
Returns:
| Type | Description |
|---|---|
PlotGoshResult
|
A |
PlotGoshResult
|
not drawn); for a scatterplot matrix |
PlotGoshResult
|
whichever were drawn. |
Raises:
| Type | Description |
|---|---|
InputError
|
|
plot_selmodel ¶
plot_selmodel(
x: SelmodelResult,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
n: int = 1000,
prec: str | float = 'max',
scale: bool = False,
ci: bool | str = False,
reps: int = 1000,
shade: bool | str = True,
rug: bool = True,
add: bool = False,
lty: str | int | Sequence[str | int] = LINE_STYLES,
lwd: float | Sequence[float] = (2.0, 1.0),
seed: int | None = None,
draw: bool = True,
*,
ax: Axes | None = None,
bty: str = 'o',
col: str | None = None,
) -> SelPlotResult
Draw the selection function of a selection model against the p-value.
Mirrors metafor's plot.rma.uni.selmodel().
prec fixes the precision at which the function is drawn ('min', 'max', 'mean', 'median' or a number).
ci adds a confidence region: 'wald' transforms the Wald bounds of the selection parameters, 'boot' (or True)
simulates reps parameter vectors from their estimated multivariate normal distribution (with NumPy's generator seeded by
seed, so the bounds agree with metafor only up to simulation error). scale rescales the curve to the unit interval,
shade fills the region, rug marks the observed p-values and add draws into existing axes. draw=False only
computes the curve. bty (the type of box around the plot) and col (the colour of the lines) are passed on to plot() and lines() by
metafor. The curve is returned as SelPlotResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
SelmodelResult
|
A selection model from selmodel. |
required |
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis (the p-values for which the function is drawn), within 0 and 1. Default: the model's smallest p-value
|
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high). Default: 0 to 1 for the bounded selection functions ( |
None
|
n
|
int
|
Number of p-values within |
1000
|
prec
|
str | float
|
Precision at which a selection function that involves one is drawn: |
'max'
|
scale
|
bool
|
Rescale the curve (and region) to the 0 to 1 range. Default: |
False
|
ci
|
bool | str
|
Add a confidence region around the curve: |
False
|
reps
|
int
|
Number of simulated parameter vectors for the |
1000
|
shade
|
bool | str
|
Shade the confidence region: |
True
|
rug
|
bool
|
Mark the observed p-values along the horizontal axis (not with |
True
|
add
|
bool
|
Add the curve to the existing axes without drawing a new frame, labels or rug. Default: |
False
|
lty
|
str | int | Sequence[str | int]
|
Line types of the selection function and of the confidence region bounds, as a pair (a single value serves the curve and the bounds get
|
LINE_STYLES
|
lwd
|
float | Sequence[float]
|
Line widths of the selection function and of the confidence region bounds, as a pair (a single value serves the curve and the bounds get 1).
Default: |
(2.0, 1.0)
|
seed
|
int | None
|
Seed of NumPy's generator for the |
None
|
draw
|
bool
|
If |
True
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
bty
|
str
|
Type of box around the plot: |
'o'
|
col
|
str | None
|
Colour of the curve and of the confidence region bounds (the shading has its own colour |
None
|
Returns:
| Type | Description |
|---|---|
SelPlotResult
|
A |
SelPlotResult
|
confidence region) and the axes |
Raises:
| Type | Description |
|---|---|
InputError
|
the model has a truncated selection function or none; |
regplot ¶
Meta-analytic scatterplot (metafor's regplot.rma) and its points method (points.regplot).
Plots the observed effects against one moderator of a meta-regression model, with the size of each point given by its weight (or a precision), the fitted regression line and, optionally, the pointwise confidence and prediction bands. See https://wviechtb.github.io/metafor/reference/regplot.html, https://github.com/wviechtb/metafor/blob/master/R/regplot.rma.r, https://github.com/wviechtb/metafor/blob/master/R/points.regplot.r and Thompson & Higgins (2002), doi:10.1002/sim.1187.
RegplotResult
dataclass
¶
RegplotResult(
ax: Axes,
xi: FloatArray,
yi: FloatArray,
psize: FloatArray,
pred: FloatArray | None,
label: NDArray[bool_],
slab: tuple[str, ...],
order: NDArray[intp],
offset: tuple[float, ...],
labsize: float,
ids: NDArray[intp],
pch: tuple[int, ...],
col: tuple[Any, ...],
bg: tuple[Any, ...],
)
The plotted points (what metafor's regplot() returns invisibly) and the axes drawn on.
xi and yi are the coordinates of the studies drawn (yi after any transformation), psize the
symbol sizes (the cex of the points), label which studies were labelled, pred the fitted values and
order the order in which the points were drawn (largest symbols first). ids are the 0-based positions of the studies among
the rows supplied, pch, col and bg the symbols and colours of the points, and offset and labsize those of the
labels, so that :func:points_regplot can redraw the points and labels (metafor's points() of a regplot object).
points ¶
points(ax: Axes | None = None) -> None
Redraw the points and labels; see :func:points_regplot.
expand ¶
An argument that is one value or one value per study (.expand1() and the length check of metafor).
Raises:
| Type | Description |
|---|---|
InputError
|
|
find_moderator ¶
find_moderator(
x: FitView,
names: Sequence[str],
mod: str | int | None,
grep: bool = False,
fixed: bool = False,
) -> int
The 0-based position of the moderator among the coefficients (metafor's mod, with its grep and fixed arguments).
A string is matched against the coefficient names by charmatch() (exactly, or as the start of a single name); with grep=True it is
searched for in the names as a regular expression (fixed=True: as a literal string) and must be found in exactly one.
Raises:
| Type | Description |
|---|---|
InputError
|
|
symbol_sizes ¶
symbol_sizes(
psize: Any,
weights: NDArray[float64],
vi: NDArray[float64],
plim: Sequence[float],
) -> NDArray[float64]
The cex of the points: the given sizes, or the weights (or 'seinv'/'vinv') rescaled to plim.
Raises:
| Type | Description |
|---|---|
InputError
|
a numeric |
sorted_pair ¶
sorted_pair(
lb: NDArray[float64], ub: NDArray[float64]
) -> tuple[NDArray[float64], NDArray[float64]]
.psort(): the smaller of each pair first (transformations may reverse the order).
regplot ¶
regplot(
x: RMAResult
| RMAMVResult
| FixedBinaryResult
| RMALSResult
| SelmodelResult
| GLMMResult,
mod: str | int | None = None,
pred: bool | PredictResult = True,
ci: bool = True,
pi: bool = False,
shade: bool | str | Sequence[str] = True,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
predlim: Sequence[float] | None = None,
olim: Sequence[float] | None = None,
xlab: str | None = None,
ylab: str | None = None,
at: ArrayLike | None = None,
digits: float | Sequence[float] = 2,
transf: Callable[..., Any] | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
level: float | None = None,
pch: int | Sequence[int] = 21,
psize: float | str | Sequence[float] | None = None,
plim: Sequence[float] = (0.5, 3.0),
col: str | Sequence[str] | None = None,
bg: str | Sequence[str] | None = None,
slab: Sequence[Any] | None = None,
grid: bool | str = False,
refline: float | None = None,
label: bool | str | Sequence[Any] = False,
offset: float | Sequence[float] = (1.0, 1.0),
labsize: float = 1.0,
lcol: str | Sequence[str] | None = None,
lwd: float | Sequence[float] | None = None,
lty: str | int | Sequence[str | int] | None = None,
legend: bool | str | dict[str, Any] = False,
xvals: ArrayLike | None = None,
*,
bty: str = 'o',
las: int = 0,
grep: bool = False,
fixed: bool = False,
ax: Axes | None = None,
xaxt: str = 's',
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
at_lab: Sequence[str] | None = None,
box_lty: str = 'solid',
) -> RegplotResult
Meta-analytic scatterplot of a meta-regression model (regplot.rma).
Mirrors metafor's regplot().
mod is the moderator on the horizontal axis (its name, or its 0-based position among the coefficients; it may
be left out when the model has a single moderator). The regression line (pred) and the confidence (ci) and
prediction (pi) bands are drawn for the other moderators set to their means; xvals gives the moderator values
to predict at, and pred may be a PredictResult for those values. transf
transforms the effects and the bands, atransf only the labels of the vertical axis, and olim limits the
values drawn. The points have the cex psize (or the square roots of the weights rescaled to plim; give
'seinv' or 'vinv' to scale the inverse standard errors or variances instead). label labels the studies
(True/'all', 'ciout'/'piout' for those outside the bands, a boolean array or 0-based indices), with
offset the distance from the point in percent of the vertical range and labsize the text size. legend
adds a legend (True, a location such as 'topright' or a dict with x and cex);
box_lty is the line type of its frame ('blank' for none). at_lab gives the labels of the ticks at of the vertical axis
(one per value of at, or per tick when at is not given) instead of the formatted values.
bty ('o' or 'l') is the box type and las the orientation of the labels of the vertical axis (0 = parallel to it, 1 = horizontal).
xaxt='n' leaves out the horizontal axis.
grep=True makes a string mod a regular expression searched for in the coefficient names (which must find exactly one) and
fixed=True a literal string instead (the grep and fixed arguments metafor reads through ...).
na_action stands for R's options(na.action=): 'fail' stops when the regression line is drawn (pred=True) and studies were left out of the
fit, the other choices give the same plot.
x is a fit of rma, including location-scale models, of selmodel, of rma_mv
or of rma_glmm; the bands are the predictions of the model, so no prediction interval is drawn where
predict gives none (location-scale models). The sizes of the points are equal for the models without weights
(selmodel and rma_glmm fits).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | RMAMVResult | FixedBinaryResult | RMALSResult | SelmodelResult | GLMMResult
|
required | |
mod
|
str | int | None
|
Moderator on the horizontal axis: its name (matched exactly or as the start of one coefficient name), or its 0-based position among the coefficients (the intercept, if any, is position 0). May be left out when the model has a single moderator. |
None
|
pred
|
bool | PredictResult
|
Draw the regression line (the other moderators are set to their means), or give a PredictResult for the values in
|
True
|
ci
|
bool
|
Draw the confidence band. Default: |
True
|
pi
|
bool
|
Draw the prediction band (none is drawn, with a warning, where the model gives no prediction interval). Default: |
False
|
shade
|
bool | str | Sequence[str]
|
Shade the bands: |
True
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis as (low, high). Default: the range of the moderator. |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high). Default: the range of the (transformed) estimates and of the prediction band (if drawn) or
confidence band, extended to include |
None
|
predlim
|
Sequence[float] | None
|
Limits (low, high) of the moderator values for the regression line and bands. Default: the range of the moderator extended by 4 percent on each side. |
None
|
olim
|
Sequence[float] | None
|
Limits (low, high) the estimates and the line and band bounds cannot exceed, for bounded measures. Default: none. |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: the coefficient name. |
None
|
ylab
|
str | None
|
Label of the vertical axis. Default: derived from the effect size measure and |
None
|
at
|
ArrayLike | None
|
Positions of the tick marks of the vertical axis (on the transformed scale of |
None
|
digits
|
float | Sequence[float]
|
Number of decimals of the vertical-axis tick labels (trailing zeros are kept) and of the level in the legend. Default: 2. |
2
|
transf
|
Callable[..., Any] | None
|
Function applied to the estimates and to the line and band bounds before they are drawn. Not together with |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the vertical-axis tick labels only. Not together with |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
level
|
float | None
|
Confidence level of the bands (95 or 0.95 for 95 percent). Default: the level of the model. |
None
|
pch
|
int | Sequence[int]
|
Plotting symbol of the points (R's |
21
|
psize
|
float | str | Sequence[float] | None
|
Size (expansion factor) of the points: a number, one per study used in the fit, or |
None
|
plim
|
Sequence[float]
|
Range (min, max) of the point sizes when |
(0.5, 3.0)
|
col
|
str | Sequence[str] | None
|
Border colour of the points, or one per study used in the fit (a matplotlib colour). Default: black. |
None
|
bg
|
str | Sequence[str] | None
|
Fill colour of the points for symbols with a separate fill, or one per study used in the fit. Default: grey. |
None
|
slab
|
Sequence[Any] | None
|
Study labels (for |
None
|
grid
|
bool | str
|
Add a grid: |
False
|
refline
|
float | None
|
Position of a horizontal reference line. Default: none. |
None
|
label
|
bool | str | Sequence[Any]
|
Label the studies: |
False
|
offset
|
float | Sequence[float]
|
Distance of the labels from the points, in percent of the vertical range: one value (a multiple of the point size) or a pair (added distance, multiple of the point size). Default: (1, 1). |
(1.0, 1.0)
|
labsize
|
float
|
Text size of the labels, as an expansion factor. Default: 1. |
1.0
|
lcol
|
str | Sequence[str] | None
|
Colours of up to four lines: the regression line, the confidence band bounds, the prediction band bounds and the reference line. A single colour serves all four; two give (line, both bounds) and three leave the reference line at its default. Default: black, black, black and grey. |
None
|
lwd
|
float | Sequence[float] | None
|
Line widths of the same four lines, expanded like |
None
|
lty
|
str | int | Sequence[str | int] | None
|
Line types of the same four lines, expanded like |
None
|
legend
|
bool | str | dict[str, Any]
|
Add a legend: |
False
|
xvals
|
ArrayLike | None
|
Moderator values to predict at, for the regression line and bands; required with a |
None
|
bty
|
str
|
Type of box around the plot, as R's |
'o'
|
las
|
int
|
Orientation of the vertical-axis tick labels: 0 (the default) parallel to the axis, any other value horizontal. |
0
|
grep
|
bool
|
Treat a string |
False
|
fixed
|
bool
|
Treat a string |
False
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
xaxt
|
str
|
|
's'
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with missing values (R's |
'omit'
|
at_lab
|
Sequence[str] | None
|
Labels of the vertical-axis tick marks |
None
|
box_lty
|
str
|
Line type of the frame of the legend ( |
'solid'
|
Returns:
| Type | Description |
|---|---|
RegplotResult
|
The plotted coordinates and the axes; pass it to points_regplot to redraw the points. |
Raises:
| Type | Description |
|---|---|
InputError
|
the model has no moderator; |
NotSupportedError
|
|
ArgumentError
|
|
draw_points ¶
draw_points(
ax: Axes,
xi: NDArray[float64],
yi: NDArray[float64],
pch: Sequence[int],
psize: NDArray[float64],
col: Sequence[Any],
bg: Sequence[Any],
order: NDArray[intp],
) -> None
Draw the points in order (the largest symbols first, so that the small ones are on top).
draw_labels ¶
draw_labels(
ax: Axes,
xi: NDArray[float64],
yi: NDArray[float64],
pred: NDArray[float64] | None,
psize: NDArray[float64],
flags: NDArray[bool_],
slab: Sequence[str],
offset: Sequence[float],
labsize: float,
) -> None
Label the flagged points above the point where the observed value is above the fitted one and below otherwise.
points_regplot ¶
points_regplot(
x: RegplotResult, ax: Axes | None = None
) -> None
Redraw the points (and the labels, if there were any) of a regplot (metafor's points.regplot).
Mirrors metafor's points() method for regplot objects (points.regplot).
The points are drawn on ax (default: the axes of the plot) in the order of x.order, which puts the points with the
smallest symbols on top again after other elements were added to the plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RegplotResult
|
The result of regplot. |
required |
ax
|
Axes | None
|
Matplotlib axes to draw on. Default: the axes of the plot. |
None
|
Raises:
| Type | Description |
|---|---|
InputError
|
|
dash ¶
The matplotlib line style of an R line type name, or the name itself when it is already a style.
regplot_legend ¶
regplot_legend(
ax: Axes,
legend: bool | str | dict[str, Any],
addpred: bool,
ci: bool,
pi: bool,
level: float,
digits: int,
lty: list[str],
lcol: list[str],
lwd: list[float],
shade: list[str],
col: list[Any],
bg: list[Any],
pch: list[int],
box_lty: str = 'solid',
) -> None
The legend of regplot(): studies, regression line and the confidence and prediction intervals.
points_regplot ¶
points_regplot(
x: RegplotResult, ax: Axes | None = None
) -> None
Redraw the points (and the labels, if there were any) of a regplot (metafor's points.regplot).
Mirrors metafor's points() method for regplot objects (points.regplot).
The points are drawn on ax (default: the axes of the plot) in the order of x.order, which puts the points with the
smallest symbols on top again after other elements were added to the plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RegplotResult
|
The result of regplot. |
required |
ax
|
Axes | None
|
Matplotlib axes to draw on. Default: the axes of the plot. |
None
|
Raises:
| Type | Description |
|---|---|
InputError
|
|
forest_cumul ¶
forest_cumul(
x: CumulResult,
*,
annotate: bool = True,
header: bool | str | Sequence[str] = True,
xlim: Sequence[float] | None = None,
alim: Sequence[float] | None = None,
olim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
at: ArrayLike | None = None,
steps: int = 5,
refline: float | None = 0,
digits: int | Sequence[float] | NDArray[floating] = 2,
width: int | Sequence[int] | None = None,
xlab: str | Sequence[str] | None = None,
ilab: Any = None,
ilab_lab: str | Sequence[str] | None = None,
ilab_xpos: ArrayLike | None = None,
ilab_pos: int | Sequence[int] | None = None,
transf: Callable[..., Any] | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
rows: ArrayLike | float | None = None,
efac: float | Sequence[float] = 1,
pch: int | Sequence[int] = 15,
psize: float | ArrayLike = 1,
col: str | Sequence[str] | None = None,
colci: str | Sequence[str] | None = None,
shade: bool | str | ArrayLike | None = None,
colshade: str | None = None,
lty: str | Sequence[str] | None = None,
fonts: Any = None,
cex: float | None = None,
cex_lab: float | None = None,
cex_axis: float | None = None,
ax: Axes | None = None,
annosym: Sequence[str] | None = None,
tabfig: int | None = None,
textpos: Sequence[float] | None = None,
rowadj: float | Sequence[float] | None = None,
top: float = 3,
at_lab: Sequence[str] | None = None,
xlabadj: float | Sequence[float] | None = None,
xlabfont: int | Sequence[int] = 1,
) -> ForestResult
Cumulative forest plot (forest.cumul.rma): one row per step of a cumul analysis.
Mirrors metafor's forest.cumul.rma().
The first row is labelled with the first study, the others with + and the added study (Study and its label when the model had
no study labels). The plot is that of forest for a vector of estimates with confidence intervals: there is no summary
polygon, the arguments mean what they mean there for a vector x (so col colours the markers, interval lines and labels) and the
confidence level is that of the cumulative analysis. forest(cumul(res), ...) is the same call (with warnings for the arguments of the
fitted-model form that this plot does not have).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
CumulResult
|
The result of cumul. |
required |
annotate
|
bool
|
Add the annotations (estimate and confidence interval) on the right. Default: |
True
|
header
|
bool | str | Sequence[str]
|
|
True
|
xlim
|
Sequence[float] | None
|
Horizontal limits of the plot region. Default: the CI bounds extended on both sides for the labels and annotations. |
None
|
alim
|
Sequence[float] | None
|
Limits of the x axis. Default: the range of |
None
|
olim
|
Sequence[float] | None
|
Limits |
None
|
ylim
|
Sequence[float] | None
|
Vertical limits of the plot region; a single value sets the lower limit only. |
None
|
at
|
ArrayLike | None
|
Positions of the x-axis tick marks, on the scale that is plotted (after |
None
|
steps
|
int
|
Number of tick marks of the x axis: exact when |
5
|
refline
|
float | None
|
Position of the dotted vertical reference line, or |
0
|
digits
|
int | Sequence[float] | NDArray[floating]
|
Number of decimals of the annotations and of the x-axis labels, in this order (a third value is for weights, which this plot does not have). A single value is used for both. An integer drops trailing zeros from the axis labels, a float keeps them. Default: 2. |
2
|
width
|
int | Sequence[int] | None
|
Minimum width (number of characters) of the annotation columns, one value or one per column. Default: the longest entry. |
None
|
xlab
|
str | Sequence[str] | None
|
Label of the x axis, or three or two labels (see forest). Default: the 'Overall' label of the measure of
the analysis (for example |
None
|
ilab
|
Any
|
Extra columns of information on the left: a vector, a matrix or a data frame with one row per step. |
None
|
ilab_lab
|
str | Sequence[str] | None
|
Headings of the |
None
|
ilab_xpos
|
ArrayLike | None
|
X positions of the |
None
|
ilab_pos
|
int | Sequence[int] | None
|
Alignment of the |
None
|
transf
|
Callable[..., Any] | None
|
Function applied to the estimates and interval bounds. Cannot be used together with |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the x-axis labels and to the annotations. Cannot be used together with |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
rows
|
ArrayLike | float | None
|
Rows in which the steps are drawn: one per step, or a single value for the first. Default: counted down from the number of steps. |
None
|
efac
|
float | Sequence[float]
|
Vertical expansion factors of the CI end bars and of the arrows: one value for both or two. Default: 1. |
1
|
pch
|
int | Sequence[int]
|
Plotting symbol of the markers (an R code; 15 is a filled square). Default: 15. |
15
|
psize
|
float | ArrayLike
|
Size of the markers: one value or one per step. Unlike forest the markers are not scaled by precision. Default: 1. |
1
|
col
|
str | Sequence[str] | None
|
Colour of the markers, interval lines and labels: one value or one per step. Default: black. |
None
|
colci
|
str | Sequence[str] | None
|
Colour of the confidence interval lines. Default: that of the markers. |
None
|
shade
|
bool | str | ArrayLike | None
|
Shade rows: |
None
|
colshade
|
str | None
|
Colour of the shading. Default: |
None
|
lty
|
str | Sequence[str] | None
|
|
None
|
fonts
|
Any
|
Font family and font of the labels, annotations and |
None
|
cex
|
float | None
|
Character expansion factor of the text and symbols. Default: 1, reduced when the rows would not fit on the axes. |
None
|
cex_lab
|
float | None
|
Character expansion factor of the x-axis label. Default: the value of |
None
|
cex_axis
|
float | None
|
Character expansion factor of the x-axis tick labels. Default: the value of |
None
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
annosym
|
Sequence[str] | None
|
Symbols of the annotations, as in forest (three, four or five strings). |
None
|
tabfig
|
int | None
|
1, 2 or 3 replaces |
None
|
textpos
|
Sequence[float] | None
|
|
None
|
rowadj
|
float | Sequence[float] | None
|
Vertical adjustment of the labels, annotations and |
None
|
top
|
float
|
Number of rows above the first step. Default: 3. |
3
|
at_lab
|
Sequence[str] | None
|
Labels of the tick marks, one per position. |
None
|
xlabadj
|
float | Sequence[float] | None
|
Alignment of the left and right x-axis labels, as in forest. Default: centred. |
None
|
xlabfont
|
int | Sequence[int]
|
Font (1 to 4) of the x-axis labels, as in forest. Default: 1. |
1
|
Returns:
| Type | Description |
|---|---|
ForestResult
|
A |
Raises:
| Type | Description |
|---|---|
InputError
|
plot_cumul ¶
plot_cumul(
x: CumulResult,
yaxis: str | None = None,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
xlab: str | None = None,
ylab: str | None = None,
at: ArrayLike | None = None,
transf: Callable[..., Any] | None = None,
atransf: Callable[..., Any] | None = None,
targs: Any = None,
digits: int | Sequence[int] | None = None,
cols: Sequence[str] | None = None,
grid: bool | str = True,
pch: int = 19,
cex: float = 1.0,
lwd: float = 2.0,
*,
las: int = 0,
ax: Axes | None = None,
addgrid: bool | str | None = None,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> PlotCumulResult
Plot of the results of a cumulative meta-analysis (plot.cumul.rma).
Mirrors metafor's plot.cumul.rma().
The pooled estimates (horizontal axis) are plotted against the amount of heterogeneity (yaxis 'tau2', 'tau', 'I2' or
'H2'; 'tau2' unless the model is a fixed-effects one), joined in order by a line whose colour runs from the first of cols to
the last (light to dark by default). transf transforms the estimates, atransf only the labels of the horizontal axis,
digits are the digits of the labels of the two axes and grid draws the dotted grid (a colour for the lines of the grid; addgrid is the
old spelling that metafor reads from ... and wins).
na_action stands for R's options(na.action=): an unknown value raises, the others
give the same result (metafor sets na.pass while it computes). With 'fail' missing values in the results stop the plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
CumulResult
|
The result of cumul. |
required |
yaxis
|
str | None
|
Heterogeneity statistic on the vertical axis: |
None
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis as (low, high), in either order. Default: the range of the (transformed) pooled estimates. |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high), in either order. Default: the range of the heterogeneity statistic. |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: derived from the effect size measure. |
None
|
ylab
|
str | None
|
Label of the vertical axis. Default: derived from |
None
|
at
|
ArrayLike | None
|
Positions of the tick marks of the horizontal axis (on the scale after |
None
|
transf
|
Callable[..., Any] | None
|
Function applied to the pooled estimates before drawing. Not together with |
None
|
atransf
|
Callable[..., Any] | None
|
Function applied to the labels of the horizontal axis only. Not together with |
None
|
targs
|
Any
|
Additional arguments passed to |
None
|
digits
|
int | Sequence[int] | None
|
Number of decimals of the tick labels of the horizontal axis and of the vertical axis: one integer for both or a pair (horizontal, vertical).
Default: 2 and 3 for |
None
|
cols
|
Sequence[str] | None
|
Colours (matplotlib colours) of the first and last step; the points and the line change from the first to the last. Only the first and last colour are used (metafor interpolates through all of them). Default: light grey to dark grey. |
None
|
grid
|
bool | str
|
Draw the dotted grid; a colour string sets the colour of its lines. Default: |
True
|
pch
|
int
|
Plotting symbol of the points (R's |
19
|
cex
|
float
|
Expansion factor of the points. Default: 1. |
1.0
|
lwd
|
float
|
Width of the line joining the steps. Default: 2. |
2.0
|
las
|
int
|
Orientation of the vertical-axis tick labels: 0 (the default) parallel to the axis, any other value horizontal. |
0
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
addgrid
|
bool | str | None
|
Old spelling of |
None
|
na_action
|
Literal['omit', 'exclude', 'pass', 'fail']
|
What to do with missing values (R's |
'omit'
|
Returns:
| Type | Description |
|---|---|
PlotCumulResult
|
A |
PlotCumulResult
|
colour |
Raises:
| Type | Description |
|---|---|
InputError
|
|
llplot ¶
Plot of the likelihood functions of the individual studies (metafor's llplot).
For measure='GEN' each study contributes the normal likelihood of its effect size yi with sampling variance vi; for
measure='OR' the likelihood of the (log) odds ratio is the conditional one given the margins of the 2x2 table, which follows Fisher's
non-central hypergeometric distribution (Fog 2008, doi:10.1080/03610910701790236). With scale=True every likelihood is rescaled to area
one, so that the curves show how much information each study has about the effect. See
https://wviechtb.github.io/metafor/reference/llplot.html and van Houwelingen et al. (1993), doi:10.1002/sim.4780122405.
LlplotResult
dataclass
¶
LlplotResult(ax: Axes, xs: FloatArray, lls: FloatArray)
The likelihoods drawn (what metafor's llplot() returns invisibly): lls[i, j] is the likelihood of study i at xs[j].
Values outside of the (very wide) confidence interval of a study are NaN and not drawn.
odds_ratio_likelihood ¶
odds_ratio_likelihood(
a: NDArray[float64],
b: NDArray[float64],
c: NDArray[float64],
d: NDArray[float64],
xs: NDArray[float64],
) -> NDArray[float64]
The conditional likelihood of each table at the log odds ratios xs (rows are studies).
r_rank ¶
rank(x) as an integer index (average ranks of ties are truncated when used to index a vector, as R does).
llplot ¶
llplot(
measure: str = 'GEN',
yi: ArrayLike | str | None = None,
vi: ArrayLike | str | None = None,
sei: ArrayLike | 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,
data: Any = None,
subset: ArrayLike | None = None,
drop00: bool = True,
xvals: int = 1000,
xlim: Sequence[float] | None = None,
ylim: Sequence[float] | None = None,
xlab: str | None = None,
ylab: str | None = None,
scale: bool = True,
lty: str | Sequence[str] | None = None,
lwd: float | Sequence[float] | None = None,
col: str | Sequence[str] | None = None,
level: float = 99.99,
refline: float | None = 0,
*,
onlyo1: bool = False,
addyi: bool = True,
addvi: bool = True,
ax: Axes | None = None,
) -> LlplotResult
Plot the likelihood function of the true effect given the data of each study (llplot).
Mirrors metafor's llplot().
measure is 'GEN' (give yi with vi or sei) or 'OR' (give the counts ai, bi, ci, di, or ai,
n1i, ci, n2i). Studies with no cases (or only cases) in both groups (drop00) are left out for 'OR'; if kept, they are drawn
dotted, and tables with a single zero count dashed, as in metafor. xvals is the number of points of each curve, level the confidence level of the
interval outside which the curves are not drawn, scale rescales each likelihood to area one, and lty, lwd and col
are per study (by default the more precise studies get thicker and darker lines). refline draws a vertical line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measure
|
str
|
|
'GEN'
|
yi
|
ArrayLike | str | None
|
Observed effect sizes (array or column name of |
None
|
vi
|
ArrayLike | str | None
|
Sampling variances (array or column name), for |
None
|
sei
|
ArrayLike | str | None
|
Standard errors (array or column name), for |
None
|
ai
|
ArrayLike | str | None
|
2x2 table counts, upper left cell (array or column name), for |
None
|
bi
|
ArrayLike | str | None
|
2x2 table counts, upper right cell. |
None
|
ci
|
ArrayLike | str | None
|
2x2 table counts, lower left cell. |
None
|
di
|
ArrayLike | str | None
|
2x2 table counts, lower right cell. |
None
|
n1i
|
ArrayLike | str | None
|
Size of group 1 (the row total of the first row); an alternative to |
None
|
n2i
|
ArrayLike | str | None
|
Size of group 2 (the row total of the second row); an alternative to |
None
|
data
|
Any
|
Data frame holding the variables named (as column names) in the other arguments. |
None
|
subset
|
ArrayLike | None
|
Which studies to use: a boolean array or an array of 0-based indices (into the data, so |
None
|
drop00
|
bool
|
Drop studies with no cases (or only cases) in both groups ( |
True
|
xvals
|
int
|
Number of points at which each likelihood is evaluated. Default: 1000. |
1000
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis (the range of the curves) as (low, high), in either order. Default: the range of the confidence intervals of
the studies at |
None
|
ylim
|
Sequence[float] | None
|
Limits of the vertical axis as (low, high), in either order. Default: 0 to the largest likelihood. |
None
|
xlab
|
str | None
|
Label of the horizontal axis. Default: |
None
|
ylab
|
str | None
|
Label of the vertical axis. Default: |
None
|
scale
|
bool
|
Rescale each likelihood so that the area under its curve is (about) 1. Default: |
True
|
lty
|
str | Sequence[str] | None
|
Line type of the curves: one value or one per study (of the whole data). Default: solid for |
None
|
lwd
|
float | Sequence[float] | None
|
Line width of the curves: one value or one per study. Default: 4 to 0.4, thicker for the more precise studies (by the rank of the sampling variance). |
None
|
col
|
str | Sequence[str] | None
|
Colour of the curves: one value or one per study (a matplotlib colour). Default: shades of grey from dark (the most precise study) to light (the least precise study). |
None
|
level
|
float
|
Confidence level in percent of the interval of each study outside which its curve is not drawn (and which sets the default |
99.99
|
refline
|
float | None
|
Position of a vertical reference line, or |
0
|
onlyo1
|
bool
|
Passed to escalc: only the first outcome of the 2x2 tables is used. |
False
|
addyi
|
bool
|
Passed to escalc: apply |
True
|
addvi
|
bool
|
Passed to escalc: apply |
True
|
ax
|
Axes | None
|
Matplotlib axes to draw into. Default: the current axes. |
None
|
Returns:
| Type | Description |
|---|---|
LlplotResult
|
A |
LlplotResult
|
study, NaN outside the confidence interval of the study at |
Raises:
| Type | Description |
|---|---|
ArgumentError
|
a count passed to escalc has the wrong type. |
InputError
|
|
plot_permutest ¶
plot_permutest(
x: PermutestResult | LSPermutestResult,
beta: Sequence[int | str] | int | str | None = None,
alpha: Sequence[int | str] | int | str | None = None,
QM: bool = False,
QS: bool = False,
breaks: object = 'Scott',
freq: bool = False,
col: str | None = None,
border: str | None = None,
col_out: str | None = None,
col_ref: str | None = None,
col_density: str | None = None,
trim: float = 0.0,
adjust: float = 1.0,
lwd: float | Sequence[float] = (2, 0, 0, 4),
legend: bool | str = False,
*,
alternative: str | None = None,
p2defn: str | None = None,
stat: str | None = None,
ax: Axes | None = None,
xlim: Sequence[float] | None = None,
layout: object = None,
) -> PlotPermutestResult
Plot the permutation distributions of a permutest result (plot.permutest.rma.uni).
Mirrors metafor's plot.permutest.rma.uni().
One panel is drawn per selected element, in the order of metafor: the omnibus test of the location coefficients (QM=True), the
location coefficients, the omnibus test of the scale coefficients (QS=True) and the scale coefficients. Each panel is the histogram of
the permuted test statistics (or coefficients), the observed value is a dashed line and the tails beyond it are filled with col_out.
The theoretical null distribution and the kernel density estimate are omitted by default (their lwd is 0). A single-coefficient plot
has no panel title.
Trimming only affects the histogram; the kernel density estimate uses all permutations.
For an omnibus test with a single degree of freedom (QM=True and one coefficient tested) the theoretical density is infinite at 0. That
point is left out of the curve and of the y range, whereas metafor stops with an infinite ylim there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
PermutestResult | LSPermutestResult
|
The result of permutest; a location-scale permutation test gives |
required |
beta
|
Sequence[int | str] | int | str | None
|
Location coefficients to plot, as names or 0-based positions (R: 1-based). A single name or position is allowed. Default
|
None
|
alpha
|
Sequence[int | str] | int | str | None
|
Scale coefficients to plot, selected as |
None
|
QM
|
bool
|
Add the panel of the omnibus test of the location coefficients (ignored for an intercept-only model). Default: |
False
|
QS
|
bool
|
Add the panel of the omnibus test of the scale coefficients ( |
False
|
breaks
|
object
|
The |
'Scott'
|
freq
|
bool
|
Draw counts instead of densities. Forces |
False
|
col
|
str | None
|
Fill colour of the histogram bars. Default: |
None
|
border
|
str | None
|
Border colour of the bars. Default: |
None
|
col_out
|
str | None
|
Fill colour of the bars in the tails beyond the observed value. Default: |
None
|
col_ref
|
str | None
|
Colour of the theoretical null distribution. Default: |
None
|
col_density
|
str | None
|
Colour of the kernel density estimate. Default: |
None
|
trim
|
float
|
Fraction of the permutations dropped from the histogram, which must be below 0.5. The omnibus panels drop the upper |
0.0
|
adjust
|
float
|
Bandwidth adjustment of the kernel density estimate, as the |
1.0
|
lwd
|
float | Sequence[float]
|
Line widths of the dashed line at the observed value, of the theoretical null distribution, of the kernel density estimate and
of the vertical line at zero (coefficient panels only). A width of 0 leaves the element out. A single number is used for the
first three and 4 for the last; two or three values are completed to four (the second is repeated for the third, the last
defaults to 4). Default: |
(2, 0, 0, 4)
|
legend
|
bool | str
|
|
False
|
alternative
|
str | None
|
|
None
|
p2defn
|
str | None
|
Definition of the two-sided p-value, |
None
|
stat
|
str | None
|
Statistic plotted, |
None
|
ax
|
Axes | None
|
Matplotlib axes to draw into; the panels are laid out inside it. Default: the current axes. |
None
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis of every panel. Default: the range of the histogram breaks. The plotted axis extends 4 percent beyond the limits, as in R. |
None
|
layout
|
object
|
Deprecated and ignored; a warning is issued, as in metafor. |
None
|
Returns:
| Type | Description |
|---|---|
PlotPermutestResult
|
A |
PlotPermutestResult
|
coefficient name of each panel, in the same order). |
Raises:
| Type | Description |
|---|---|
InputError
|
|
plot_vif ¶
plot_vif(
x: VIFResult,
breaks: object = 'Scott',
freq: bool = False,
col: str | None = None,
border: str | None = None,
col_out: str | None = None,
col_density: str | None = None,
trim: float = 0.0,
adjust: float = 1.0,
lwd: float | Sequence[float] = (2, 0),
*,
tail: str = 'upper',
ax: Axes | None = None,
xlim: Sequence[float] | None = None,
layout: object = None,
) -> PlotVifResult
Plot the simulated (G)VIFs of a vif result obtained with sim=True (plot.vif.rma).
Mirrors metafor's plot.vif.rma().
One panel is drawn per (G)VIF in x, titled Coefficient: name (Coefficients: name for a set of coefficients). Each panel is the
histogram of the (G)VIFs simulated under independence of the moderators, with the observed (G)VIF as a dashed black vertical line and the
bars beyond it filled with col_out. A (G)VIF beyond the right edge of the plot is drawn at the edge, with an arrow pointing to it.
The kernel density estimate is omitted by default (its lwd is 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
VIFResult
|
The result of vif obtained with |
required |
breaks
|
object
|
The |
'Scott'
|
freq
|
bool
|
Draw counts instead of densities. This turns off the kernel density estimate. Default: |
False
|
col
|
str | None
|
Fill colour of the histogram bars. Default: |
None
|
border
|
str | None
|
Border colour of the bars. Default: |
None
|
col_out
|
str | None
|
Fill colour of the bars beyond the observed (G)VIF. Default: |
None
|
col_density
|
str | None
|
Colour of the kernel density estimate. Default: |
None
|
trim
|
float
|
Fraction (below 0.5) of the largest simulated values dropped from the histogram. Default: 0. |
0.0
|
adjust
|
float
|
Bandwidth adjustment of the kernel density estimate, as the |
1.0
|
lwd
|
float | Sequence[float]
|
Line widths of the dashed line at the observed (G)VIF and of the kernel density estimate; a width of 0 leaves the element out.
A single number is used for both. Default: |
(2, 0)
|
tail
|
str
|
Tail of the simulated distribution filled beyond the observed (G)VIF, |
'upper'
|
ax
|
Axes | None
|
Matplotlib axes to draw into; the panels are laid out inside it. Default: the current axes. |
None
|
xlim
|
Sequence[float] | None
|
Limits of the horizontal axis of every panel. Default: the range of the histogram breaks. The plotted axis extends 4 percent beyond the limits, as in R. |
None
|
layout
|
object
|
Deprecated and ignored; a warning is issued, as in metafor. |
None
|
Returns:
| Type | Description |
|---|---|
PlotVifResult
|
A |
Raises:
| Type | Description |
|---|---|
InputError
|
|