@numero-uno-jpn/rstats 1.18.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.ja.md +7 -7
- package/README.md +7 -7
- package/dist/causal.js +2 -2
- package/dist/chunks/chunk-33ODAPMR.js +2 -0
- package/dist/chunks/chunk-3ST6RZXG.js +2 -0
- package/dist/chunks/{chunk-JF4PXFJE.js → chunk-4EQN74JN.js} +2 -2
- package/dist/chunks/chunk-5RRFO4NU.js +2 -0
- package/dist/chunks/{chunk-3JFRDXN7.js → chunk-64DDDGJU.js} +2 -2
- package/dist/chunks/chunk-66TEOHPF.js +2 -0
- package/dist/chunks/chunk-6ISDROPG.js +2 -0
- package/dist/chunks/{chunk-EC77KAAM.js → chunk-6LAKI2QG.js} +2 -2
- package/dist/chunks/{chunk-5CTWYFMB.js → chunk-6QCH4LAL.js} +2 -2
- package/dist/chunks/{chunk-H6Z7JVSD.js → chunk-6RA73LXX.js} +2 -2
- package/dist/chunks/{chunk-KJMLQHCY.js → chunk-7C2ECGT6.js} +1 -1
- package/dist/chunks/{chunk-SCFFHEDZ.js → chunk-7KPFNJBE.js} +2 -2
- package/dist/chunks/chunk-ARPXG2PG.js +2 -0
- package/dist/chunks/chunk-AWXW4WSX.js +2 -0
- package/dist/chunks/{chunk-XQCHC3SH.js → chunk-B5GSH3AK.js} +1 -1
- package/dist/chunks/{chunk-2JB7F646.js → chunk-BLDLJHUG.js} +2 -2
- package/dist/chunks/{chunk-IKMW63BE.js → chunk-BU4I544S.js} +2 -2
- package/dist/chunks/{chunk-LCIX76FR.js → chunk-CAUNJ7S6.js} +2 -2
- package/dist/chunks/chunk-DFGW4QWU.js +2 -0
- package/dist/chunks/{chunk-WYVUCQO3.js → chunk-DPCCSFCG.js} +1 -1
- package/dist/chunks/chunk-EXS5QD7V.js +2 -0
- package/dist/chunks/chunk-FOCHNNP3.js +2 -0
- package/dist/chunks/{chunk-MXZ64QME.js → chunk-HEPGGURG.js} +2 -2
- package/dist/chunks/chunk-INNFAVT3.js +2 -0
- package/dist/chunks/chunk-JEELIABM.js +2 -0
- package/dist/chunks/chunk-KNF2GPJV.js +2 -0
- package/dist/chunks/chunk-L4ZS7MAX.js +2 -0
- package/dist/chunks/{chunk-RXYZQ3UX.js → chunk-LZAB4M7P.js} +2 -2
- package/dist/chunks/chunk-LZTDYQRS.js +3 -0
- package/dist/chunks/{chunk-N7BUE54L.js → chunk-MTSU2QHB.js} +2 -2
- package/dist/chunks/{chunk-GIK34P23.js → chunk-MXRN2G7O.js} +2 -2
- package/dist/chunks/chunk-OFDD4GTZ.js +2 -0
- package/dist/chunks/chunk-OOHFFLMY.js +2 -0
- package/dist/chunks/chunk-OOO5AAM7.js +2 -0
- package/dist/chunks/chunk-PJJJR3H6.js +2 -0
- package/dist/chunks/chunk-PVRNAOO7.js +2 -0
- package/dist/chunks/chunk-Q2JLU5YD.js +2 -0
- package/dist/chunks/{chunk-Z33Q545U.js → chunk-QCQBK5AC.js} +2 -2
- package/dist/chunks/chunk-RXK4KSKH.js +2 -0
- package/dist/chunks/chunk-UC3YYJHM.js +4 -0
- package/dist/chunks/chunk-UPACHZ4F.js +2 -0
- package/dist/chunks/{chunk-VATAUY7N.js → chunk-VCXPGCA4.js} +2 -2
- package/dist/chunks/chunk-VFL4GGYT.js +2 -0
- package/dist/chunks/chunk-VL72MQOQ.js +2 -0
- package/dist/chunks/chunk-VSV5QGXX.js +2 -0
- package/dist/chunks/{chunk-CTZUYKVL.js → chunk-WMEF5XWO.js} +2 -2
- package/dist/chunks/chunk-X6JS6ZZB.js +2 -0
- package/dist/chunks/chunk-YEDVOX5V.js +2 -0
- package/dist/chunks/chunk-ZCTB4N5J.js +3 -0
- package/dist/descriptive.js +2 -2
- package/dist/distributions/normal.d.ts +4 -0
- package/dist/distributions/normal.js +4 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/tests.d.ts +6 -0
- package/dist/entries/tests.js +6 -0
- package/dist/entries/timeseries.d.ts +11 -0
- package/dist/entries/timeseries.js +11 -0
- package/dist/htest/timeROC.d.ts +564 -0
- package/dist/htest/timeROC.js +1106 -0
- package/dist/linalg.js +2 -2
- package/dist/meta/metabin.d.ts +32 -0
- package/dist/meta/metabin.js +137 -0
- package/dist/meta/metaextra.d.ts +153 -0
- package/dist/meta/metaextra.js +290 -0
- package/dist/meta/metagen.d.ts +124 -0
- package/dist/meta/metagen.js +263 -0
- package/dist/meta/metaother.d.ts +87 -0
- package/dist/meta/metaother.js +342 -0
- package/dist/meta/netmeta.d.ts +256 -0
- package/dist/meta/netmeta.js +547 -0
- package/dist/mixed.js +3 -4
- package/dist/models/glmFamily.js +4 -1
- package/dist/models/metaAnalysis.d.ts +4 -0
- package/dist/models/metaAnalysis.js +100 -18
- package/dist/multivariate.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/regression.js +2 -2
- package/dist/rstats.js +20 -18
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -15
- package/dist/timeseries/acf.js +5 -2
- package/dist/timeseries/arima.d.ts +154 -0
- package/dist/timeseries/arima.js +1007 -0
- package/dist/timeseries/autoArima.d.ts +70 -0
- package/dist/timeseries/autoArima.js +191 -0
- package/dist/timeseries/ets.d.ts +158 -0
- package/dist/timeseries/ets.js +883 -0
- package/dist/timeseries/forecastArima.d.ts +136 -0
- package/dist/timeseries/forecastArima.js +432 -0
- package/dist/timeseries/forecastDispatch.d.ts +83 -0
- package/dist/timeseries/forecastDispatch.js +130 -0
- package/dist/timeseries/forecastSimple.d.ts +177 -0
- package/dist/timeseries/forecastSimple.js +371 -0
- package/dist/timeseries/forecastUtils.d.ts +260 -0
- package/dist/timeseries/forecastUtils.js +619 -0
- package/dist/timeseries/holtWinters.d.ts +65 -0
- package/dist/timeseries/holtWinters.js +193 -0
- package/dist/timeseries/input.d.ts +8 -0
- package/dist/timeseries/input.js +27 -0
- package/dist/timeseries/ocsbCritical.d.ts +2 -0
- package/dist/timeseries/ocsbCritical.js +6 -0
- package/dist/timeseries/scale.d.ts +16 -0
- package/dist/timeseries/scale.js +48 -0
- package/dist/timeseries/statsTs.d.ts +128 -0
- package/dist/timeseries/statsTs.js +456 -0
- package/dist/timeseries/stl.d.ts +131 -0
- package/dist/timeseries/stl.js +489 -0
- package/dist/timeseries/tseries.d.ts +110 -0
- package/dist/timeseries/tseries.js +369 -0
- package/dist/timeseries.js +2 -2
- package/package.json +1 -1
- package/dist/chunks/chunk-53WQDB3C.js +0 -2
- package/dist/chunks/chunk-6I23C2YJ.js +0 -2
- package/dist/chunks/chunk-FLFNMSHI.js +0 -3
- package/dist/chunks/chunk-GEHMND3C.js +0 -2
- package/dist/chunks/chunk-HG4LJBNV.js +0 -2
- package/dist/chunks/chunk-HGAEVPVS.js +0 -2
- package/dist/chunks/chunk-HMLYEFQN.js +0 -2
- package/dist/chunks/chunk-HRRCC2BD.js +0 -2
- package/dist/chunks/chunk-IBHMM2SL.js +0 -2
- package/dist/chunks/chunk-ICDW3I2F.js +0 -2
- package/dist/chunks/chunk-IOJVFYHW.js +0 -2
- package/dist/chunks/chunk-IW4S634O.js +0 -2
- package/dist/chunks/chunk-JPWYGTUN.js +0 -2
- package/dist/chunks/chunk-KVJBCT3D.js +0 -2
- package/dist/chunks/chunk-LY5XGFPU.js +0 -2
- package/dist/chunks/chunk-MKZH65DK.js +0 -2
- package/dist/chunks/chunk-MVPHISOV.js +0 -2
- package/dist/chunks/chunk-NDZVVNBB.js +0 -2
- package/dist/chunks/chunk-NOTJ45G3.js +0 -4
- package/dist/chunks/chunk-QUD3374N.js +0 -2
- package/dist/chunks/chunk-V6FMGGUV.js +0 -2
- package/dist/chunks/chunk-W5M3R4NH.js +0 -2
- package/dist/chunks/chunk-XUMVTGMM.js +0 -2
- package/dist/chunks/chunk-YXMHWS5R.js +0 -2
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// meta's metagen and the machinery shared by the meta functions: the common and random effects, Hartung-Knapp, the
|
|
2
|
+
// prediction interval, heterogeneity (Q, tau2 and its interval, H, I2 and their intervals). Written for rStats.js from
|
|
3
|
+
// the behaviour specification oracle/tsmeta-behaviour.md (Part 2) with the details found in
|
|
4
|
+
// experiments/tsmeta120-log.md (items 61-63). The generalised Q interval follows Jackson (2013), with the distribution of
|
|
5
|
+
// a weighted sum of chi-squares by Imhof's (1961) integral. No R or package source was read.
|
|
6
|
+
import { powerOfTwoScale } from "../timeseries/scale.js";
|
|
7
|
+
import { pchisq } from "../distributions/chisq.js";
|
|
8
|
+
import { pnorm, qnorm } from "../distributions/normal.js";
|
|
9
|
+
import { pt1, qt1 } from "../distributions/t.js";
|
|
10
|
+
import { confintRma, rma } from "../models/metaAnalysis.js";
|
|
11
|
+
import { integrate } from "../numerics/integrate.js";
|
|
12
|
+
import { symmetricEigen } from "../random/mvrnorm.js";
|
|
13
|
+
import { lgamma } from "../special/gamma.js";
|
|
14
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
15
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
16
|
+
const METAGEN_KEYS = ["methodTau", "methodRandomCi", "methodTauCi", "level", "levelMa", "levelPredict"];
|
|
17
|
+
const sum = (v) => v.reduce((a, b) => a + b, 0);
|
|
18
|
+
/**
|
|
19
|
+
* P(sum_j lambda_j chi2_1 <= q) for lambda_j >= 0: Ruben's (1962) series sum_k c_k P(chi2_{r + 2k} <= q / beta) with
|
|
20
|
+
* beta = 2 lmin lmax / (lmin + lmax), or Imhof's (1961) integral when the series would be long.
|
|
21
|
+
* Not an R function.
|
|
22
|
+
*
|
|
23
|
+
* @category Meta-analysis
|
|
24
|
+
*/
|
|
25
|
+
export function pWeightedChisq(q0, lambda0) {
|
|
26
|
+
// lambda and q divided by one power of two (exact; the probability does not depend on it), so that lmin lmax and the
|
|
27
|
+
// integrand stay in range for weights near 1e+-300 (log 110)
|
|
28
|
+
const c = powerOfTwoScale(lambda0);
|
|
29
|
+
const lambda = lambda0.map((l) => l / c);
|
|
30
|
+
const q = q0 / c;
|
|
31
|
+
const mx = Math.max(0, ...lambda);
|
|
32
|
+
const lam = lambda.filter((l) => l > 1e-14 * mx);
|
|
33
|
+
if (lam.length === 0)
|
|
34
|
+
return q >= 0 ? 1 : 0;
|
|
35
|
+
if (q <= 0)
|
|
36
|
+
return 0;
|
|
37
|
+
const r = lam.length;
|
|
38
|
+
const lmin = Math.min(...lam), lmax = Math.max(...lam);
|
|
39
|
+
const beta = (2 * lmin * lmax) / (lmin + lmax);
|
|
40
|
+
const rho = (lmax - lmin) / (lmax + lmin);
|
|
41
|
+
const K = rho < 1e-12 ? 1 : Math.ceil(Math.log(1e-17) / Math.log(rho)) + 10;
|
|
42
|
+
if (K <= 20000) {
|
|
43
|
+
const x = q / beta;
|
|
44
|
+
const gam = lam.map((l) => 1 - beta / l);
|
|
45
|
+
const c = [Math.exp(0.5 * sum(lam.map((l) => Math.log(beta / l))))];
|
|
46
|
+
const g = [0];
|
|
47
|
+
for (let m = 1; m <= K; m++)
|
|
48
|
+
g.push(0.5 * sum(gam.map((gj) => gj ** m)));
|
|
49
|
+
let F = pchisq(x, r); // P(chi2_nu <= x), nu = r + 2k
|
|
50
|
+
let lt = (r / 2) * Math.log(x / 2) - x / 2 - lgamma(r / 2 + 1); // log x^{nu/2} e^{-x/2} / (2^{nu/2} Gamma(nu/2 + 1))
|
|
51
|
+
let total = c[0] * F;
|
|
52
|
+
let csum = c[0];
|
|
53
|
+
for (let k = 1; k <= K; k++) {
|
|
54
|
+
let ck = 0;
|
|
55
|
+
for (let i = 0; i < k; i++)
|
|
56
|
+
ck += g[k - i] * c[i];
|
|
57
|
+
ck /= k;
|
|
58
|
+
c.push(ck);
|
|
59
|
+
const nu = r + 2 * (k - 1);
|
|
60
|
+
F -= Math.exp(lt);
|
|
61
|
+
lt += Math.log(x / 2) - Math.log(nu / 2 + 1);
|
|
62
|
+
total += ck * F;
|
|
63
|
+
csum += ck;
|
|
64
|
+
if (Math.abs(1 - csum) < 1e-16 && Math.abs(ck) < 1e-18)
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return Math.min(1, Math.max(0, total));
|
|
68
|
+
}
|
|
69
|
+
const f = (u) => {
|
|
70
|
+
if (u === 0)
|
|
71
|
+
return 0.5 * (sum(lam) - q);
|
|
72
|
+
let th = 0, lr = 0;
|
|
73
|
+
for (const l of lam) {
|
|
74
|
+
th += Math.atan(l * u);
|
|
75
|
+
lr += Math.log1p(l * l * u * u);
|
|
76
|
+
}
|
|
77
|
+
return Math.sin(0.5 * th - 0.5 * q * u) / (u * Math.exp(0.25 * lr));
|
|
78
|
+
};
|
|
79
|
+
const res = integrate(f, 0, Infinity, { relTol: 1e-10, subdivisions: 5000, stopOnError: false });
|
|
80
|
+
return Math.min(1, Math.max(0, 0.5 - res.value / Math.PI));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The generalised Q interval for tau2 (Jackson 2013) with study weights a: Q_a = sum a (y - mu_a)^2 follows
|
|
84
|
+
* sum lambda chi2_1 with lambda the eigenvalues of S^(1/2) (A - a a' / sum a) S^(1/2), S = diag(v + tau2); the bounds
|
|
85
|
+
* solve P(Q_a <= q_obs) = 1 - alpha/2 and alpha/2 (0 when not reached).
|
|
86
|
+
* Not an R function.
|
|
87
|
+
*
|
|
88
|
+
* @category Meta-analysis
|
|
89
|
+
*/
|
|
90
|
+
export function genqInterval(y, v, a, level) {
|
|
91
|
+
const k = y.length;
|
|
92
|
+
const sa = sum(a);
|
|
93
|
+
const mu = sum(a.map((w, i) => w * y[i])) / sa;
|
|
94
|
+
const qObs = sum(a.map((w, i) => w * (y[i] - mu) ** 2));
|
|
95
|
+
const cdf = (t2) => {
|
|
96
|
+
const s = v.map((vi) => Math.sqrt(vi + t2));
|
|
97
|
+
const M = Array.from({ length: k }, (_, i) => Array.from({ length: k }, (_, j) => s[i] * ((i === j ? a[i] : 0) - (a[i] * a[j]) / sa) * s[j]));
|
|
98
|
+
return pWeightedChisq(qObs, symmetricEigen(M).values.map((l) => Math.max(0, l)));
|
|
99
|
+
};
|
|
100
|
+
const alpha = 1 - level;
|
|
101
|
+
const solve = (target) => {
|
|
102
|
+
if (cdf(0) <= target)
|
|
103
|
+
return 0;
|
|
104
|
+
// the bracket and the stopping rule at the data's scale (relative), for study variances of any size
|
|
105
|
+
let hi = Math.max(...v);
|
|
106
|
+
for (let i = 0; i < 2100 && cdf(hi) > target && Number.isFinite(hi); i++)
|
|
107
|
+
hi *= 2;
|
|
108
|
+
let lo = 0;
|
|
109
|
+
for (let i = 0; i < 2200 && hi - lo > 1e-15 * hi; i++) {
|
|
110
|
+
const mid = (lo + hi) / 2;
|
|
111
|
+
if (mid === lo || mid === hi)
|
|
112
|
+
break;
|
|
113
|
+
if (cdf(mid) > target)
|
|
114
|
+
lo = mid;
|
|
115
|
+
else
|
|
116
|
+
hi = mid;
|
|
117
|
+
}
|
|
118
|
+
return (lo + hi) / 2;
|
|
119
|
+
};
|
|
120
|
+
return [solve(1 - alpha / 2), solve(alpha / 2)];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* H and I2 with Higgins and Thompson's (2002) intervals (H at least 1, as meta). Not an R function.
|
|
124
|
+
*
|
|
125
|
+
* @category Meta-analysis
|
|
126
|
+
*/
|
|
127
|
+
export function heterogeneityIntervals(Q, k, level) {
|
|
128
|
+
const dfQ = k - 1;
|
|
129
|
+
// meta reports H at least 1 (Q below its degrees of freedom: H = 1)
|
|
130
|
+
const H = k > 1 ? Math.max(1, Math.sqrt(Q / dfQ)) : NaN;
|
|
131
|
+
const I2 = k > 1 ? Math.max(0, (Q - dfQ) / Q) : NaN;
|
|
132
|
+
let lH = NaN, uH = NaN;
|
|
133
|
+
if (k > 2) {
|
|
134
|
+
const seLog = Q > k ? (0.5 * (Math.log(Q) - Math.log(dfQ))) / (Math.sqrt(2 * Q) - Math.sqrt(2 * k - 3)) : Math.sqrt((1 / (2 * (k - 2))) * (1 - 1 / (3 * (k - 2) ** 2)));
|
|
135
|
+
const zl = qnorm(0.5 + level / 2);
|
|
136
|
+
const c = Math.log(Math.max(H, 1));
|
|
137
|
+
lH = Math.max(1, Math.exp(c - zl * seLog));
|
|
138
|
+
uH = Math.max(1, Math.exp(c + zl * seLog));
|
|
139
|
+
}
|
|
140
|
+
return { H, lH, uH, I2, lI2: Math.max(0, 1 - 1 / (lH * lH)), uI2: Math.max(0, 1 - 1 / (uH * uH)) };
|
|
141
|
+
}
|
|
142
|
+
export function metaCore(TE, seTE, options = {}) {
|
|
143
|
+
// all of it is equivariant in the scale: for extreme scales (seTE beyond 2^+-200, where the variances leave or near
|
|
144
|
+
// the double range) computed on TE / c, seTE / c with c a power of two near the largest seTE (exact). Not for ordinary
|
|
145
|
+
// scales: REML's stopping rule (metafor's absolute threshold, reproduced) is not scale invariant, and R's values are
|
|
146
|
+
// kept there (1.20.0 edge-case review)
|
|
147
|
+
const mx = Math.max(...seTE.map(Math.abs));
|
|
148
|
+
const c = mx > 0 && Number.isFinite(mx) && (mx > 2 ** 200 || mx < 2 ** -200) ? 2 ** Math.round(Math.log2(mx)) : 1;
|
|
149
|
+
if (c === 1)
|
|
150
|
+
return metaCoreScaled(TE, seTE, options);
|
|
151
|
+
const r = metaCoreScaled(TE.map((t) => t / c), seTE.map((s) => s / c), { ...options, ...(options.fixedTau2 !== undefined ? { fixedTau2: options.fixedTau2 / c / c } : {}) });
|
|
152
|
+
const lin = ["TE.common", "seTE.common", "lower.common", "upper.common", "TE.random", "seTE.random", "lower.random", "upper.random", "seTE.predict", "lower.predict", "upper.predict", "tau", "lower.tau", "upper.tau"];
|
|
153
|
+
const sq = ["tau2", "lower.tau2", "upper.tau2"];
|
|
154
|
+
const out = { ...r, TE: TE.slice(), seTE: seTE.slice(), "w.common": r["w.common"].map((w) => w / c / c), "w.random": r["w.random"].map((w) => w / c / c) };
|
|
155
|
+
for (const k of lin)
|
|
156
|
+
out[k] = r[k] * c;
|
|
157
|
+
for (const k of sq)
|
|
158
|
+
out[k] = r[k] * c * c;
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
function metaCoreScaled(TE, seTE, options = {}) {
|
|
162
|
+
if (TE.length === 0) {
|
|
163
|
+
// no study to pool (metabin with every study double-zero): R's NA everywhere
|
|
164
|
+
const r = metaCoreScaled([0], [1], options);
|
|
165
|
+
for (const key of Object.keys(r))
|
|
166
|
+
if (typeof r[key] === "number")
|
|
167
|
+
r[key] = NaN;
|
|
168
|
+
return { ...r, TE: [], seTE: [], k: 0, "w.common": [], "w.random": [], "df.Q": NaN, "df.predict": NaN };
|
|
169
|
+
}
|
|
170
|
+
const k = TE.length;
|
|
171
|
+
const v = seTE.map((s) => s * s);
|
|
172
|
+
const methodTau = options.methodTau ?? "REML";
|
|
173
|
+
const ciMethod = options.methodRandomCi ?? "classic";
|
|
174
|
+
const methodTauCi = options.methodTauCi ?? (methodTau === "DL" ? "J" : "QP");
|
|
175
|
+
const level = options.level ?? 0.95;
|
|
176
|
+
const levelMa = options.levelMa ?? level;
|
|
177
|
+
const levelPredict = options.levelPredict ?? level;
|
|
178
|
+
const zMa = qnorm(0.5 + levelMa / 2);
|
|
179
|
+
const w = v.map((x) => 1 / x);
|
|
180
|
+
const sw = sum(w);
|
|
181
|
+
const teC = sum(w.map((wi, i) => wi * TE[i])) / sw;
|
|
182
|
+
const seC = Math.sqrt(1 / sw);
|
|
183
|
+
const Q = options.fixedQ ?? sum(w.map((wi, i) => wi * (TE[i] - teC) ** 2));
|
|
184
|
+
const dfQ = k - 1;
|
|
185
|
+
let tau2 = 0;
|
|
186
|
+
if (options.fixedTau2 !== undefined)
|
|
187
|
+
tau2 = options.fixedTau2;
|
|
188
|
+
else if (k > 1)
|
|
189
|
+
tau2 = rma(TE, v, { method: methodTau }).tau2;
|
|
190
|
+
const wr = v.map((x) => 1 / (x + tau2));
|
|
191
|
+
const swr = sum(wr);
|
|
192
|
+
const teR = sum(wr.map((wi, i) => wi * TE[i])) / swr;
|
|
193
|
+
let seR = Math.sqrt(1 / swr);
|
|
194
|
+
let lowR, upR, statR, pR, dfR = null;
|
|
195
|
+
if (ciMethod === "HK" && k > 1) {
|
|
196
|
+
const qhk = sum(wr.map((wi, i) => wi * (TE[i] - teR) ** 2)) / (k - 1);
|
|
197
|
+
seR = Math.sqrt(qhk / swr);
|
|
198
|
+
dfR = k - 1;
|
|
199
|
+
const tq = qt1(0.5 + levelMa / 2, dfR, true, false);
|
|
200
|
+
lowR = teR - tq * seR;
|
|
201
|
+
upR = teR + tq * seR;
|
|
202
|
+
statR = teR / seR;
|
|
203
|
+
pR = 2 * pt1(-Math.abs(statR), dfR, true, false);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
lowR = teR - zMa * seR;
|
|
207
|
+
upR = teR + zMa * seR;
|
|
208
|
+
statR = teR / seR;
|
|
209
|
+
pR = 2 * pnorm(-Math.abs(statR));
|
|
210
|
+
}
|
|
211
|
+
const statC = teC / seC;
|
|
212
|
+
// prediction interval ("V"): t(k - 1) with sqrt(tau2 + seTE.random^2)
|
|
213
|
+
// (with the classic seTE.random also under Hartung-Knapp, log 96)
|
|
214
|
+
const sePred = Math.sqrt(tau2 + 1 / swr);
|
|
215
|
+
const dfPred = k - 1;
|
|
216
|
+
const tp = dfPred > 0 ? qt1(0.5 + levelPredict / 2, dfPred, true, false) : NaN;
|
|
217
|
+
// tau2 interval
|
|
218
|
+
let lt = NaN, ut = NaN;
|
|
219
|
+
if (k > 1) {
|
|
220
|
+
if (methodTauCi === "QP") {
|
|
221
|
+
const fit = rma(TE, v, { method: methodTau, level: 100 * level });
|
|
222
|
+
const row = confintRma(fit, { type: "QP", level: 100 * level }).random.rows[0];
|
|
223
|
+
// the whole interval at 0 when Q(0) is below the lower quantile (metafor's NA upper bound; meta reports 0)
|
|
224
|
+
lt = row["ci.lb"];
|
|
225
|
+
ut = Number.isFinite(row["ci.ub"]) ? row["ci.ub"] : 0;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
[lt, ut] = genqInterval(TE, v, methodTauCi === "J" ? seTE.map((s) => 1 / s) : w, level);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const { H, lH, uH, I2, lI2, uI2 } = heterogeneityIntervals(Q, k, level);
|
|
232
|
+
return {
|
|
233
|
+
TE: TE.slice(), seTE: seTE.slice(), k,
|
|
234
|
+
"TE.common": teC, "seTE.common": seC, "lower.common": teC - zMa * seC, "upper.common": teC + zMa * seC, "statistic.common": statC, "pval.common": 2 * pnorm(-Math.abs(statC)),
|
|
235
|
+
"TE.random": teR, "seTE.random": seR, "lower.random": lowR, "upper.random": upR, "statistic.random": statR, "pval.random": pR, "df.random": dfR,
|
|
236
|
+
"seTE.predict": sePred, "lower.predict": teR - tp * sePred, "upper.predict": teR + tp * sePred, "df.predict": dfPred,
|
|
237
|
+
Q, "df.Q": dfQ, "pval.Q": k > 1 ? pchisq(Q, dfQ, { lowerTail: false }) : NaN,
|
|
238
|
+
// one study: no between-study variance (R's NA)
|
|
239
|
+
tau2: k > 1 ? tau2 : NaN, "lower.tau2": lt, "upper.tau2": ut, tau: k > 1 ? Math.sqrt(tau2) : NaN, "lower.tau": Math.sqrt(lt), "upper.tau": Math.sqrt(ut),
|
|
240
|
+
H, "lower.H": lH, "upper.H": uH, I2, "lower.I2": lI2, "upper.I2": uI2,
|
|
241
|
+
"w.common": w, "w.random": wr, methodTau, methodRandomCi: ciMethod, methodTauCi,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generic inverse-variance meta-analysis (meta's `metagen()`): study estimates TE with standard errors seTE; the
|
|
246
|
+
* common effect, the random effect with tau2 by `methodTau` (default REML) and a classic or Hartung-Knapp interval,
|
|
247
|
+
* the prediction interval (t on k - 1), Q, tau2's interval (QP, or J for DL), H and I2 with Higgins and Thompson's
|
|
248
|
+
* intervals.
|
|
249
|
+
* Equivalent to `meta::metagen()` in R.
|
|
250
|
+
*
|
|
251
|
+
* @category Meta-analysis
|
|
252
|
+
*/
|
|
253
|
+
export function metagen(TE, seTE, options = {}) {
|
|
254
|
+
checkOptions(options, METAGEN_KEYS, "metagen"); // generated: option-keys.mjs
|
|
255
|
+
if (TE.length !== seTE.length)
|
|
256
|
+
throw new RangeError("metagen: TE and seTE must have the same length");
|
|
257
|
+
if (TE.length === 0)
|
|
258
|
+
throw new RangeError("metagen: no studies");
|
|
259
|
+
const ok = TE.map((t, i) => Number.isFinite(t) && Number.isFinite(seTE[i]) && seTE[i] > 0);
|
|
260
|
+
if (ok.some((b) => !b))
|
|
261
|
+
throw new RangeError("metagen: TE must be finite and seTE finite and positive");
|
|
262
|
+
return metaCore(TE, seTE, options);
|
|
263
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type MetaCommonOptions, type MetaResult } from "./metagen.js";
|
|
2
|
+
/**
|
|
3
|
+
* Meta-analysis of continuous outcomes (meta's `metacont()`): sm "MD" (default), "SMD" (Hedges' g with the exact J;
|
|
4
|
+
* variance 1/n1 + 1/n2 + (1 - (N - 4) / ((N - 2) J^2)) g^2, log 69) or "ROM" (log ratio of means).
|
|
5
|
+
* Equivalent to `meta::metacont()` in R.
|
|
6
|
+
*
|
|
7
|
+
* @category Meta-analysis
|
|
8
|
+
*/
|
|
9
|
+
export declare function metacont(n1: readonly number[], m1: readonly number[], sd1: readonly number[], n2: readonly number[], m2: readonly number[], sd2: readonly number[], options?: MetaCommonOptions & {
|
|
10
|
+
sm?: "MD" | "SMD" | "ROM";
|
|
11
|
+
}): MetaResult;
|
|
12
|
+
/**
|
|
13
|
+
* Meta-analysis of incidence rates (meta's `metainc()`): events e1 / e2 in person-times t1 / t2; sm "IRR" (default) or
|
|
14
|
+
* "IRD"; method "MH" (default; Greenland and Robins 1985, no increments) or "Inverse". Studies with a zero get 0.5 added
|
|
15
|
+
* to the events for the study values (log 67).
|
|
16
|
+
* Equivalent to `meta::metainc()` in R.
|
|
17
|
+
*
|
|
18
|
+
* @category Meta-analysis
|
|
19
|
+
*/
|
|
20
|
+
export declare function metainc(e1: readonly number[], t1: readonly number[], e2: readonly number[], t2: readonly number[], options?: MetaCommonOptions & {
|
|
21
|
+
sm?: "IRR" | "IRD";
|
|
22
|
+
method?: "MH" | "Inverse";
|
|
23
|
+
incr?: number;
|
|
24
|
+
}): MetaResult;
|
|
25
|
+
/**
|
|
26
|
+
* Meta-analysis of correlations (meta's `metacor()`): sm "ZCOR" (Fisher's z, variance 1/(n - 3), default) or "COR"
|
|
27
|
+
* (variance (1 - r^2)^2 / (n - 1)).
|
|
28
|
+
* Equivalent to `meta::metacor()` in R.
|
|
29
|
+
*
|
|
30
|
+
* @category Meta-analysis
|
|
31
|
+
*/
|
|
32
|
+
export declare function metacor(cor: readonly number[], n: readonly number[], options?: MetaCommonOptions & {
|
|
33
|
+
sm?: "ZCOR" | "COR";
|
|
34
|
+
}): MetaResult;
|
|
35
|
+
/**
|
|
36
|
+
* Meta-analysis of single means (meta's `metamean()`): sm "MRAW" (default; variance sd^2/n) or "MLN" (log mean,
|
|
37
|
+
* variance sd^2 / (n mean^2)).
|
|
38
|
+
* Equivalent to `meta::metamean()` in R.
|
|
39
|
+
*
|
|
40
|
+
* @category Meta-analysis
|
|
41
|
+
*/
|
|
42
|
+
export declare function metamean(n: readonly number[], mean: readonly number[], sd: readonly number[], options?: MetaCommonOptions & {
|
|
43
|
+
sm?: "MRAW" | "MLN";
|
|
44
|
+
}): MetaResult;
|
|
45
|
+
/**
|
|
46
|
+
* Meta-analysis of single incidence rates (meta's `metarate()`): sm "IRLN" (log rate, default), "IR", "IRS" (square
|
|
47
|
+
* root) or "IRFT" (Freeman-Tukey); 0.5 added to zero counts for IR and IRLN.
|
|
48
|
+
* Equivalent to `meta::metarate()` in R.
|
|
49
|
+
*
|
|
50
|
+
* @category Meta-analysis
|
|
51
|
+
*/
|
|
52
|
+
export declare function metarate(event: readonly number[], time: readonly number[], options?: MetaCommonOptions & {
|
|
53
|
+
sm?: "IRLN" | "IR" | "IRS" | "IRFT";
|
|
54
|
+
incr?: number;
|
|
55
|
+
}): MetaResult;
|
|
56
|
+
/**
|
|
57
|
+
* Meta-analysis of single proportions by the inverse variance (meta's `metaprop(method = "Inverse")`): sm "PLOGIT"
|
|
58
|
+
* (default; (x + 0.5)/(n + 1) for 0 or n events), "PFT" (Freeman-Tukey), "PAS" (arcsine), "PRAW" or "PLN"
|
|
59
|
+
* (log((x + 0.5)/(n + 0.5)) for 0; for n events the variance 1/x - 1/(n + 0.5)). The default method of meta, the GLMM, is {@link metapropGlmm}.
|
|
60
|
+
* Equivalent to `meta::metaprop()` in R.
|
|
61
|
+
*
|
|
62
|
+
* @category Meta-analysis
|
|
63
|
+
*/
|
|
64
|
+
export declare function metaprop(event: readonly number[], n: readonly number[], options?: MetaCommonOptions & {
|
|
65
|
+
sm?: "PLOGIT" | "PFT" | "PAS" | "PRAW" | "PLN";
|
|
66
|
+
incr?: number;
|
|
67
|
+
}): MetaResult;
|
|
68
|
+
/**
|
|
69
|
+
* The result of {@link metapropGlmm}: as {@link MetaResult}, with Q, df.Q and pval.Q as [Wald, LRT].
|
|
70
|
+
*
|
|
71
|
+
* @category Meta-analysis
|
|
72
|
+
*/
|
|
73
|
+
export type MetapropGlmmResult = Omit<MetaResult, "Q" | "df.Q" | "pval.Q"> & {
|
|
74
|
+
Q: [number, number];
|
|
75
|
+
"df.Q": [number, number];
|
|
76
|
+
"pval.Q": [number, number];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Meta-analysis of single proportions by a random intercept logistic model (meta's `metaprop()` default, method
|
|
80
|
+
* "GLMM"; log 75-76): glmer(x/n ~ 1 + (1 | study), binomial, weights n, nAGQ = 7) for the random effect and tau2,
|
|
81
|
+
* glm(x/n ~ 1) for the common effect; Q = [Wald, LRT]: the Wald test of equal study effects in glm(x/n ~ study) and the
|
|
82
|
+
* common glm's deviance; H and I2 from the Wald Q. Study values are the PLOGIT ones.
|
|
83
|
+
* Equivalent to `meta::metaprop()` in R.
|
|
84
|
+
*
|
|
85
|
+
* @category Meta-analysis
|
|
86
|
+
*/
|
|
87
|
+
export declare function metapropGlmm(event: readonly number[], n: readonly number[], options?: Omit<MetaCommonOptions, "methodTau" | "methodTauCi">): MetapropGlmmResult;
|