Models¶
Functions that fit a model and the result classes they return, see Fitting models, Binary and count data, Multilevel and multivariate models and Selection models and location-scale models. metafopy.rma is an alias of metafopy.rma_uni.
Fitting¶
rma_uni ¶
rma_uni(
yi: ArrayLike | str | DataFrame | None = None,
vi: ArrayLike | str | None = None,
*,
sei: ArrayLike | str | None = None,
weights: 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,
x1i: ArrayLike | str | None = None,
x2i: ArrayLike | str | None = None,
t1i: ArrayLike | str | None = None,
t2i: ArrayLike | str | None = None,
m1i: ArrayLike | str | None = None,
m2i: ArrayLike | str | None = None,
sd1i: ArrayLike | str | None = None,
sd2i: ArrayLike | str | None = None,
xi: ArrayLike | str | None = None,
mi: ArrayLike | str | None = None,
ri: ArrayLike | str | None = None,
ti: ArrayLike | str | None = None,
fi: ArrayLike | str | None = None,
pi: ArrayLike | str | None = None,
sdi: ArrayLike | str | None = None,
r2i: ArrayLike | str | None = None,
mini: ArrayLike | str | None = None,
maxi: ArrayLike | str | None = None,
ni: ArrayLike | str | None = None,
mods: str | ArrayLike | DataFrame | None = None,
measure: str = 'GEN',
data: DataFrame | None = None,
slab: ArrayLike | str | Sequence[str] | None = None,
subset: ArrayLike | str | None = None,
add: float | None = None,
to: Literal['all', 'only0', 'if0all', 'none'] = 'only0',
drop00: bool = False,
intercept: bool = True,
method: str | Sequence[str] = 'REML',
weighted: bool = True,
test: str = 'z',
level: float = 95,
digits: int | Mapping[str, int] | None = None,
btt: int | Sequence[int] | str | None = None,
att: int | Sequence[int] | str | None = None,
scale: str | ArrayLike | DataFrame | None = None,
link: Literal['log', 'identity'] = 'log',
optbeta: bool = False,
alpha: ArrayLike | None = None,
beta: ArrayLike | None = None,
tau2: float | None = None,
control: Control
| LSControl
| Mapping[str, Any]
| None = None,
verbose: bool | int = False,
na_action: Literal['omit', 'fail', 'pass'] = 'omit',
vtype: str | Sequence[str] = 'LS',
correct: bool = True,
cutoff: float | None = None,
onlyo1: bool = False,
addyi: bool = True,
addvi: bool = True,
knha: bool | None = None,
dfs: float | Sequence[float] | None = None,
i2def: Literal['1', '2'] = '1',
r2def: str = '1',
skipr2: bool = False,
abbrev: bool = False,
skiphes: bool = False,
) -> RMAResult | RMALSResult
Fit an equal-, fixed-, random- or mixed-effects meta-analytic model.
Mirrors metafor's rma.uni() (alias rma). The model is given either as effect sizes with their sampling variances
(yi with vi or sei), as a model formula in yi ('yi ~ ablat + year', which then also supplies the moderators), as an
escalc data frame, or as raw data (ai, bi, ... with measure), in which case the effect sizes are
computed by escalc. Passing scale fits a location-scale model (Viechtbauer & Lopez-Lopez, 2022,
doi:10.1002/jrsm.1562).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yi
|
ArrayLike | str | DataFrame | None
|
Observed effect sizes, as an array or the name of a column of |
None
|
vi
|
ArrayLike | str | None
|
Sampling variances, as an array or a column name. A single value is used for every study. |
None
|
sei
|
ArrayLike | str | None
|
Standard errors, as an array or a column name; their squares are used as |
None
|
weights
|
ArrayLike | str | None
|
Optional custom weights for the fit, as an array or a column name; negative weights raise an error. Required for
|
None
|
ai
|
ArrayLike | str | None
|
2x2 table frequencies (upper left cell). With |
None
|
bi
|
ArrayLike | str | None
|
2x2 table frequencies (upper right cell). |
None
|
ci
|
ArrayLike | str | None
|
2x2 table frequencies (lower left cell). |
None
|
di
|
ArrayLike | str | None
|
2x2 table frequencies (lower right cell). |
None
|
n1i
|
ArrayLike | str | None
|
Group sizes or row totals (first group or row). |
None
|
n2i
|
ArrayLike | str | None
|
Group sizes or row totals (second group or row). |
None
|
x1i
|
ArrayLike | str | None
|
Number of events (first group). |
None
|
x2i
|
ArrayLike | str | None
|
Number of events (second group). |
None
|
t1i
|
ArrayLike | str | None
|
Total person-times (first group). |
None
|
t2i
|
ArrayLike | str | None
|
Total person-times (second group). |
None
|
m1i
|
ArrayLike | str | None
|
Means (first group or time point). |
None
|
m2i
|
ArrayLike | str | None
|
Means (second group or time point). |
None
|
sd1i
|
ArrayLike | str | None
|
Standard deviations (first group or time point). |
None
|
sd2i
|
ArrayLike | str | None
|
Standard deviations (second group or time point). |
None
|
xi
|
ArrayLike | str | None
|
Frequencies of the event of interest. |
None
|
mi
|
ArrayLike | str | None
|
Frequencies of the complement of the event of interest, or the group means. |
None
|
ri
|
ArrayLike | str | None
|
Raw correlation coefficients. |
None
|
ti
|
ArrayLike | str | None
|
Total person-times or t-test statistics. |
None
|
fi
|
ArrayLike | str | None
|
F-test statistics. |
None
|
pi
|
ArrayLike | str | None
|
(Signed) p-values. |
None
|
sdi
|
ArrayLike | str | None
|
Standard deviations. |
None
|
r2i
|
ArrayLike | str | None
|
|
None
|
mini
|
ArrayLike | str | None
|
Minimum values. |
None
|
maxi
|
ArrayLike | str | None
|
Maximum values. |
None
|
ni
|
ArrayLike | str | None
|
None
|
|
mods
|
str | ArrayLike | DataFrame | None
|
Moderators, as a one-sided formula string ( |
None
|
measure
|
str
|
'GEN'
|
|
data
|
DataFrame | None
|
Data frame holding the variables named in the other arguments. |
None
|
slab
|
ArrayLike | str | Sequence[str] | None
|
Study labels, as a sequence or a column name. Defaults to the labels stored by escalc, else |
None
|
subset
|
ArrayLike | str | None
|
Which studies to fit: a boolean array, an array of 0-based indices, or a string expression evaluated on |
None
|
add
|
float | None
|
Constant added to zero cells, counts or frequencies when effect sizes are computed from raw data (default |
None
|
to
|
Literal['all', 'only0', 'if0all', 'none']
|
Which tables get |
'only0'
|
drop00
|
bool
|
Drop studies with no events (or only events) in both groups from the calculations (raw data only). |
False
|
intercept
|
bool
|
Include an intercept when |
True
|
method
|
str | Sequence[str]
|
Estimator of the amount of heterogeneity |
'REML'
|
weighted
|
bool
|
Use inverse-variance weights ( |
True
|
test
|
str
|
Test for the coefficients (case-insensitive): |
'z'
|
level
|
float
|
Confidence interval level in percent ( |
95
|
digits
|
int | Mapping[str, int] | None
|
Number of decimals used when printing, or a mapping with the keys |
None
|
btt
|
int | Sequence[int] | str | None
|
Coefficients to test jointly in the omnibus test, as 0-based indices or a regular expression matched
against coefficient names ( |
None
|
att
|
int | Sequence[int] | str | None
|
Scale coefficients to test jointly, as |
None
|
scale
|
str | ArrayLike | DataFrame | None
|
Scale moderators of a location-scale model: a one-sided formula ( |
None
|
link
|
Literal['log', 'identity']
|
Link function of the scale model, |
'log'
|
optbeta
|
bool
|
Estimate the location coefficients jointly with the scale coefficients (needs |
False
|
alpha
|
ArrayLike | None
|
Fixed values for the scale coefficients ( |
None
|
beta
|
ArrayLike | None
|
Fixed values for the location coefficients ( |
None
|
tau2
|
float | None
|
Fixed value of |
None
|
control
|
Control | LSControl | Mapping[str, Any] | None
|
Settings of the |
None
|
verbose
|
bool | int
|
Print metafor's iteration log of the |
False
|
na_action
|
Literal['omit', 'fail', 'pass']
|
What to do with studies that have missing values (metafor uses the global |
'omit'
|
vtype
|
str | Sequence[str]
|
Type of the sampling variance formula used by escalc for raw data, |
'LS'
|
correct
|
bool
|
Bias correction of escalc for the measures that have one ( |
True
|
cutoff
|
float | None
|
Value above which the absolute value of an estimate computed by escalc is flagged with a warning. The default is 2
for |
None
|
onlyo1
|
bool
|
Passed to escalc: |
False
|
addyi
|
bool
|
Passed to escalc: |
True
|
addvi
|
bool
|
Passed to escalc: the same for the sampling variances |
True
|
knha
|
bool | None
|
|
None
|
dfs
|
float | Sequence[float] | None
|
Degrees of freedom of the t and F tests (the first value is used) instead of |
None
|
i2def
|
Literal['1', '2']
|
Definition of |
'1'
|
r2def
|
str
|
Definition of |
'1'
|
skipr2
|
bool
|
Skip the computation of |
False
|
abbrev
|
bool
|
Shorten the names of the coefficients of |
False
|
skiphes
|
bool
|
Skip the Hessian of location-scale models, so that their standard errors are missing. |
False
|
Returns:
| Type | Description |
|---|---|
RMAResult | RMALSResult
|
The fitted model, an RMAResult (an
RMALSResult when |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
ArgumentError
|
|
NotFoundError
|
a column name given for an argument is not in |
EstimationError
|
every requested |
NotSupportedError
|
escalc does not implement the requested combination of measure and inputs. |
InternalError
|
an internal invariant of escalc does not hold. |
Examples:
>>> from metafopy import datasets, rma
>>> dat = datasets.load("dat.bcg")
>>> rma(measure="RR", ai="tpos", bi="tneg", ci="cpos", di="cneg", data=dat)
rma_mh ¶
rma_mh(
ai: ArrayLike | str | None = None,
bi: ArrayLike | str | None = None,
ci: ArrayLike | str | None = None,
di: ArrayLike | str | None = None,
n1i: ArrayLike | str | None = None,
n2i: ArrayLike | str | None = None,
x1i: ArrayLike | str | None = None,
x2i: ArrayLike | str | None = None,
t1i: ArrayLike | str | None = None,
t2i: ArrayLike | str | None = None,
measure: str = 'OR',
data: DataFrame | None = None,
slab: ArrayLike | str | Sequence[str] | None = None,
subset: ArrayLike | str | None = None,
add: float | Sequence[float] = 0.5,
to: str | Sequence[str] = 'only0',
drop00: bool | Sequence[bool] = True,
correct: bool = True,
level: float = 95,
verbose: bool | int = False,
digits: int = 4,
na_action: Literal['omit', 'fail', 'pass'] = 'omit',
onlyo1: bool = False,
addyi: bool = True,
addvi: bool = True,
) -> MHResult
Fit a Mantel-Haenszel meta-analysis of 2x2 tables (measure 'OR', 'RR', 'RD') or rate data ('IRR', 'IRD').
Mirrors metafor's rma.mh(). The pooled effect is the Mantel-Haenszel
estimate (Mantel & Haenszel, 1959; see metafor's help page for the further references). The individual
effect sizes and sampling variances are computed as by escalc. For odds ratios the result also holds the
Cochran-Mantel-Haenszel test and Tarone's test of heterogeneity, for incidence rate ratios the Mantel-Haenszel test. The first element of
add, to and drop00 is used when computing the individual yi/vi values, the second one for the counts entering the
Mantel-Haenszel estimator (by default nothing is added to them and no study is dropped there).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ai
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, upper left cell (event in group 1), as an array or the name of a column of |
None
|
bi
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, upper right cell (no event in group 1). |
None
|
ci
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, lower left cell (event in group 2). |
None
|
di
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, lower right cell (no event in group 2). |
None
|
n1i
|
ArrayLike | str | None
|
Size of group 1 (row total); can be given instead of |
None
|
n2i
|
ArrayLike | str | None
|
Size of group 2 (row total); can be given instead of |
None
|
x1i
|
ArrayLike | str | None
|
Number of events in group 1 (rate data, |
None
|
x2i
|
ArrayLike | str | None
|
Number of events in group 2 (rate data). |
None
|
t1i
|
ArrayLike | str | None
|
Total person-time of group 1 (rate data). |
None
|
t2i
|
ArrayLike | str | None
|
Total person-time of group 2 (rate data). |
None
|
measure
|
str
|
Effect measure: |
'OR'
|
data
|
DataFrame | None
|
Data frame holding the variables named in the other arguments. |
None
|
slab
|
ArrayLike | str | Sequence[str] | None
|
Study labels, as a sequence or a column name. Defaults to |
None
|
subset
|
ArrayLike | str | None
|
Which studies to use: a boolean array, an array of 0-based indices, or a string expression evaluated on |
None
|
add
|
float | Sequence[float]
|
Constant added to zero cells or counts. A single value, or a pair: the first applies when the |
0.5
|
to
|
str | Sequence[str]
|
Which tables get |
'only0'
|
drop00
|
bool | Sequence[bool]
|
Drop studies with no events (or only events) in both groups. A single value, or a pair as for |
True
|
correct
|
bool
|
Use the continuity correction in the Cochran-Mantel-Haenszel test (odds ratios) and in the Mantel-Haenszel test (incidence rate ratios). |
True
|
level
|
float
|
Confidence interval level in percent ( |
95
|
verbose
|
bool | int
|
Print metafor's progress messages to stderr (and blank lines to stdout). |
False
|
digits
|
int
|
Number of decimals used when printing, stored in the result. |
4
|
na_action
|
Literal['omit', 'fail', 'pass']
|
What to do with studies that have missing values (metafor uses the global |
'omit'
|
onlyo1
|
bool
|
Passed to escalc for the |
False
|
addyi
|
bool
|
Passed to escalc: |
True
|
addvi
|
bool
|
Passed to escalc: the same for the sampling variances |
True
|
Returns:
| Type | Description |
|---|---|
MHResult
|
The fitted model. The pooled estimate is in |
MHResult
|
|
MHResult
|
Cochran-Mantel-Haenszel test (odds ratios) or the Mantel-Haenszel test (incidence rate ratios), |
MHResult
|
different variance (odds ratios), and |
MHResult
|
that do not apply are |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid, or |
Examples:
>>> from metafopy import datasets, rma_mh
>>> dat = datasets.load("dat.bcg")
>>> rma_mh(ai="tpos", bi="tneg", ci="cpos", di="cneg", data=dat)
rma_peto ¶
rma_peto(
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: DataFrame | None = None,
slab: ArrayLike | str | Sequence[str] | None = None,
subset: ArrayLike | str | None = None,
add: float | Sequence[float] = 0.5,
to: str | Sequence[str] = 'only0',
drop00: bool | Sequence[bool] = True,
level: float = 95,
verbose: bool | int = False,
digits: int = 4,
na_action: Literal['omit', 'fail', 'pass'] = 'omit',
) -> PetoResult
Fit Peto's one-step method to a set of 2x2 tables.
Mirrors metafor's rma.peto(). The pooled effect is a log odds ratio
(Yusuf et al., 1985). The first element of add, to and drop00 is used for the individual yi/vi values, the second for the
counts used in the pooled estimate (by default nothing is added to them).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ai
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, upper left cell (event in group 1), as an array or the name of a column of |
None
|
bi
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, upper right cell (no event in group 1). |
None
|
ci
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, lower left cell (event in group 2). |
None
|
di
|
ArrayLike | str | None
|
Frequencies of the 2x2 tables, lower right cell (no event in group 2). |
None
|
n1i
|
ArrayLike | str | None
|
Size of group 1 (row total); can be given instead of |
None
|
n2i
|
ArrayLike | str | None
|
Size of group 2 (row total); can be given instead of |
None
|
data
|
DataFrame | None
|
Data frame holding the variables named in the other arguments. |
None
|
slab
|
ArrayLike | str | Sequence[str] | None
|
Study labels, as a sequence or a column name. Defaults to |
None
|
subset
|
ArrayLike | str | None
|
Which studies to use: a boolean array, an array of 0-based indices, or a string expression evaluated on |
None
|
add
|
float | Sequence[float]
|
Constant added to zero cells. A single value, or a pair: the first applies when the |
0.5
|
to
|
str | Sequence[str]
|
Which tables get |
'only0'
|
drop00
|
bool | Sequence[bool]
|
Drop studies with no events (or only events) in both groups. A single value, or a pair as for |
True
|
level
|
float
|
Confidence interval level in percent ( |
95
|
verbose
|
bool | int
|
Print metafor's progress messages to stderr (and blank lines to stdout). |
False
|
digits
|
int
|
Number of decimals used when printing, stored in the result. |
4
|
na_action
|
Literal['omit', 'fail', 'pass']
|
What to do with studies that have missing values (metafor uses the global |
'omit'
|
Returns:
| Type | Description |
|---|---|
PetoResult
|
The fitted model. The pooled log odds ratio is in |
PetoResult
|
|
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid, or one of the two outcomes never occurred in any table. |
Examples:
>>> from metafopy import datasets, rma_peto
>>> dat = datasets.load("dat.bcg")
>>> rma_peto(ai="tpos", bi="tneg", ci="cpos", di="cneg", data=dat)
rma_glmm ¶
rma_glmm(
*,
ai: ArrayLike | str | None = None,
bi: ArrayLike | str | None = None,
ci: ArrayLike | str | None = None,
di: ArrayLike | str | None = None,
n1i: ArrayLike | str | None = None,
n2i: ArrayLike | str | None = None,
x1i: ArrayLike | str | None = None,
x2i: ArrayLike | str | None = None,
t1i: ArrayLike | str | None = None,
t2i: ArrayLike | str | None = None,
xi: ArrayLike | str | None = None,
mi: ArrayLike | str | None = None,
ti: ArrayLike | str | None = None,
ni: ArrayLike | str | None = None,
mods: str | ArrayLike | DataFrame | None = None,
measure: str | None = None,
data: DataFrame | None = None,
slab: ArrayLike | str | Sequence[str] | None = None,
subset: ArrayLike | str | None = None,
add: float | Sequence[float] = 0.5,
to: str | Sequence[str] = 'only0',
drop00: bool | Sequence[bool] = True,
intercept: bool = True,
model: str | None = None,
method: str = 'ML',
coding: float = 0.5,
cor: bool = False,
test: str = 'z',
level: float = 95,
btt: int | Sequence[int] | str | None = None,
nAGQ: int = 7,
verbose: bool | int = False,
digits: int = 4,
control: GLMMControl | Mapping[str, Any] | None = None,
na_action: Literal['omit', 'fail', 'pass'] = 'omit',
i2def: str = '1',
onlyo1: bool = False,
addyi: bool = True,
addvi: bool = True,
link: str | None = None,
family: GLMFamily | str | None = None,
) -> GLMMResult
Fit a generalized linear mixed-effects model to binary or count data.
Mirrors metafor's rma.glmm(). measure is
'OR' (2x2 tables: ai, bi, ci, di or ai, ci,
n1i, n2i), 'IRR' (x1i, x2i, t1i, t2i), 'PLO'
(xi and mi or ni) or 'IRLN' (xi, ti). model is
'UM.FS' (the default), 'UM.RS', 'CM.AL' or 'CM.EL' and
method 'ML' or 'FE' ('EE', 'CE'). Only the first of
several add, to and drop00 values is used. All arguments are keyword-only.
The experimental measures 'RR' and 'RD' (arguments as for 'OR',
unconditional models only) and 'PR' and 'PLN' (arguments as for
'PLO') are fitted as metafor does and give its warning that their use is
experimental; as in metafor, the log and identity links can put fitted
probabilities outside (0, 1), in which case fitting fails (EstimationError)
or the estimates are unreliable.
link (one of 'logit', 'probit', 'cauchit', 'cloglog', 'log', 'identity', 'sqrt') replaces the
link of the model and family ('binomial', 'poisson' or metafopy.core.glm.binomial /
metafopy.core.glm.poisson, which carry a link) replaces family and link, like metafor's link and family
arguments passed through .... They apply to the unconditional models ('UM.FS', 'UM.RS') and the one-group
measures, the models that metafor fits with glm() and glmer(); the conditional models ignore them as in metafor.
The family must match the data (binomial for 'OR', 'RR', 'RD', 'PLO', 'PR', 'PLN', Poisson for
'IRR' and 'IRLN').
control={'optimizer': 'clogit'} or 'clogistic' fits the fixed-effects (method='FE') conditional model
'CM.EL' for 'OR' with survival::clogit() or Epi::clogistic() (implemented in metafopy.core.clogit,
without building the individual patient data); clogitCtrl and clogisticCtrl entries of control are passed on
as in metafor (see metafopy.core.clogit.clogit_settings and metafopy.core.clogit.clogistic_settings).
The default 'nlminb' maximises the exact likelihood numerically. The other optimisers of metafor's control$optimizer
('optim' with optmethod, 'Nelder-Mead', 'BFGS', 'CG', 'L-BFGS-B', 'nlm', 'uobyqa', 'newuoa',
'bobyqa', ...) maximise it as metafopy.models.sel_opt minimises: optim with BFGS or Nelder-Mead is R's routine
(optCtrl takes maxit, reltol, abstol and ndeps), the others stand in with the closest SciPy method. The Wald test
of the saturated model (QE_Wld) of 'CM.EL' can be ill-conditioned; for some data sets it differs between optimisers in R as well.
The Hessian of 'CM.EL' is computed as control={'hesspack': ..., 'hessianCtrl': {...}} asks ('numDeriv' with r = 16
unless hessianCtrl gives r, 'pracma' with h, 'calculus' with accuracy and stepsize). Unlike metafor, whose
default is the density of BiasedUrn::dFNCHypergeo with precision dnchgprec (1e-10), metafopy uses the untruncated density
(dnchgcalc='dnoncenhypergeom') by default; control={'dnchgcalc': 'dFNCHypergeo'} or a dnchgprec entry selects a port of
BiasedUrn's algorithm including the truncation of the tails that makes R's finite-difference standard errors noisy.
control={'package': ...} chooses the package that fits the mixed models, as in metafor:
'lme4' (the default), 'GLMMadaptive' (adaptive quadrature with nAGQ points in every
dimension, so that 'UM.RS' with method='ML' is not reduced to nAGQ = 1; it fails, like
metafor, when a coefficient other than the first exceeds 12 in absolute value, the default max_coef_value of GLMMadaptive 0.9-7) or 'glmmTMB'
(Laplace approximation, nAGQ is ignored). They maximise the same likelihood and differ in
the integration, in what log-likelihood they report and in the convergence tolerances; see
docs/differences.md.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ai
|
ArrayLike | str | None
|
2x2 table frequencies, upper left cell (event in group 1), as an array or the name of a column of |
None
|
bi
|
ArrayLike | str | None
|
2x2 table frequencies, upper right cell (no event in group 1). |
None
|
ci
|
ArrayLike | str | None
|
2x2 table frequencies, lower left cell (event in group 2). |
None
|
di
|
ArrayLike | str | None
|
2x2 table frequencies, lower right cell (no event in group 2). |
None
|
n1i
|
ArrayLike | str | None
|
Size of group 1 (row total); an alternative to |
None
|
n2i
|
ArrayLike | str | None
|
Size of group 2 (row total); an alternative to |
None
|
x1i
|
ArrayLike | str | None
|
Number of events in group 1 ( |
None
|
x2i
|
ArrayLike | str | None
|
Number of events in group 2 ( |
None
|
t1i
|
ArrayLike | str | None
|
Total person-time of group 1 ( |
None
|
t2i
|
ArrayLike | str | None
|
Total person-time of group 2 ( |
None
|
xi
|
ArrayLike | str | None
|
Number of events (one-group measures |
None
|
mi
|
ArrayLike | str | None
|
Number of non-events ( |
None
|
ti
|
ArrayLike | str | None
|
Total person-time ( |
None
|
ni
|
ArrayLike | str | None
|
Sample size ( |
None
|
mods
|
str | ArrayLike | DataFrame | None
|
Moderators, as a one-sided formula string ( |
None
|
measure
|
str | None
|
Outcome measure, required: |
None
|
data
|
DataFrame | None
|
Data frame holding the variables named in the other arguments. |
None
|
slab
|
ArrayLike | str | Sequence[str] | None
|
Study labels, as a sequence or a column name. Defaults to |
None
|
subset
|
ArrayLike | str | None
|
Which studies to use: a boolean array, an array of 0-based indices, or a string expression evaluated on |
None
|
add
|
float | Sequence[float]
|
Constant added to zero cells, counts or frequencies when computing the |
0.5
|
to
|
str | Sequence[str]
|
Which tables get |
'only0'
|
drop00
|
bool | Sequence[bool]
|
Drop studies with no events (or only events) in both groups (only the first value of a sequence is used). Default |
True
|
intercept
|
bool
|
Include an intercept when |
True
|
model
|
str | None
|
Model for 2x2 tables ( |
None
|
method
|
str
|
|
'ML'
|
coding
|
float
|
Coding of the group variable in the random-effects structure of the unconditional models ( |
0.5
|
cor
|
bool
|
Allow the random study effects and the random group effects of |
False
|
test
|
str
|
Test for the coefficients: |
'z'
|
level
|
float
|
Confidence interval level in percent ( |
95
|
btt
|
int | Sequence[int] | str | None
|
Coefficients to test jointly in the omnibus test, as 0-based indices or a regular expression matched against coefficient names. Default: all coefficients but the intercept (the intercept itself for a model without moderators). |
None
|
nAGQ
|
int
|
Number of quadrature points per dimension of the adaptive Gauss-Hermite approximation of the likelihood of the mixed models (default
7); |
7
|
verbose
|
bool | int
|
Print metafor's progress messages to stderr ( |
False
|
digits
|
int
|
Number of decimals used when printing, stored in the result. |
4
|
control
|
GLMMControl | Mapping[str, Any] | None
|
Optimiser and package settings, as a GLMMControl or a mapping with metafor's names ( |
None
|
na_action
|
Literal['omit', 'fail', 'pass']
|
What to do with studies that have missing values, in the table data or the moderators (metafor uses the global |
'omit'
|
i2def
|
str
|
Definition of |
'1'
|
onlyo1
|
bool
|
Passed to escalc for the |
False
|
addyi
|
bool
|
Passed to escalc: |
True
|
addvi
|
bool
|
Passed to escalc: the same for the sampling variances |
True
|
link
|
str | None
|
Link function replacing the one of the model: |
None
|
family
|
GLMFamily | str | None
|
Family replacing the family and link of the model: |
None
|
Returns:
| Type | Description |
|---|---|
GLMMResult
|
The fitted model. Coefficients are in |
GLMMResult
|
|
GLMMResult
|
omnibus test; |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid. |
EstimationError
|
a model cannot be fitted. |
NotSupportedError
|
the optimiser chosen in |
InternalError
|
a binomial model was built without its group sizes. |
Examples:
>>> from metafopy import datasets, rma_glmm
>>> dat = datasets.load("dat.bcg")
>>> rma_glmm(ai="tpos", bi="tneg", ci="cpos", di="cneg", data=dat, measure="OR")
rma_mv ¶
rma_mv(
yi: object,
V: object,
*,
W: object = None,
mods: object = None,
data: DataFrame | None = None,
slab: object = None,
subset: ArrayLike | str | None = None,
random: str | Sequence[str] | None = None,
struct: str | Sequence[str] | None = None,
intercept: bool = True,
method: str = 'REML',
test: str = 'z',
dfs: str | float | Sequence[float] = 'residual',
level: float = 95,
digits: int | Mapping[str, int] | None = None,
btt: int | Sequence[int] | str | None = None,
R: Mapping[str, object] | None = None,
Rscale: str | bool | int = 'cor',
sigma2: ArrayLike | None = None,
tau2: ArrayLike | None = None,
rho: ArrayLike | None = None,
gamma2: ArrayLike | None = None,
phi: ArrayLike | None = None,
sparse: bool = False,
dist: object = 'euclidean',
cvvc: bool | str = False,
optbeta: bool = False,
beta: ArrayLike | None = None,
lambda1: float = 0.0,
lambda2: float = 0.0,
vccon: Mapping[str, ArrayLike] | None = None,
restart: RMAMVResult | bool | None = None,
control: MVControl | Mapping[str, Any] | None = None,
verbose: bool | int = False,
na_action: Literal['omit', 'fail', 'pass'] = 'omit',
) -> RMAMVResult
Fit a multivariate/multilevel meta-analytic model.
Mirrors metafor's rma.mv(). yi is a vector, a column
of data or a model formula ('yi ~ x1 + x2'); V is a vector of sampling variances, a k x k matrix, a list of
block matrices (see bldiag), a column name or 0. random is a formula such as '~ 1 | study',
'~ 1 | district/school' or '~ outcome | study' (or a list of them), struct (default 'CS') the variance-covariance structure of
the ~ inner | outer terms and R a dict of known correlation matrices (DataFrames with dimension names) keyed by the
grouping variable. sigma2, tau2, rho, gamma2 and phi fix the corresponding parameters (nan entries are
estimated). dfs is 'residual', 'contain' or numeric. digits (a number of decimals, or a mapping with the keys est, se,
... of which est is used) is stored in the result and used by its printout unless digits is passed to summary() or set with
metafopy.setmfopt.
cvvc (False, True, 'varcor', 'varcov' or 'transf') requests the Hessian of the variance components
and its inverse (hessian and vvc of the result): variances and correlations for True/'varcor', variances
and covariances for 'varcov' (UN and GEN structures only), the transformed parameters for 'transf'. With
optbeta=True the coefficients are optimised together with the variance components, and their covariance matrix is
taken from the inverse Hessian (lambda1 and lambda2 add a lasso and ridge penalty on the coefficients other than
the intercept and imply optbeta=True; see https://github.com/wviechtb/metafor/blob/master/R/rma.mv.r). beta fixes
coefficients (nan entries are estimated). vccon is a dict with the keys sigma2, tau2, rho, gamma2
and phi whose entries are group ids: components with the same id are constrained to be equal. restart is a
previous fit of the same model whose variance components are the starting values, or True for the last values the optimiser tried in
this session, as metafor's restart=TRUE (also after a fit that did not converge).
The Hessians are the Richardson extrapolation of numDeriv (hesspack='numDeriv').
verbose prints metafor's table of the variance components and a log line per evaluation of the log-likelihood to
stdout (the optimiser differs from metafor's nlminb, so the sequence of evaluations differs too) and, with
verbose=2 or more, its progress messages to stderr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yi
|
object
|
Observed effect sizes, as a vector, the name of a column of |
required |
V
|
object
|
Sampling variances or covariances: a vector of variances, a |
required |
W
|
object
|
Optional weights of the fit, as a vector, a column name or a |
None
|
mods
|
object
|
Moderators, as a one-sided formula string ( |
None
|
data
|
DataFrame | None
|
Data frame holding the variables named in the other arguments. |
None
|
slab
|
object
|
Study labels, as a sequence or a column name. Defaults to |
None
|
subset
|
ArrayLike | str | None
|
Which rows to use: a boolean array, an array of 0-based indices, or a string expression evaluated on |
None
|
random
|
str | Sequence[str] | None
|
Random effects, a formula such as |
None
|
struct
|
str | Sequence[str] | None
|
Variance-covariance structure of the |
None
|
intercept
|
bool
|
Include an intercept in the model with moderators. Ignored (the formula decides) when |
True
|
method
|
str
|
|
'REML'
|
test
|
str
|
Test for the coefficients: |
'z'
|
dfs
|
str | float | Sequence[float]
|
Degrees of freedom of the t tests: |
'residual'
|
level
|
float
|
Confidence interval level in percent ( |
95
|
digits
|
int | Mapping[str, int] | None
|
Number of decimals used when printing, or a mapping with the keys |
None
|
btt
|
int | Sequence[int] | str | None
|
Coefficients to test jointly in the omnibus test, as 0-based indices or a regular expression matched against coefficient names. Default: all but the intercept. |
None
|
R
|
Mapping[str, object] | None
|
Known correlation matrices of the random effects, a mapping from the name of the grouping variable to a matrix (a data frame with dimension names). |
None
|
Rscale
|
str | bool | int
|
How |
'cor'
|
sigma2
|
ArrayLike | None
|
Fixed values for the variance components of the |
None
|
tau2
|
ArrayLike | None
|
Fixed values for the variance components of the inner factor of the first |
None
|
rho
|
ArrayLike | None
|
Fixed values for the correlation parameters of the first |
None
|
gamma2
|
ArrayLike | None
|
As |
None
|
phi
|
ArrayLike | None
|
As |
None
|
sparse
|
bool
|
Use sparse matrices, which can be faster for large models. |
False
|
dist
|
object
|
Distance measure for the spatial structures ( |
'euclidean'
|
cvvc
|
bool | str
|
Compute the Hessian of the variance components and its inverse ( |
False
|
optbeta
|
bool
|
Optimise the coefficients together with the variance components; their covariance matrix is then taken from the inverse Hessian. |
False
|
beta
|
ArrayLike | None
|
Fixed values for the coefficients ( |
None
|
lambda1
|
float
|
Lasso penalty on the coefficients other than the intercept; a positive value implies |
0.0
|
lambda2
|
float
|
Ridge penalty on the coefficients other than the intercept; a positive value implies |
0.0
|
vccon
|
Mapping[str, ArrayLike] | None
|
Constraints on the variance components, a mapping with the keys |
None
|
restart
|
RMAMVResult | bool | None
|
Starting values for the variance components: a previous fit of the same model, or |
None
|
control
|
MVControl | Mapping[str, Any] | None
|
Optimiser settings, as an MVControl or a mapping with metafor's names ( |
None
|
verbose
|
bool | int
|
Print metafor's table of the variance components and a log line per likelihood evaluation to stdout (the optimiser differs from
metafor's |
False
|
na_action
|
Literal['omit', 'fail', 'pass']
|
What to do with rows that have missing values (metafor uses the global |
'omit'
|
Returns:
| Type | Description |
|---|---|
RMAMVResult
|
The fitted model. Coefficients are in |
RMAMVResult
|
their covariance matrix in |
RMAMVResult
|
when the model has no such component, see |
RMAMVResult
|
|
RMAMVResult
|
rma_uni. |
Raises:
| Type | Description |
|---|---|
InputError
|
an argument or the data is invalid (including an unknown |
ArgumentError
|
|
NotSupportedError
|
|
EstimationError
|
the model could not be fitted (for example when the marginal variance-covariance matrix is not positive definite at the starting values). |
InternalError
|
a random-effects structure built on an inner factor has none. |
NotFoundError
|
a variable is not found in the data. |
selmodel ¶
selmodel(
x: RMAResult | SelmodelResult,
type: str,
alternative: str = 'greater',
prec: str | None = None,
subset: ArrayLike | None = None,
delta: Any = None,
steps: Any = None,
decreasing: bool = False,
verbose: bool | int = False,
digits: int | None = None,
control: Mapping[str, Any] | None = None,
**kwargs: Any,
) -> SelmodelResult | DataFrame | NDArray[float64]
Fit a selection model to a fitted rma_uni model (metafor's selmodel.rma.uni).
Mirrors metafor's selmodel(). A selection model describes how the
probability that an estimate is observed depends on its p-value (and optionally its precision); it is used to assess and adjust for publication
bias (Vevea & Hedges, 1995; Citkowicz & Vevea, 2017; Preston, Ashby & Smyth, 2004). Models that were not fitted with ML (or as an
equal/fixed-effects model) are refitted with ML first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
RMAResult | SelmodelResult
|
A model fitted by rma_uni (not a robust one), or an earlier selection model, whose base model is used. Models with non-positive sampling variances, or unweighted or custom-weighted ones, are refused. |
required |
type
|
str
|
Selection function: |
required |
alternative
|
str
|
Direction of the one-sided p-values: |
'greater'
|
prec
|
str | None
|
Measure of precision the selection function may depend on: |
None
|
subset
|
ArrayLike | None
|
Which studies the selection function applies to (the others are always observed): a boolean or 0-based index vector over the studies
of |
None
|
delta
|
Any
|
Fixed values of the selection parameters, one per parameter of the chosen type ( |
None
|
steps
|
Any
|
Values whose meaning depends on |
None
|
decreasing
|
bool
|
For |
False
|
verbose
|
bool | int
|
Print the progress of the optimiser (to stderr); larger values print more. |
False
|
digits
|
int | None
|
Number of decimals used when printing, stored in the result. Default ( |
None
|
control
|
Mapping[str, Any] | None
|
Optimiser settings as a mapping with metafor's names ( |
None
|
**kwargs
|
Any
|
Further arguments as in metafor: |
{}
|
Returns:
| Type | Description |
|---|---|
SelmodelResult | DataFrame | NDArray[float64]
|
The fitted selection model, a SelmodelResult with the location coefficients in |
SelmodelResult | DataFrame | NDArray[float64]
|
parameters in |
SelmodelResult | DataFrame | NDArray[float64]
|
selection. With |
SelmodelResult | DataFrame | NDArray[float64]
|
|
SelmodelResult | DataFrame | NDArray[float64]
|
fitted as usual. With |
SelmodelResult | DataFrame | NDArray[float64]
|
matrix if |
SelmodelResult | DataFrame | NDArray[float64]
|
given); metafor returns the whole optimiser result instead. |
Raises:
| Type | Description |
|---|---|
ArgumentError
|
|
InputError
|
an argument or the data is invalid (unknown |
EstimationError
|
the optimiser did not converge or the likelihood could not be integrated. |
NotSupportedError
|
the optimiser chosen in |
Results¶
RMAResult
dataclass
¶
RMAResult(
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
coef_names: tuple[str, ...],
tau2: float,
se_tau2: float,
k: int,
p: int,
m: int,
btt: tuple[int, ...],
QE: float,
QEp: float,
QM: float,
QMp: float,
QMdf: tuple[int, float | None],
I2: float,
H2: float,
R2: float | None,
vt: float,
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
parms: int,
method: str,
test: Test,
level: float,
ddf: int | None,
s2w: float,
weighted: bool,
weights: FloatArray | None,
tau2_fix: bool,
int_only: bool,
int_incl: bool,
allvipos: bool,
yi: FloatArray,
vi: FloatArray,
X: FloatArray,
slab: tuple[str, ...],
data: MetaData,
control: Control,
iterations: int = 0,
measure: str = 'GEN',
robust: RobustInfo | None = None,
digits: int = 4,
coef_na: tuple[bool, ...] = (),
X_f: FloatArray = (lambda: empty((0, 0)))(),
add: float = 0.5,
to: str = 'only0',
drop00: bool = False,
*,
call: Call | None = None,
)
Bases: DataFields, RobustFields, FitMethods
A fitted rma.uni model.
Array attributes follow metafor's names with . replaced by _
(ci_lb, se_tau2). btt holds 0-based coefficient indices.
tau2_f
property
¶
tau2_f: float
The amount of heterogeneity, metafor's tau2.f (the same number as tau2 here).
dfs
property
¶
The degrees of freedom of the tests (metafor's dfs): ddf for test='t' or 'knha', those of :func:metafopy.robust for a robust fit.
A model made robust has a single number (the number of clusters minus p) for the default method and one value per coefficient for
club_sandwich=True, for which ddf stays None because it holds a single number.
coef ¶
Estimated coefficients, indexed by name; type is accepted for metafor's coef(x, type=) and only location-scale fits use it.
vcov ¶
vcov(
type: Literal[
'fixed',
'beta',
'alpha',
'delta',
'obs',
'marginal',
'fitted',
'resid',
] = 'fixed',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> DataFrame
Variance-covariance matrix of the coefficients, or with type of the observed effects; see :func:metafopy.vcov.
fitted ¶
Fitted values X beta.
na_action is 'omit' (the studies used in fitting), 'exclude', 'pass' or 'fail', as in :func:metafopy.residuals.
residuals ¶
residuals(
type: Literal[
'response',
'rstandard',
'rstudent',
'pearson',
'cholesky',
] = 'response',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Residuals; see :func:metafopy.residuals (type is 'response', 'rstandard', 'rstudent', 'pearson' or 'cholesky').
weights_ ¶
weights_(
type: Literal['diagonal', 'matrix'] = 'diagonal',
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Percentage weights of the estimates in the model fit (type='diagonal') or the weight matrix ('matrix'), metafor's weights().
na_action is 'omit', 'exclude', 'pass' or 'fail' as in :func:metafopy.residuals.
hatvalues ¶
hatvalues(
type: Literal['diagonal', 'matrix'] = 'diagonal',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Diagonal of the hat matrix (type='diagonal') or the hat matrix itself ('matrix'), as metafor's hatvalues().
With na_action='exclude' or 'pass' the studies left out because of missing values are NaN rows (and columns); 'fail' stops if any were.
Raises:
| Type | Description |
|---|---|
InputError
|
|
plot ¶
Draw the forest, funnel, radial and residual plots with :func:metafopy.plot.plot_rma.
summary ¶
summary(
digits: int | Mapping[str, int] | None = None,
showfit: bool = True,
*,
signif_stars: bool | None = None,
signif_legend: bool | None = None,
num: bool = False,
) -> str
The printout with the fit statistics table, as metafor's summary(); str(res) leaves it out like print().
digits defaults to the digits option, else to the digits the model was fitted with. signif_stars (default: the
signif_stars option, True) adds the significance stars and signif_legend (default: signif_stars) the legend of the codes.
num numbers the rows of the table of coefficients (print(x, num = TRUE) in metafor).
FitStats
dataclass
¶
Log-likelihood, deviance and information criteria (metafor's fit.stats).
RMALSResult
dataclass
¶
RMALSResult(
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
coef_names: tuple[str, ...],
alpha: FloatArray,
va: FloatArray,
se_alpha: FloatArray,
zval_alpha: FloatArray,
pval_alpha: FloatArray,
ci_lb_alpha: FloatArray,
ci_ub_alpha: FloatArray,
alpha_names: tuple[str, ...],
alpha_fix: BoolArray,
tau2: FloatArray,
k: int,
p: int,
q: int,
m: int,
m_alpha: int,
btt: tuple[int, ...],
att: tuple[int, ...],
QE: float,
QEp: float,
QM: float,
QMp: float,
QMdf: tuple[int, float | None],
QS: float,
QSp: float,
QSdf: tuple[int, float | None],
I2: FloatArray,
H2: FloatArray,
vt: float,
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
parms: int,
method: str,
test: Test,
level: float,
ddf: int | None,
ddf_alpha: int | None,
s2w: float,
weighted: bool,
weights: FloatArray | None,
link: str,
optbeta: bool,
beta_fix: BoolArray,
int_only: bool,
int_incl: bool,
Z_int_only: bool,
Z_int_incl: bool,
allvipos: bool,
yi: FloatArray,
vi: FloatArray,
X: FloatArray,
Z: FloatArray,
slab: tuple[str, ...],
data: MetaData,
control: LSControl,
vcovmat: FloatArray | None = None,
H: FloatArray | None = None,
tau2_fix: bool = False,
measure: str = 'GEN',
formula_scale: str | None = None,
Z_f: FloatArray | None = None,
digits: int = 4,
coef_na: tuple[bool, ...] = (),
coef_na_Z: tuple[bool, ...] = (),
X_f: FloatArray = (lambda: empty((0, 0)))(),
add: float = 0.5,
to: str = 'only0',
drop00: bool = False,
*,
call: Call | None = None,
)
Bases: DataFields, FitMethods
A fitted location-scale model.
The location part (beta, se, ..., vb) and the scale part
(alpha, se_alpha, ..., va) follow metafor's names with . replaced
by _. tau2 holds the fitted heterogeneity of every study used in the fit.
btt and att are 0-based coefficient indices.
se_tau2
property
¶
se_tau2: float
Not available for location-scale models (NaN, as metafor stores NA).
randhet
property
¶
randhet: bool
Whether random heterogeneity is modelled (always False here, metafor's randhet).
Z_intercept
property
¶
Z_intercept: bool
Whether the scale model has an intercept, metafor's Z.intercept.
dfs
property
¶
dfs: int | None
The degrees of freedom of the tests of the location coefficients (None for the z-test), metafor's dfs.
tau2_f
property
¶
tau2_f: FloatArray
The amount of residual heterogeneity of each study after subsetting, NaN for those left out of the fit, metafor's tau2.f.
coef ¶
Location ('beta') and/or scale ('alpha') coefficients, indexed by name.
vcov ¶
vcov(
type: Literal[
'fixed',
'beta',
'alpha',
'delta',
'obs',
'marginal',
'fitted',
'resid',
] = 'fixed',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> DataFrame | dict[str, DataFrame]
Variance-covariance matrices; 'fixed' (the default) gives {'beta': ..., 'alpha': ...}, the other types follow :func:metafopy.vcov.
fitted ¶
fitted(
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> dict[str, NDArray[float64]]
Fitted location values X beta and scale values Z alpha (the latter on the link scale); na_action is as for rma_uni fits.
residuals ¶
residuals(
type: Literal[
'response',
'rstandard',
'rstudent',
'pearson',
'cholesky',
] = 'response',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Residuals; see :func:metafopy.residuals (type is 'response', 'rstandard', 'rstudent', 'pearson' or 'cholesky').
weights_ ¶
weights_(
type: Literal['diagonal', 'matrix'] = 'diagonal',
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Percentage weights of the estimates in the model fit (type='diagonal') or the weight matrix ('matrix'), metafor's weights().
na_action is 'omit', 'exclude', 'pass' or 'fail' as in :func:metafopy.residuals.
hatvalues ¶
hatvalues(
type: Literal['diagonal', 'matrix'] = 'diagonal',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Diagonal of the hat matrix (type='diagonal') or the hat matrix itself ('matrix'), as metafor's hatvalues().
With na_action='exclude' or 'pass' the studies left out because of missing values are NaN rows (and columns); 'fail' stops if any were.
Raises:
| Type | Description |
|---|---|
InputError
|
|
summary ¶
summary(
digits: int | Mapping[str, int] | None = None,
showfit: bool = True,
*,
signif_stars: bool | None = None,
signif_legend: bool | None = None,
num: bool = False,
) -> str
The printout with the fit statistics table, as metafor's summary(); str(res) leaves it out like print().
digits defaults to the digits option, else to the digits the model was fitted with; signif_stars, signif_legend and
num as for :meth:metafopy.models.rma_uni.RMAResult.summary.
MHResult
dataclass
¶
MHResult(
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
tau2: float,
I2: float,
H2: float,
QE: float,
QEp: float,
k: int,
k_f: int,
k_yi: int,
k_all: int,
k_pos: int | None,
p: int,
parms: int,
measure: str,
level: float,
add: tuple[float, float],
to: tuple[str, str],
drop00: tuple[bool, bool],
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
tables: TableSet,
data: DataFrame | None = None,
digits: int = 4,
coef_names: tuple[str, ...] = ('intrcpt',),
method: str = 'FE',
test: str = 'z',
int_only: bool = True,
weighted: bool = True,
CO: float = NAN,
COp: float = NAN,
MH: float = NAN,
MHp: float = NAN,
BD: float = NAN,
BDp: float = NAN,
TA: float = NAN,
TAp: float = NAN,
correct: bool = True,
*,
call: Call | None = None,
)
Bases: FixedBinaryResult
A fitted rma.mh model; CO/MH are the Cochran and Mantel-Haenszel tests, BD/TA the Breslow-Day and Tarone tests (odds ratios only).
PetoResult
dataclass
¶
PetoResult(
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
tau2: float,
I2: float,
H2: float,
QE: float,
QEp: float,
k: int,
k_f: int,
k_yi: int,
k_all: int,
k_pos: int | None,
p: int,
parms: int,
measure: str,
level: float,
add: tuple[float, float],
to: tuple[str, str],
drop00: tuple[bool, bool],
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
tables: TableSet,
data: DataFrame | None = None,
digits: int = 4,
coef_names: tuple[str, ...] = ('intrcpt',),
method: str = 'FE',
test: str = 'z',
int_only: bool = True,
weighted: bool = True,
*,
call: Call | None = None,
)
Bases: FixedBinaryResult
A fitted rma.peto model (the pooled effect is a log odds ratio).
GLMMResult
dataclass
¶
GLMMResult(
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
tau2: float,
se_tau2: float,
sigma2: float,
rho: float,
ci_lb_tau2: float,
ci_ub_tau2: float,
I2: float,
H2: float,
vt: float,
QE_Wld: float,
QEp_Wld: float,
QE_LRT: float,
QEp_LRT: float,
QE_df: int | None,
QM: float,
QMdf: tuple[int, int | None],
QMp: float,
k: int,
k_f: int,
k_yi: int,
k_eff: int,
k_all: int,
p: int,
p_eff: int,
parms: int,
int_only: bool,
int_incl: bool,
intercept: bool,
X: FloatArray,
X_f: FloatArray,
coef_names: tuple[str, ...],
tables: TableSet,
measure: str,
method: str,
model: str,
weighted: bool,
test: str,
ddf: int | None,
btt: tuple[int, ...],
m: int,
digits: int,
level: float,
add: float,
to: str,
drop00: bool,
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
se_warn: bool,
data: DataFrame | None = None,
*,
call: Call | None = None,
control: Any = None,
)
Bases: TableFields, FitMethods
A fitted rma.glmm model: a generalized linear mixed-effects model for binary or count data.
beta, se, zval, pval, ci_lb, ci_ub and vb hold one element per coefficient
(coef_names). QE_Wld and QE_LRT are the Wald-type and likelihood ratio tests for (residual)
heterogeneity, QM the omnibus test of the coefficients btt (0-based). level is the
significance level alpha (0.05 for 95% intervals), as in metafor. tables keeps the counts
and the yi/vi used for I2/H2.
outdat_f
property
¶
The counts of the tables after subsetting; ni holds the sample sizes of those tables, as in metafor's outdat.f.
See rma.glmm in https://github.com/wviechtb/metafor/blob/master/R/rma.glmm.r.
dfs
property
¶
dfs: int | None
The degrees of freedom of the tests of the coefficients (None for the z-test), metafor's dfs.
coef ¶
Estimated coefficients, indexed by name; type is accepted for metafor's coef(x, type=) and only location-scale fits use it.
vcov ¶
vcov(
type: Literal[
'fixed',
'beta',
'alpha',
'delta',
'obs',
'marginal',
'fitted',
'resid',
] = 'fixed',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> DataFrame
Variance-covariance matrix of the coefficients, or with type='fitted' of the fitted values; see :func:metafopy.vcov.
fitted ¶
Fitted values X beta of the tables used in fitting (metafor's fitted.rma; na_action as for rma_uni fits).
weights_ ¶
Not available (metafor's weights() stops for this class).
Raises:
| Type | Description |
|---|---|
NotSupportedError
|
always. |
residuals ¶
residuals(
type: Literal[
'response',
'rstandard',
'rstudent',
'pearson',
'cholesky',
] = 'response',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Residuals; see :func:metafopy.residuals (type is 'response', 'rstandard', 'rstudent', 'pearson' or 'cholesky').
summary ¶
summary(
digits: int | None = None,
showfit: bool = True,
*,
signif_stars: bool | None = None,
signif_legend: bool | None = None,
num: bool = False,
) -> str
The printout with the fit statistics table, as metafor's summary(); str(res) leaves it out like print().
signif_stars (default: the signif_stars option, True) adds the significance stars, signif_legend (default: signif_stars)
their legend, num numbers the rows of the table of coefficients.
RMAMVResult
dataclass
¶
RMAMVResult(
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
coef_names: tuple[str, ...],
sigma2: FloatArray | None,
tau2: FloatArray | None,
rho: FloatArray | None,
gamma2: FloatArray | None,
phi: FloatArray | None,
G: FloatArray | None,
H: FloatArray | None,
M: Mat,
V: Mat,
W: Mat | None,
X: FloatArray,
yi: FloatArray,
vi: FloatArray,
slab: tuple[str, ...],
QE: float,
QEdf: int,
QEp: float,
QM: float,
QMdf: tuple[int, float | None],
QMp: float,
k: int,
k_f: int,
k_all: int,
p: int,
m: int,
btt: tuple[int, ...],
parms: int,
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
method: str,
test: str,
dfs: str | float | tuple[float, ...],
ddf: FloatArray,
s2w: float,
level: float,
int_only: bool,
int_incl: bool,
intercept: bool,
allvipos: bool,
coef_na: tuple[bool, ...],
ids: tuple[int, ...],
not_na: NDArray[bool_],
struct: tuple[str, str],
with_s: bool,
with_g: bool,
with_h: bool,
with_r: bool,
sigma2s: int,
tau2s: int,
rhos: int,
gamma2s: int,
phis: int,
vc_fix: dict[str, NDArray[bool_] | None],
s_names: tuple[str, ...],
g_names: tuple[str, ...],
h_names: tuple[str, ...],
s_nlevels: tuple[int, ...],
s_levels: tuple[tuple[str, ...], ...],
Rfix: tuple[bool, ...],
Rscale: str,
group_g: Group | None,
group_h: Group | None,
s_factors: tuple[Any, ...],
Z_S: tuple[Mat, ...],
D_S: tuple[Mat, ...],
problem: Problem,
hessian: FloatArray | None,
vvc: FloatArray | None,
vc_names: tuple[str, ...],
spec: dict[str, Any],
iterations: int = 0,
measure: str = 'GEN',
robust: RobustInfo | None = None,
p_eff: int = 0,
optbeta: bool = False,
lambda1: float = 0.0,
lambda2: float = 0.0,
beta_est: tuple[bool, ...] = (),
vccon: dict[str, NDArray[Any]] | None = None,
cvvc: str | None = None,
s_levels_f: tuple[tuple[str, ...], ...] = (),
slab_f: tuple[str, ...] = (),
X_f: FloatArray | None = None,
digits: int = 4,
yi_f: FloatArray = (lambda: empty(0))(),
vi_f: FloatArray = (lambda: empty(0))(),
V_f: Mat | None = None,
W_f: Mat | None = None,
ni: FloatArray | None = None,
ni_f: FloatArray | None = None,
subset: NDArray[bool_] | None = None,
slab_null: bool = True,
control: Any = None,
*,
call: Call | None = None,
)
Bases: RobustFields, FitMethods
A fitted multivariate/multilevel meta-analytic model (metafor's rma.mv).
Names follow metafor with . replaced by _; btt holds 0-based coefficient indices.
spec keeps the arguments of the call, which :func:metafopy.confint and :func:metafopy.profile use to refit the model.
hessian and vvc are the Hessian of -ll and its inverse (optbeta=True, where the leading rows are the
coefficients, or cvvc), with the row names vc_names; p_eff is the number of estimated (not fixed) coefficients,
beta_est flags them, and vccon holds the group ids of constrained variance components. slab_f and
s_levels_f are the study labels and the levels of the ~ 1 | id terms before rows with missing values were
dropped (metafor's slab and s.levels.f), used to pad results under na_action='exclude'.
X_f is the model matrix before rows with missing values were dropped (metafor's X.f; NaN where a moderator value is missing),
used by fitted() and predict() under na_action='pass'.
g_nlevels
property
¶
Number of levels of the inner and outer factor of the tau2/rho term in the fit (metafor's g.nlevels), None without one.
g_nlevels_f
property
¶
As :attr:g_nlevels before the rows with missing values were dropped (metafor's g.nlevels.f).
g_levels_f
property
¶
The levels of the inner and outer factor of the tau2/rho term before the rows with missing values were dropped (g.levels.f).
g_levels_k
property
¶
Number of observations at each level of the inner factor of the tau2/rho term, named by the levels (metafor's g.levels.k).
g_levels_comb_k
property
¶
g_levels_comb_k: FloatArray | None
Number of observations at each combination of inner levels of the tau2/rho term (metafor's g.levels.comb.k).
h_nlevels
property
¶
As :attr:g_nlevels for the gamma2/phi term (metafor's h.nlevels).
h_nlevels_f
property
¶
As :attr:g_nlevels_f for the gamma2/phi term (metafor's h.nlevels.f).
h_levels_f
property
¶
As :attr:g_levels_f for the gamma2/phi term (metafor's h.levels.f).
h_levels_k
property
¶
As :attr:g_levels_k for the gamma2/phi term (metafor's h.levels.k).
h_levels_comb_k
property
¶
h_levels_comb_k: FloatArray | None
As :attr:g_levels_comb_k for the gamma2/phi term (metafor's h.levels.comb.k).
G_dimnames
property
¶
The row and column names of G (the levels of the inner factor, or the inner variables for GEN/GDIAG), as metafor sets them.
H_dimnames
property
¶
The row and column names of H, as :attr:G_dimnames.
G_frame
property
¶
G_frame: DataFrame | None
G as a data frame with its row and column names, None without a tau2/rho term.
H_frame
property
¶
H_frame: DataFrame | None
H as a data frame with its row and column names, None without a gamma2/phi term.
weighted
property
¶
weighted: bool
Whether the model is fitted by weighting (always True for rma_mv), metafor's weighted.
data
property
¶
data: DataFrame | None
The data frame the model was fitted to (None if the model was fitted to vectors), metafor's data.
dist
property
¶
The distance measures of the 'SP' structures (the dist argument, two entries), metafor's dist.
random
property
¶
The random formulas as given (None without any), metafor's random.
R
property
¶
R: Any
The known correlation matrices given as R (None without any), metafor's R: a mapping with an entry for every ~ 1 | factor term,
None for the terms without a matrix.
formulas
property
¶
The two ~ inner | outer formulas of the model (None for a missing one), metafor's formulas.
s_nlevels_f
property
¶
The number of levels of each ~ 1 | id factor before the removal of studies with missing values, metafor's s.nlevels.f.
Z_G1
property
¶
Z_G1: Mat | None
The design matrix of the outer factor of the first ~ inner | outer term, metafor's Z.G1.
Z_G2
property
¶
Z_G2: Mat | None
The design matrix of the inner factor of the first ~ inner | outer term, metafor's Z.G2.
Z_H1
property
¶
Z_H1: Mat | None
The design matrix of the outer factor of the second ~ inner | outer term, metafor's Z.H1.
Z_H2
property
¶
Z_H2: Mat | None
The design matrix of the inner factor of the second ~ inner | outer term, metafor's Z.H2.
k_eff
property
¶
k_eff: int
Number of effective observations (the rows used in the fit), metafor's k.eff.
coef ¶
Estimated coefficients, indexed by name; type is accepted for metafor's coef(x, type=) and only location-scale fits use it.
named_inner ¶
Z1 of a ~ inner | outer term with the column names R gives it: the levels of a factor or the columns of the inner variables.
named_outer ¶
Z2 of a ~ inner | outer term with the column names R gives it (mf.g[[nvars]] and the levels).
used_row_names ¶
The row names R gives the matrices of the ~ inner | outer terms: the rows after subset numbered from 1, less those with missing values.
R builds them from a data frame of the subset (.process.G.aftersub) and drops the rows with missing values afterwards, so a subset
renumbers the rows and the removal of missing values does not.
vcov ¶
vcov(
type: Literal[
'fixed',
'beta',
'alpha',
'delta',
'obs',
'marginal',
'fitted',
'resid',
] = 'fixed',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> DataFrame
Variance-covariance matrix of the coefficients, or with type of the observed effects; see :func:metafopy.vcov.
fitted ¶
Fitted values X beta.
na_action is 'omit' (the rows used in fitting), 'exclude', 'pass' or 'fail', as in :func:metafopy.residuals.
residuals ¶
residuals(
type: Literal[
'response',
'rstandard',
'rstudent',
'pearson',
'cholesky',
] = 'response',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Residuals; see :func:metafopy.residuals (type is 'response', 'rstandard', 'rstudent', 'pearson' or 'cholesky').
hat_matrix ¶
X (X'WX)^-1 X'W (metafor hatvalues.rma.mv(type="matrix")).
hatvalues ¶
hatvalues(
type: Literal['diagonal', 'matrix'] = 'diagonal',
na_action: str = 'omit',
) -> NDArray[float64]
Diagonal of the hat matrix (type='diagonal') or the hat matrix itself ('matrix'), as metafor's hatvalues.rma.mv.
With na_action='exclude' or 'pass' rows (and columns) left out because of missing values are NaN.
See https://github.com/wviechtb/metafor/blob/master/R/hatvalues.rma.mv.r.
Raises:
| Type | Description |
|---|---|
InputError
|
an unknown |
weights_ ¶
weights_(
type: Literal[
'diagonal', 'matrix', 'rowsum'
] = 'diagonal',
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Percentage weights ('diagonal'), the weight matrix W ('matrix') or the percentage row sums of W ('rowsum', intercept-only).
Raises:
| Type | Description |
|---|---|
InputError
|
|
summary ¶
summary(
digits: int | Mapping[str, int] | None = None,
showfit: bool = True,
*,
signif_stars: bool | None = None,
signif_legend: bool | None = None,
num: bool = False,
) -> str
The printout with the fit statistics table, as metafor's summary(); str(res) leaves it out like print().
digits defaults to the digits option, else to the digits the model was fitted with; signif_stars, signif_legend and
num as for :meth:metafopy.models.rma_uni.RMAResult.summary.
SelmodelResult
dataclass
¶
SelmodelResult(
base: RMAResult,
beta: FloatArray,
se: FloatArray,
zval: FloatArray,
pval: FloatArray,
ci_lb: FloatArray,
ci_ub: FloatArray,
vb: FloatArray,
betaspec: bool,
tau2: float,
se_tau2: float,
ci_lb_tau2: float,
ci_ub_tau2: float,
tau2_fix: bool,
QM: float,
QMp: float,
delta: FloatArray,
vd: FloatArray,
se_delta: FloatArray,
zval_delta: FloatArray,
pval_delta: FloatArray,
ci_lb_delta: FloatArray,
ci_ub_delta: FloatArray,
deltas: int,
delta_fix: tuple[bool, ...],
hessian: FloatArray | None,
hest: tuple[bool, ...],
ll: float,
ll0: float,
LRT: float,
LRTdf: int,
LRTp: float,
LRT_tau2: float,
LRTp_tau2: float,
parms: int,
fit_stats_ml: FitStats,
fit_stats_reml: FitStats,
pvals: FloatArray,
spec: SelSpec,
type: str,
steps: FloatArray,
decreasing: bool,
stepsspec: bool,
pgrp: NDArray[intp] | None,
ptable: DataFrame | None,
subset: BoolArray,
k0: int,
k1: int,
alternative: str,
pval_min: float,
prec: str | None,
precspec: bool,
precis: dict[str, float],
scaleprec: bool | None,
delta_lb: FloatArray,
delta_ub: FloatArray,
delta_lb_excl: tuple[bool, ...],
delta_ub_excl: tuple[bool, ...],
delta_min: FloatArray,
delta_max: FloatArray,
tau2_max: float,
control: dict[str, Any],
defmap: bool | None,
mapfun: tuple[str | None, ...] | None,
mapinvfun: tuple[str | None, ...] | None,
digits: int = 4,
*,
call: Call | None = None,
trimfill_info: dict[str, Any] = dict(),
)
Bases: FitMethods
A selection model fitted by :func:metafopy.selmodel (metafor's rma.uni.selmodel object).
base is the ML (or equal/fixed-effects) :class:~metafopy.RMAResult the selection model was fitted from; the
data (yi, vi, X, ...) come from it. All other names follow metafor with . replaced by _
(se_delta, ci_lb_delta, LRT_tau2). beta, se, vb and tau2 are the estimates under the
selection model; delta holds the selection parameters, vd their covariance matrix.
k_all
property
¶
k_all: int
Number of studies supplied to the model the fit holds (a model that metafor refits has only the studies used, so this is their number).
ni
property
¶
ni: FloatArray | None
Sample sizes of the studies used in the fit (None when unknown).
M
property
¶
M: FloatArray
The marginal variance-covariance matrix of the observed effects, diag(vi + tau2) with the tau2 of the selection model.
QMdf
property
¶
Degrees of freedom of the test of the moderators: (m, None), as the test is a chi-square test (metafor's QMdf).
tau2_f
property
¶
tau2_f: float
The amount of heterogeneity, metafor's tau2.f (the same number as tau2 here).
data
property
¶
data: MetaData
The data of the underlying model (metafor keeps the data frame the model was fitted to).
wi_fun
property
¶
wi_fun: Weight | None
The selection function of the model (metafor's wi.fun), vectorised over the studies.
__getattr__ ¶
The trim-and-fill details (fill, se_k0, ...) of a trimfill fit the selection model was fitted to, which metafor keeps in the result.
coef ¶
The coefficients and selection parameters as {'beta': ..., 'delta': ...} (as R's coef()), or one of them with type.
type='beta' or 'delta' gives that part as a series and 'all' both concatenated into one series.
vcov ¶
vcov(
type: Literal[
'fixed',
'beta',
'alpha',
'delta',
'obs',
'marginal',
'fitted',
'resid',
] = 'fixed',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> DataFrame | dict[str, DataFrame]
Variance-covariance matrices; 'fixed' (the default) gives {'beta': ..., 'delta': ...}, the other types follow :func:metafopy.vcov.
fitted ¶
Fitted values X beta (na_action is accepted for symmetry: the selection model was fitted to the studies without missing values).
weights_ ¶
Not available (metafor's weights() stops for this class).
Raises:
| Type | Description |
|---|---|
NotSupportedError
|
always. |
residuals ¶
residuals(
type: Literal[
'response',
'rstandard',
'rstudent',
'pearson',
'cholesky',
] = 'response',
*,
na_action: Literal[
'omit', 'exclude', 'pass', 'fail'
] = 'omit',
) -> NDArray[float64]
Residuals; see :func:metafopy.residuals (type is 'response', 'rstandard', 'rstudent', 'pearson' or 'cholesky').
plot ¶
Draw the selection function with :func:metafopy.plot.plot_selmodel.
summary ¶
summary(
digits: int | None = None,
showfit: bool = True,
*,
signif_stars: bool | None = None,
signif_legend: bool | None = None,
num: bool = False,
) -> str
The printout with the fit statistics table, as metafor's summary(); str(res) leaves it out like print().
signif_stars (default: the signif_stars option, True) adds the significance stars, signif_legend (default: signif_stars)
their legend, num numbers the rows of the table of coefficients.
Control settings¶
Control
dataclass
¶
Control(
tau2_init: float | None = None,
tau2_min: float = 0.0,
tau2_max: float = 100.0,
threshold: float = 1e-05,
tol: float = eps**0.25,
ll0check: bool = True,
maxiter: int = 100,
stepadj: float = 1.0,
evtol: float = 1e-07,
REMLf: bool = True,
ignored: dict[str, Any] = dict(),
)
Control settings for rma_uni (names follow metafor with . -> _).
LSControl
dataclass
¶
LSControl(
alpha_init: ArrayLike | None = None,
alpha_max: ArrayLike = inf,
alpha_min: ArrayLike = -inf,
beta_init: ArrayLike | None = None,
evtol: float = 1e-07,
hes_alpha_fix: bool = False,
hes_beta_fix: bool = False,
hessian_d: float = 0.1,
hessian_eps: float = 0.0001,
hessian_r: int = 4,
maxiter: int = 5000,
optimizer: str = 'nlminb',
optmethod: str = 'BFGS',
opt_ctrl: Mapping[str, Any] = dict(),
ncpus: int = 1,
cl: Any = None,
parallel: Mapping[str, Any] = dict(),
polish_converged: bool = True,
REMLf: bool = True,
scaleZ: bool = True,
tau2_max: float = inf,
tau2_min: float = 0.0,
ignored: dict[str, Any] = dict(),
)
Control settings for location-scale models (names follow metafor with . -> _).
polish_converged=False skips the Nelder-Mead polish after a converged BFGS run (used by the permutation test).
optimizer is 'nlminb' (the default, mapped to SciPy's BFGS or, for the identity link, constrOptim), any other
optimiser of metafor's rma.uni ('optim' with optmethod, 'BFGS', 'CG', 'L-BFGS-B', 'Nelder-Mead',
'nlm', 'uobyqa', 'newuoa', 'bobyqa', 'nloptr', 'hjk', 'nmk', 'mads', 'ucminf', 'lbfgsb3c',
'subplex', 'BBoptim', 'optimParallel', 'Rcgmin', 'Rvmmin', and for the identity link 'constrOptim',
'solnp', 'constrOptim.nl'/'alabama' and 'auglag'), mapped as :mod:metafopy.models.sel_opt maps them. opt_ctrl
holds the optimiser settings given in control (maxit, reltol, abstol, ndeps, tol). ncpus larger than 1
selects 'optimParallel' as in metafor, but the likelihood is evaluated serially (parallel and cl are accepted and
ignored). hessian_d, hessian_eps and
hessian_r are the arguments of numDeriv::hessian's Richardson method
(metafor sets r = 8, whose eight Richardson steps amplify round-off in the log-likelihood to a relative 1e-4 or more in the standard errors; metafopy
defaults to r = 4, which agrees with metafor's values to about 1e-5, see docs/differences.md).
ignored
class-attribute
instance-attribute
¶
The entries other functions of metafor read (vc.min, stepadj, ...) and those given under another name (tol is in opt_ctrl),
kept as R keeps them in res$control; read them as attributes.
GLMMControl
dataclass
¶
GLMMControl(
package: str = 'lme4',
scale_x: bool = True,
evtol: float = 1e-07,
tau2tol: float = 0.0001,
int_rel_tol: float = epsilon**0.25,
int_subdivisions: int = 100,
hessian_r: int = 16,
hesspack: str = 'numDeriv',
hessian_ctrl: Mapping[str, Any] = dict(),
dnchgcalc: str | None = None,
dnchgprec: float | None = None,
gtol: float = 1e-07,
optimizer: str = 'nlminb',
optmethod: str = 'BFGS',
opt_ctrl: Mapping[str, Any] = dict(),
clogit_ctrl: Mapping[str, Any] = dict(),
clogistic_ctrl: Mapping[str, Any] = dict(),
ignored: dict[str, Any] = dict(),
)
Control settings of rma_glmm (names follow metafor's control list with . replaced by _).
int_rel_tol and int_subdivisions are the rel.tol and subdivisions of the intCtrl
list used for the integral in the exact conditional model; hessian_r is numDeriv's r. hesspack ('numDeriv',
'pracma' or 'calculus') and hessian_ctrl (metafor's hessianCtrl: d, eps, r, v for numDeriv, h for
pracma, accuracy and stepsize for calculus) choose the numerical Hessian of the exact conditional model; dnchgcalc
('dFNCHypergeo' or 'dnoncenhypergeom') and dnchgprec (the precision of BiasedUrn::dFNCHypergeo, 1e-10 in
metafor) its density. Without either entry the Hessian uses the untruncated density; with dnchgcalc='dFNCHypergeo' or a
dnchgprec it uses :func:metafopy.core.nchg.fisher_log_probability, the port of BiasedUrn's truncating algorithm.
package is the package that fits the mixed models: 'lme4', 'GLMMadaptive' or 'glmmTMB'.
optimizer is 'nlminb' (the default: a quasi-Newton maximisation of the exact likelihood of model='CM.EL'),
'clogit' or 'clogistic' (survival::clogit() / Epi::clogistic(), only for the fixed-effects methods) or one of the
other optimisers of rma.glmm ('optim' with optmethod, 'Nelder-Mead', 'BFGS', 'bobyqa', 'nlm', ...) that
:mod:metafopy.models.sel_opt provides: optim with BFGS and Nelder-Mead are ports of R's routines, the others stand in
for them with the closest SciPy method. opt_ctrl is metafor's optCtrl list (maxit, reltol, abstol, ndeps);
clogit_ctrl and clogistic_ctrl are metafor's clogitCtrl and clogisticCtrl lists (see :func:clogit_settings
and :func:clogistic_settings for the entries).
MVControl
dataclass
¶
MVControl(
sigma2_init: ArrayLike | None = None,
tau2_init: ArrayLike | None = None,
rho_init: ArrayLike | None = None,
gamma2_init: ArrayLike | None = None,
phi_init: ArrayLike | None = None,
REMLf: bool = True,
evtol: float = 1e-07,
cholesky: bool | tuple[bool, bool] | None = None,
check_k_gtr_1: bool = True,
hesstol: float = sqrt(EPS),
gtol: float = 1e-07,
maxiter: int = 5000,
hessian_d: float = 0.1,
hessian_eps: float = 0.0001,
hessian_r: int = 8,
optimizer: str = 'nlminb',
optmethod: str = 'BFGS',
opt_ctrl: Mapping[str, Any] = dict(),
ncpus: int = 1,
cl: Any = None,
parallel: Mapping[str, Any] = dict(),
nearpd: bool = False,
hesspack: str = 'numDeriv',
hessian_ctrl: Mapping[str, Any] = dict(),
mfmaxit: float = inf,
ignored: dict[str, Any] = dict(),
)
Control arguments of :func:rma_mv (metafor's control list).
*_init give starting values (on the original scale), cholesky switches the Cholesky parametrisation of the
UN and GEN structures on or off per term, gtol and maxiter control the default BFGS optimiser, and hessian_d,
hessian_eps and hessian_r are the arguments of numDeriv::hessian's Richardson method (metafor's
hessianCtrl with its default hesspack='numDeriv') used for optbeta and cvvc.
optimizer (default 'nlminb', here BFGS with the analytic score) may be any other optimiser of metafor's rma.mv
('optim' with optmethod, 'BFGS', 'Nelder-Mead', 'nlm', 'bobyqa', 'hjk', ...); they are run as
:mod:metafopy.models.sel_opt describes (optim with BFGS or Nelder-Mead is R's routine, the others are SciPy stand-ins), on
the log-likelihood alone. opt_ctrl holds optimiser settings given in control (maxit, reltol, abstol, ndeps,
tol); ncpus above 1 selects 'optimParallel' but the likelihood is evaluated serially (parallel and cl are
accepted and ignored). nearpd forces G, H (UN and GEN structures) and M to be positive definite with
nearPD (:func:metafopy.core.linalg.near_pd); the score is then taken by finite differences. hesspack
('numDeriv', 'pracma' or 'calculus') and hessian_ctrl (metafor's hessianCtrl: d, eps, r, v and
zero.tol of numDeriv, h of pracma, accuracy and stepsize of calculus) choose the Hessian. mfmaxit is the
number of likelihood evaluations after which the optimisation stops with an error.