@numero-uno-jpn/rstats 1.15.0 → 1.17.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 +22 -0
- package/README.ja.md +8 -8
- package/README.md +8 -8
- package/dist/causal/mediate.d.ts +146 -0
- package/dist/causal/mediate.js +399 -0
- package/dist/causal/mediationProcedures.d.ts +231 -0
- package/dist/causal/mediationProcedures.js +240 -0
- package/dist/causal/moderation.d.ts +148 -0
- package/dist/causal/moderation.js +165 -0
- package/dist/causal.js +2 -2
- package/dist/chunks/{chunk-FD375XBW.js → chunk-23QCIPET.js} +2 -2
- package/dist/chunks/chunk-3UEYA6VG.js +2 -0
- package/dist/chunks/{chunk-SMA62635.js → chunk-3Y4DNK4O.js} +2 -2
- package/dist/chunks/{chunk-L7HJGM52.js → chunk-4BGGWQWS.js} +2 -2
- package/dist/chunks/chunk-5UFVACSV.js +2 -0
- package/dist/chunks/{chunk-5BCXHJPF.js → chunk-5W2OZAHQ.js} +2 -2
- package/dist/chunks/{chunk-PZRABNMZ.js → chunk-6MLDKHTY.js} +2 -2
- package/dist/chunks/{chunk-XVRRYHLM.js → chunk-72I7GDWL.js} +2 -2
- package/dist/chunks/chunk-BWDXJL7T.js +2 -0
- package/dist/chunks/{chunk-VO3E4Q6H.js → chunk-DD2GG4EC.js} +1 -1
- package/dist/chunks/{chunk-CIBAGTO2.js → chunk-EB45CDFA.js} +2 -2
- package/dist/chunks/chunk-EIUK6TKF.js +2 -0
- package/dist/chunks/chunk-GIIURG5X.js +2 -0
- package/dist/chunks/chunk-GLABB425.js +2 -0
- package/dist/chunks/{chunk-OO22LZ7Q.js → chunk-GOYTZ5RB.js} +2 -2
- package/dist/chunks/{chunk-HF4TT233.js → chunk-GTSK4IN4.js} +1 -1
- package/dist/chunks/{chunk-SNQABDAT.js → chunk-I2KJMF4G.js} +1 -1
- package/dist/chunks/chunk-JG4TWDQ4.js +2 -0
- package/dist/chunks/{chunk-UFJFVNC6.js → chunk-JHABMYNH.js} +1 -1
- package/dist/chunks/chunk-JV3POOET.js +2 -0
- package/dist/chunks/chunk-K3YSXDTU.js +2 -0
- package/dist/chunks/{chunk-R74QJUYU.js → chunk-KY53MB3J.js} +2 -2
- package/dist/chunks/{chunk-AGA7JCRF.js → chunk-L77QFL3C.js} +2 -2
- package/dist/chunks/chunk-LKKUUREA.js +2 -0
- package/dist/chunks/{chunk-WL3JGBLZ.js → chunk-LY2UZGUL.js} +2 -2
- package/dist/chunks/chunk-NCDPZSI2.js +2 -0
- package/dist/chunks/{chunk-6SZLUVSL.js → chunk-NCRL33PQ.js} +2 -2
- package/dist/chunks/{chunk-RHNGF7R7.js → chunk-NPWWGIFG.js} +2 -2
- package/dist/chunks/chunk-O4D43LWM.js +2 -0
- package/dist/chunks/chunk-PSQ6MLJM.js +2 -0
- package/dist/chunks/{chunk-M3HFLMXL.js → chunk-QCPGV7XH.js} +2 -2
- package/dist/chunks/{chunk-JAXYZJV7.js → chunk-RM5D7Q7W.js} +2 -2
- package/dist/chunks/{chunk-IMSXMJ43.js → chunk-RNGDVSTS.js} +2 -2
- package/dist/chunks/{chunk-3K47QLCY.js → chunk-SA2E5GVO.js} +2 -2
- package/dist/chunks/{chunk-VHMFOILD.js → chunk-T5ZALLTJ.js} +2 -2
- package/dist/chunks/{chunk-GBNGGBU3.js → chunk-TTOJDLIQ.js} +2 -2
- package/dist/chunks/{chunk-FV4ZQPRI.js → chunk-V54MBEJM.js} +2 -2
- package/dist/chunks/chunk-VZSQAGL2.js +3 -0
- package/dist/chunks/{chunk-NULJXDAR.js → chunk-XEJX5HBJ.js} +2 -2
- package/dist/chunks/chunk-XPYZOG5H.js +2 -0
- package/dist/chunks/{chunk-4EH3O466.js → chunk-XR7Y4ZV6.js} +2 -2
- package/dist/chunks/{chunk-JGZSGGMD.js → chunk-YMI33F7W.js} +2 -2
- package/dist/chunks/{chunk-MKCPS5QQ.js → chunk-ZRKXHVTJ.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/causal.d.ts +3 -0
- package/dist/entries/causal.js +3 -0
- package/dist/entries/distributions.d.ts +1 -0
- package/dist/entries/distributions.js +1 -0
- package/dist/entries/regression.d.ts +3 -0
- package/dist/entries/regression.js +6 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/betareg.d.ts +278 -0
- package/dist/models/betareg.js +588 -0
- package/dist/models/fitOptions.js +6 -4
- package/dist/models/loglin.d.ts +186 -0
- package/dist/models/loglin.js +349 -0
- package/dist/models/survreg.d.ts +43 -0
- package/dist/models/survreg.js +6 -3
- package/dist/models/tobit.d.ts +132 -0
- package/dist/models/tobit.js +172 -0
- package/dist/multivariate.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/random/mvrnorm.d.ts +60 -0
- package/dist/random/mvrnorm.js +237 -0
- package/dist/regression.js +3 -3
- package/dist/rstats.js +16 -16
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -15
- package/dist/timeseries.js +2 -2
- package/package.json +1 -1
- package/dist/chunks/chunk-5JKKIVYL.js +0 -3
- package/dist/chunks/chunk-5Q5YVM7S.js +0 -2
- package/dist/chunks/chunk-AILN2NGE.js +0 -2
- package/dist/chunks/chunk-APOF7BLH.js +0 -2
- package/dist/chunks/chunk-HSVVCFEN.js +0 -2
- package/dist/chunks/chunk-KQGH6SEW.js +0 -2
- package/dist/chunks/chunk-OBTCIG5D.js +0 -2
- package/dist/chunks/chunk-P4TKSL4W.js +0 -2
- package/dist/chunks/chunk-RV4JZHTE.js +0 -2
- package/dist/chunks/chunk-U5UOVXKD.js +0 -2
- package/dist/chunks/chunk-VHBIWPB4.js +0 -2
- package/dist/chunks/chunk-YYLBBEWZ.js +0 -2
- package/dist/chunks/chunk-ZDUVFNFH.js +0 -2
- package/dist/chunks/chunk-ZUTVNRML.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,28 @@ While the version is 0.x, a minor release (0.y.0) may contain breaking changes;
|
|
|
7
7
|
they are listed under **Breaking** for each release. From 1.0.0 the project follows
|
|
8
8
|
[Semantic Versioning](https://semver.org/).
|
|
9
9
|
|
|
10
|
+
## 1.17.0 - 2026-11-25
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Tobit regression**: `tobit` and `tobitSummary` (after `AER::tobit`): a formula entry point to `survreg` for a response censored at a left and/or right limit, with any survreg distribution; the Wald test of the regression and the null model's log-likelihood (McFadden's R², the likelihood-ratio test).
|
|
15
|
+
- **Beta regression**: `betareg`, `betaregSummary`, `betaregConfint`, `betaregPredict` and `betaregResiduals` (after `betareg::betareg`): constant precision (`y ~ x`) or a precision model (`y ~ x | z`), mean links logit, probit, cloglog, cauchit, log and loglog, precision links identity, log and sqrt, maximum likelihood, bias-corrected and bias-reduced estimates (Kosmidis and Firth 2010), predictions of the means, precisions, variances, densities, distribution functions and quantiles, and the seven types of residuals ([the differences](docs/differences-from-r.md#tobit-beta-regression-and-log-linear-models-1170)).
|
|
16
|
+
- `survreg` takes the t distribution's degrees of freedom also as `parms` (R's name), besides `df`; so does `tobit`.
|
|
17
|
+
- **Log-linear models**: `loglin` (after `stats::loglin`: iterative proportional fitting with R's iterations), `loglm` (after `MASS::loglm`: a formula on a table or on a data frame of frequencies), `loglmResiduals` and `loglmAnova`.
|
|
18
|
+
|
|
19
|
+
## 1.16.0 - 2026-11-25
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **Causal mediation analysis**: `mediate` (after `mediation::mediate`) for `lm` and binomial (logit, probit) `glm` mediator and outcome models: the average causal mediation effects, direct effects, total effect and proportions mediated with their averages, by the quasi-Bayesian approximation or the nonparametric bootstrap (percentile and BCa intervals), with `treatValue` / `controlValue`, `covariates` and HC3 covariances. The same draws, estimates, intervals and p-values as R under the same seed ([the differences](docs/differences-from-r.md#mediation-and-moderation-1160)).
|
|
24
|
+
- **Moderation**: `simSlopes` and `johnsonNeyman` (after `interactions::sim_slopes` and `johnson_neyman`): simple slopes at the moderator's mean ± SD or given values, with HC3, and the Johnson-Neyman interval.
|
|
25
|
+
- **ReactiveStat's procedures**: `sobelTest`, `mediationMonteCarlo` (the Monte Carlo method on the coefficients) and `moderatedMediation` (effects at a low and a high moderator value and the index of moderated mediation).
|
|
26
|
+
- **`mvrnorm`** (after `MASS::mvrnorm`) in the random numbers: R's values in 1 and 2 dimensions, R's distribution in more.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- The options a formula fit of `lm` or `glm` remembers (for `step`, `drop1`, `add1` and `mediate`) are kept on the result under a registered symbol, so a fit made with one CDN bundle (`dist/rstats.js`) is accepted by another (`dist/causal.js`).
|
|
31
|
+
|
|
10
32
|
## 1.15.0 - 2026-11-25
|
|
11
33
|
|
|
12
34
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -16,7 +16,7 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
|
|
|
16
16
|
- **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
|
|
17
17
|
tree-shaking が効きます (`pnorm` だけなら gzip で 1.6 KB)。
|
|
18
18
|
|
|
19
|
-
状態: **1.
|
|
19
|
+
状態: **1.17.0。** R の stats パッケージの数値計算の中心
|
|
20
20
|
(分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
|
|
21
21
|
[ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
|
|
22
22
|
|
|
@@ -217,9 +217,9 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
217
217
|
|---|---|
|
|
218
218
|
| 特殊関数 | `gamma`, `lgamma`, `beta`, `lbeta`, `choose`, `lchoose`, `factorial`, `lfactorial`, `digamma`, `trigamma`, `psigamma`, `besselI`, `besselK`, `besselJ`, `besselY`。R にはない `erf`, `erfc`, `erfinv`, `erfcinv`, `gammainc`, `perm` と、R の C API (Rmath.h) の `log1pmx`, `lgamma1p`, `log1mexp`, `log1pexp` も |
|
|
219
219
|
| 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`)。多項分布の確率 (`dmultinom`)。逆ガンマ、Kumaraswamy、Pareto、三角、Laplace (extraDistr) と逆正弦。`distSummary` (平均・分散・標準偏差・中央値・最頻値・歪度・尖度) |
|
|
220
|
-
| 乱数 | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister と L'Ecuyer-CMRG、`sample.kind` の Rejection と Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
|
|
220
|
+
| 乱数 | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister と L'Ecuyer-CMRG、`sample.kind` の Rejection と Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`), `r2dtable`, `mvrnorm` (`MASS::mvrnorm`) |
|
|
221
221
|
| 時系列 | `acf`、`pacf`、`ccf` (`stats::acf`、`stats::pacf`、`stats::ccf`)、`@numero-uno-jpn/rstats/timeseries` |
|
|
222
|
-
| 因果推論 | `match` (傾向スコアのマッチング: `ties = FALSE`・`replace = FALSE` の `Matching::Match`。ATT・ATE・ATC、1:M、キャリパー)、`matchWeights` (`cobalt::get.w`)、`weightit` (逆確率重み: glm・cbps・ipt・ebal の `WeightIt::weightit`。ATE・ATT・ATC・ATO)、`trimWeights`・`weightSummary`、`balTab` (マッチング・重み付けの前後の標準化平均差と分散比: `cobalt::bal.tab`)、`tableOneSmd` (`tableone::ExtractSmd`)、`@numero-uno-jpn/rstats/causal` |
|
|
222
|
+
| 因果推論 | `match` (傾向スコアのマッチング: `ties = FALSE`・`replace = FALSE` の `Matching::Match`。ATT・ATE・ATC、1:M、キャリパー)、`matchWeights` (`cobalt::get.w`)、`weightit` (逆確率重み: glm・cbps・ipt・ebal の `WeightIt::weightit`。ATE・ATT・ATC・ATO)、`trimWeights`・`weightSummary`、`balTab` (マッチング・重み付けの前後の標準化平均差と分散比: `cobalt::bal.tab`)、`tableOneSmd` (`tableone::ExtractSmd`)、`mediate` (因果媒介分析: `mediation::mediate`、準ベイズ近似とブートストラップ)、`simSlopes`・`johnsonNeyman` (`interactions::sim_slopes`)、`sobelTest`・`mediationMonteCarlo`・`moderatedMediation` (index of moderated mediation)、`@numero-uno-jpn/rstats/causal` |
|
|
223
223
|
| 記述統計 | `sum`, `prod`, `mean`, `weightedMean` (`weighted.mean`), `variance` (`var`), `sd`, `median`, `range`, `cumsum`, `cumprod`, `cummax`, `cummin`, `diff`, `quantile`, `IQR`, `fivenum`, `mad`, `rank`, `cov`, `cor`, `tabulate`, `table`, `unique`, `cut`, `findInterval`, `pretty`, `hist`, `ecdf`, `scale`, `skewness`, `kurtosis`, `geometricMean`, `modes`, `meanAD`, `cv` |
|
|
224
224
|
| 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (一元配置。表は当てはめの `aovSummary`), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `tamhaneT2Test` (Tamhane の T2 と T2')、`pageTest`、`grubbsTest`・`pgrubbs`・`qgrubbs`、`pAdjust` (`p.adjust`) |
|
|
225
225
|
| 分散分析 | formula で呼ぶ `aov` と `aovSummary` (多元、交互作用、共変量、`Error()` の層), `anova` (`anova.lm`。逐次の表とモデルの比較), `Anova` (car の Type II と III), `aovEz` (afex。反復測定と混合計画、Greenhouse-Geisser と Huynh-Feldt の補正、一般化 η² と偏 η²), `mauchlyTest` (`mauchly.test`) |
|
|
@@ -227,7 +227,7 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
227
227
|
| 試験デザインの標本サイズと検出力 | `epiSsequb`・`epiSsequc`・`epiSsninfb`・`epiSsninfc`・`epiSssupb`・`epiSssupc` (epiR: 比率と平均の同等性・非劣性・優越性)、`powerPaired2x2` (対応のある 2 × 2 表の正確な McNemar 検定の検出力)、`ssizeCT`・`powerCT`・`ssizeEpi`・`powerEpi`・`numDEpi` (生存時間の標本サイズと検出力)、`ph2simon` (Simon の 2 段階デザイン) |
|
|
228
228
|
| メタアナリシス | `escalc` (効果量と標本分散)、`rma` (等効果・ランダム効果のメタアナリシスとメタ回帰)、`confintRma`・`predictRma`・`regtest` (metafor) |
|
|
229
229
|
| 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (formula とデータフレーム、または行列で渡す。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`svyglm` (逆確率重みに対する `survey::svyglm`: デザインに基づく標準誤差)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`)。`vcovHC`、`vcovCL` (sandwich: HC0〜HC5、一元と多元のクラスター)、`coeftest`、`coefci` (lmtest)。`step`、`stepAIC` (lm と glm の AIC・BIC による段階的な変数選択)、`drop1`、`add1`、`extractAIC` |
|
|
230
|
-
| 回帰 | `multinom`・`multinomSummary`・`multinomConfint`・`multinomPredict`・`multinomAnova`・`multinomVcov` (nnet: 重みと decay つきの多項ロジスティック回帰)、`polr`・`polrSummary`・`polrVcov`・`polrPredict`・`polrConfint`・`polrAnova` (MASS: logistic・probit・cloglog・loglog・cauchit のリンクによる順序ロジスティック回帰)、`rlm`・`rlmSummary`・`rlmVcov`・`psiHuber`・`psiHampel`・`psiBisquare` (MASS: M 推定と MM 推定によるロバスト回帰)、`nls`・`nlsSummary`・`nlsVcov`・`nlsPredict`・`nlsConfint`・`nlsAnova` (非線形最小二乗法: 既定・`plinear`・`port` のアルゴリズムと 10 個の自己開始モデル)、`rq`・`rqSummary`・`rqPredict`・`rqPredictInterval`・`rqAnova` (分位点回帰)、`geeglm`・`geeSummary`・`geeVcov`・`geePredict`・`geeAnova`・`geeQIC` (一般化推定方程式)、`glmnet`・`glmnetCoef`・`glmnetPredict`・`cvGlmnet` (Gaussian・binomial・Poisson・multinomial の正則化回帰)。`@numero-uno-jpn/rstats/regression` から import します |
|
|
230
|
+
| 回帰 | `tobit`・`tobitSummary` (AER: `survreg` の上の Tobit 回帰、下限・上限、survreg のどの分布でも)、`betareg`・`betaregSummary`・`betaregConfint`・`betaregPredict`・`betaregResiduals` (betareg: 精度が定数か回帰のベータ回帰、平均のリンク 6 つ、最尤・バイアス補正・バイアス減少)、`loglin`・`loglm`・`loglmResiduals`・`loglmAnova` (反復比例当てはめによる対数線形モデル)、`multinom`・`multinomSummary`・`multinomConfint`・`multinomPredict`・`multinomAnova`・`multinomVcov` (nnet: 重みと decay つきの多項ロジスティック回帰)、`polr`・`polrSummary`・`polrVcov`・`polrPredict`・`polrConfint`・`polrAnova` (MASS: logistic・probit・cloglog・loglog・cauchit のリンクによる順序ロジスティック回帰)、`rlm`・`rlmSummary`・`rlmVcov`・`psiHuber`・`psiHampel`・`psiBisquare` (MASS: M 推定と MM 推定によるロバスト回帰)、`nls`・`nlsSummary`・`nlsVcov`・`nlsPredict`・`nlsConfint`・`nlsAnova` (非線形最小二乗法: 既定・`plinear`・`port` のアルゴリズムと 10 個の自己開始モデル)、`rq`・`rqSummary`・`rqPredict`・`rqPredictInterval`・`rqAnova` (分位点回帰)、`geeglm`・`geeSummary`・`geeVcov`・`geePredict`・`geeAnova`・`geeQIC` (一般化推定方程式)、`glmnet`・`glmnetCoef`・`glmnetPredict`・`cvGlmnet` (Gaussian・binomial・Poisson・multinomial の正則化回帰)。`@numero-uno-jpn/rstats/regression` から import します |
|
|
231
231
|
| 多変量解析 | `manova`・`manovaSummary` (逐次 MANOVA: Pillai・Wilks・Hotelling-Lawley・Roy)、`lda`・`ldaPredict` (線形判別分析)、`cancor` (正準相関)、`dist`・`asDist`・`hclust`・`cutree`・`kmeans` (クラスタ分析)、`cmdscale` (古典的多次元尺度法)、`ca`・`caSummary`・`caCoord` (対応分析)、`mjca` (多重対応分析)、`sammon`・`isoMDS` (非計量多次元尺度法)。`@numero-uno-jpn/rstats/multivariate` から import します |
|
|
232
232
|
| 混合モデル | `lmer` (lme4: REML と最尤法、相関のある変量効果と相関のない変量効果、交差と入れ子の群。`fixef`、`vcov`、`VarCorr`、`ranef`、`logLik`、`AIC`、`BIC`、`REMLcrit`、`isSingular`)、`lmerSummary`・`lmerContest`・`lmerAnova` (lmerTest: Satterthwaite の t 検定と F 検定、Type I/II/III の分散分析表。当てはめどうしの尤度比検定)、`glmer` (lme4: glm のすべての族、ラプラス近似と適応的 Gauss-Hermite 求積)、`glmerSummary`・`glmerAnova`・`glmerPredict`・`lmerPredict`・`confintLmer`・`confintGlmer`・`simulateLmer`・`simulateGlmer`。
|
|
233
233
|
`@numero-uno-jpn/rstats/mixed` から import する |
|
|
@@ -301,8 +301,8 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
301
301
|
| `glm` と `glmSummary` / `glm` とそのすべての関数 | 40.6 / 56.9 KB |
|
|
302
302
|
| `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 19.4 / 70.0 KB |
|
|
303
303
|
| `glmer` (`/mixed` から) / `glmerSummary`・`glmerAnova`・`glmerPredict` も | 47.2 / 66.1 KB |
|
|
304
|
-
| `polr` / `rlm` / `nls` (`/regression` から) |
|
|
305
|
-
| すべて (`/mixed` と `/regression` を除く) |
|
|
304
|
+
| `polr` / `rlm` / `nls` (`/regression` から) | 25.0 / 14.6 / 8.0 KB |
|
|
305
|
+
| すべて (`/mixed` と `/regression` を除く) | 334.0 KB |
|
|
306
306
|
|
|
307
307
|
(`npm run size` で測れます。)
|
|
308
308
|
|
|
@@ -312,12 +312,12 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
312
312
|
`/regression` の `polr`・`rlm`・`nls` とその関数は、この方法でしか import できません。メインの入口には含めていません)。
|
|
313
313
|
|
|
314
314
|
バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` と `/regression` 以外のすべての関数を含む
|
|
315
|
-
minify 済みの ES モジュール、gzip で
|
|
315
|
+
minify 済みの ES モジュール、gzip で 334 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
|
|
316
316
|
そのまま配信します。
|
|
317
317
|
|
|
318
318
|
```html
|
|
319
319
|
<script type="module">
|
|
320
|
-
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.
|
|
320
|
+
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.17.0/dist/rstats.js";
|
|
321
321
|
console.log(pnorm(1.96)); // ≈ 0.9750021049
|
|
322
322
|
</script>
|
|
323
323
|
```
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
|
|
|
14
14
|
- **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
|
|
15
15
|
(`pnorm` alone is 1.6 KB gzipped).
|
|
16
16
|
|
|
17
|
-
Status: **1.
|
|
17
|
+
Status: **1.17.0.** The goal is to cover the numerical core of R's
|
|
18
18
|
`stats` package (distributions, descriptive statistics, hypothesis tests, linear models, special
|
|
19
19
|
functions, numerical methods and the basics of linear algebra) with R-compatible results; see [ROADMAP.md](ROADMAP.md) for what remains. See [CHANGELOG.md](CHANGELOG.md).
|
|
20
20
|
|
|
@@ -215,9 +215,9 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
215
215
|
|---|---|
|
|
216
216
|
| Special functions | `gamma`, `lgamma`, `beta`, `lbeta`, `choose`, `lchoose`, `factorial`, `lfactorial`, `digamma`, `trigamma`, `psigamma`, `besselI`, `besselK`, `besselJ`, `besselY`; also `erf`, `erfc`, `erfinv`, `erfcinv`, `gammainc` and `perm`, which R lacks, and `log1pmx`, `lgamma1p`, `log1mexp`, `log1pexp` from R's C API (Rmath.h) |
|
|
217
217
|
| Distributions (d/p/q) | normal, t, chi-squared, F, beta, gamma, binomial, Poisson, uniform, exponential, log-normal, logistic, Cauchy, Weibull, geometric, negative binomial, hypergeometric, Wilcoxon signed rank and rank sum, studentized range (`ptukey`, `qtukey`), non-central chi-squared, t, F and beta (`ncp`); the multinomial probability (`dmultinom`); inverse gamma, Kumaraswamy, Pareto, triangular, Laplace (extraDistr) and arcsine; `distSummary` (mean, variance, sd, median, mode, skewness, kurtosis) |
|
|
218
|
-
| Random numbers | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister and L'Ecuyer-CMRG, `sample.kind` Rejection and Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 `r*` functions, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
|
|
218
|
+
| Random numbers | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister and L'Ecuyer-CMRG, `sample.kind` Rejection and Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 `r*` functions, `sample`, `sampleInt` (`sample.int`), `r2dtable`, `mvrnorm` (`MASS::mvrnorm`) |
|
|
219
219
|
| Time series | `acf`, `pacf`, `ccf` (`stats::acf`, `stats::pacf`, `stats::ccf`) from `@numero-uno-jpn/rstats/timeseries` |
|
|
220
|
-
| Causal inference | `match` (propensity score matching: `Matching::Match` with `ties = FALSE`, `replace = FALSE`; ATT, ATE and ATC, 1:M, caliper), `matchWeights` (`cobalt::get.w`), `weightit` (inverse probability weights: `WeightIt::weightit` with glm, cbps, ipt and ebal; ATE, ATT, ATC and ATO), `trimWeights` and `weightSummary`, `balTab` (standardized mean differences and variance ratios before and after: `cobalt::bal.tab`) and `tableOneSmd` (`tableone::ExtractSmd`), from `@numero-uno-jpn/rstats/causal` |
|
|
220
|
+
| Causal inference | `match` (propensity score matching: `Matching::Match` with `ties = FALSE`, `replace = FALSE`; ATT, ATE and ATC, 1:M, caliper), `matchWeights` (`cobalt::get.w`), `weightit` (inverse probability weights: `WeightIt::weightit` with glm, cbps, ipt and ebal; ATE, ATT, ATC and ATO), `trimWeights` and `weightSummary`, `balTab` (standardized mean differences and variance ratios before and after: `cobalt::bal.tab`) and `tableOneSmd` (`tableone::ExtractSmd`); `mediate` (causal mediation analysis: `mediation::mediate`, quasi-Bayesian and bootstrap), `simSlopes` and `johnsonNeyman` (`interactions::sim_slopes`), `sobelTest`, `mediationMonteCarlo` and `moderatedMediation` (the index of moderated mediation), from `@numero-uno-jpn/rstats/causal` |
|
|
221
221
|
| Descriptive statistics | `sum`, `prod`, `mean`, `weightedMean` (`weighted.mean`), `variance` (`var`), `sd`, `median`, `range`, `cumsum`, `cumprod`, `cummax`, `cummin`, `diff`, `quantile`, `IQR`, `fivenum`, `mad`, `rank`, `cov`, `cor`, `tabulate`, `table`, `unique`, `cut`, `findInterval`, `pretty`, `hist`, `ecdf`, `scale`, `skewness`, `kurtosis`, `geometricMean`, `modes`, `meanAD`, `cv` |
|
|
222
222
|
| Hypothesis tests | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (one way, a fit whose table is `aovSummary`), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `tamhaneT2Test` (Tamhane's T2/T2'), `pageTest`, `grubbsTest`, `pgrubbs`, `qgrubbs`, `pAdjust` (`p.adjust`) |
|
|
223
223
|
| Analysis of variance | `aov` and `aovSummary` with a formula (several factors, interactions, covariates, `Error()` strata), `anova` (`anova.lm`, sequential and model comparison), `Anova` (car: types II and III), `aovEz` (afex: repeated-measures and mixed designs, Greenhouse-Geisser and Huynh-Feldt corrections, generalized and partial eta squared), `mauchlyTest` (`mauchly.test`) |
|
|
@@ -225,7 +225,7 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
225
225
|
| Sample size and power for trial designs | `epiSsequb`, `epiSsequc`, `epiSsninfb`, `epiSsninfc`, `epiSssupb`, `epiSssupc` (epiR: equivalence, non-inferiority and superiority for proportions and means), `powerPaired2x2` (exact paired McNemar power), `ssizeCT`, `powerCT`, `ssizeEpi`, `powerEpi`, `numDEpi` (survival sample size and power), `ph2simon` (Simon two-stage designs) |
|
|
226
226
|
| Meta-analysis | `escalc` (effect sizes and sampling variances), `rma` (equal- and random-effects meta-analysis and meta-regression), `confintRma`, `predictRma`, `regtest` (metafor) |
|
|
227
227
|
| Linear models | `lm` (a formula and a data frame, or a matrix, with the `summary` quantities), `modelMatrix` (`model.matrix`), `confint`, `predict`; `glm` (a formula and a data frame, or a matrix; every family and link of R's `stats`) with `glmSummary` (`summary.glm`), `svyglm` (`survey::svyglm` for inverse probability weights: design-based standard errors), `glmResiduals` (the four kinds), `glmHatvalues`, `glmRstandard`, `glmCooksDistance`, `glmPredict` (with standard errors), `glmConfint` (profile likelihood, exact limits), `glmAnova` (`anova.glm`); `vcovHC`, `vcovCL` (sandwich: HC0 to HC5, one-way and multi-way clustered), `coeftest`, `coefci` (lmtest); `step`, `stepAIC` (stepwise selection by AIC or BIC for lm and glm), `drop1`, `add1`, `extractAIC` |
|
|
228
|
-
| Regression | `multinom`, `multinomSummary`, `multinomConfint`, `multinomPredict`, `multinomAnova`, `multinomVcov` (nnet: multinomial logistic regression with weights and decay), `polr`, `polrSummary`, `polrVcov`, `polrPredict`, `polrConfint`, `polrAnova` (MASS: ordinal logistic regression with logistic, probit, cloglog, loglog and cauchit links); `rlm`, `rlmSummary`, `rlmVcov`, `psiHuber`, `psiHampel`, `psiBisquare` (MASS: robust M and MM regression); `nls`, `nlsSummary`, `nlsVcov`, `nlsPredict`, `nlsConfint`, `nlsAnova` (nonlinear least squares: default, `plinear` and `port` algorithms, and 10 self-starting models); `rq`, `rqSummary`, `rqPredict`, `rqPredictInterval`, `rqAnova` (quantile regression); `geeglm`, `geeSummary`, `geeVcov`, `geePredict`, `geeAnova`, `geeQIC` (generalized estimating equations); `glmnet`, `glmnetCoef`, `glmnetPredict`, `cvGlmnet` (penalized Gaussian, binomial, Poisson and multinomial regression), from `@numero-uno-jpn/rstats/regression` |
|
|
228
|
+
| Regression | `tobit`, `tobitSummary` (AER: tobit regression on `survreg`, left and right limits, any survreg distribution); `betareg`, `betaregSummary`, `betaregConfint`, `betaregPredict`, `betaregResiduals` (betareg: beta regression with a constant or modelled precision, six mean links, maximum likelihood, bias-corrected and bias-reduced); `loglin`, `loglm`, `loglmResiduals`, `loglmAnova` (log-linear models by iterative proportional fitting); `multinom`, `multinomSummary`, `multinomConfint`, `multinomPredict`, `multinomAnova`, `multinomVcov` (nnet: multinomial logistic regression with weights and decay), `polr`, `polrSummary`, `polrVcov`, `polrPredict`, `polrConfint`, `polrAnova` (MASS: ordinal logistic regression with logistic, probit, cloglog, loglog and cauchit links); `rlm`, `rlmSummary`, `rlmVcov`, `psiHuber`, `psiHampel`, `psiBisquare` (MASS: robust M and MM regression); `nls`, `nlsSummary`, `nlsVcov`, `nlsPredict`, `nlsConfint`, `nlsAnova` (nonlinear least squares: default, `plinear` and `port` algorithms, and 10 self-starting models); `rq`, `rqSummary`, `rqPredict`, `rqPredictInterval`, `rqAnova` (quantile regression); `geeglm`, `geeSummary`, `geeVcov`, `geePredict`, `geeAnova`, `geeQIC` (generalized estimating equations); `glmnet`, `glmnetCoef`, `glmnetPredict`, `cvGlmnet` (penalized Gaussian, binomial, Poisson and multinomial regression), from `@numero-uno-jpn/rstats/regression` |
|
|
229
229
|
| Multivariate analysis | `manova`, `manovaSummary` (sequential MANOVA: Pillai, Wilks, Hotelling-Lawley and Roy); `lda`, `ldaPredict` (linear discriminant analysis); `cancor` (canonical correlation); `dist`, `asDist`, `hclust`, `cutree`, `kmeans` (cluster analysis); `cmdscale` (classical multidimensional scaling); `ca`, `caSummary`, `caCoord` (correspondence analysis); `mjca` (multiple correspondence analysis); `sammon` and `isoMDS` (non-metric multidimensional scaling), from `@numero-uno-jpn/rstats/multivariate` |
|
|
230
230
|
| Mixed models | `lmer` (lme4: REML and ML, correlated and uncorrelated random effects, crossed and nested grouping factors; `fixef`, `vcov`, `VarCorr`, `ranef`, `logLik`, `AIC`, `BIC`, `REMLcrit`, `isSingular`), `lmerSummary`, `lmerContest` and `lmerAnova` (lmerTest: Satterthwaite's t- and F-tests, Type I/II/III ANOVA tables; likelihood-ratio comparison of fits), `glmer` (lme4: all glm families, Laplace approximation and adaptive Gauss-Hermite quadrature), `glmerSummary`, `glmerAnova`, `glmerPredict`, `lmerPredict`, `confintLmer`, `confintGlmer`, `simulateLmer` and
|
|
231
231
|
`simulateGlmer`, from `@numero-uno-jpn/rstats/mixed` |
|
|
@@ -300,8 +300,8 @@ removed. Approximate sizes after minification and gzip:
|
|
|
300
300
|
| `glm` and `glmSummary` / `glm` with all its methods | 40.6 / 56.9 KB |
|
|
301
301
|
| `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 19.4 / 70.0 KB |
|
|
302
302
|
| `glmer` (from `/mixed`) / with `glmerSummary`, `glmerAnova`, `glmerPredict` | 47.2 / 66.1 KB |
|
|
303
|
-
| `polr` / `rlm` / `nls` (from `/regression`) |
|
|
304
|
-
| everything (except `/mixed` and `/regression`) |
|
|
303
|
+
| `polr` / `rlm` / `nls` (from `/regression`) | 25.0 / 14.6 / 8.0 KB |
|
|
304
|
+
| everything (except `/mixed` and `/regression`) | 334.0 KB |
|
|
305
305
|
|
|
306
306
|
(`npm run size` measures these.)
|
|
307
307
|
|
|
@@ -312,11 +312,11 @@ Each area is also a subpath export, for importing one area without the rest:
|
|
|
312
312
|
areas are only available this way, not from the main entry point.
|
|
313
313
|
|
|
314
314
|
Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
|
|
315
|
-
function except those of `/mixed` and `/regression`,
|
|
315
|
+
function except those of `/mixed` and `/regression`, 334 KB gzipped) from jsDelivr, which serves each npm release:
|
|
316
316
|
|
|
317
317
|
```html
|
|
318
318
|
<script type="module">
|
|
319
|
-
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.
|
|
319
|
+
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.17.0/dist/rstats.js";
|
|
320
320
|
console.log(pnorm(1.96)); // ≈ 0.9750021049
|
|
321
321
|
</script>
|
|
322
322
|
```
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type LmFormulaResult } from "../models/lm.js";
|
|
2
|
+
import { type GlmFormulaResult } from "../models/glm.js";
|
|
3
|
+
import type { DataFrame } from "../models/modelFrame.js";
|
|
4
|
+
/**
|
|
5
|
+
* A model for {@link mediate}: a formula fit of {@link lm}, or of {@link glm} with the binomial family and the logit or
|
|
6
|
+
* probit link.
|
|
7
|
+
*
|
|
8
|
+
* @category Causal inference
|
|
9
|
+
*/
|
|
10
|
+
export type MediationModel = LmFormulaResult | GlmFormulaResult;
|
|
11
|
+
/**
|
|
12
|
+
* Options for {@link mediate}.
|
|
13
|
+
*
|
|
14
|
+
* @category Causal inference
|
|
15
|
+
*/
|
|
16
|
+
export interface MediateOptions {
|
|
17
|
+
/** The treatment: a numeric variable of both models. */
|
|
18
|
+
treat: string;
|
|
19
|
+
/** The mediator: the mediator model's response and a numeric variable of the outcome model. */
|
|
20
|
+
mediator: string;
|
|
21
|
+
/** The treatment's value for the treated condition (default 1). */
|
|
22
|
+
treatValue?: number;
|
|
23
|
+
/** The treatment's value for the control condition (default 0). */
|
|
24
|
+
controlValue?: number;
|
|
25
|
+
/** Covariates held at the given values in every observation's prediction (R's `covariates`); numeric variables. */
|
|
26
|
+
covariates?: Record<string, number>;
|
|
27
|
+
/** Number of simulations or bootstrap replicates (default 1000). */
|
|
28
|
+
sims?: number;
|
|
29
|
+
/** Nonparametric bootstrap instead of the quasi-Bayesian approximation (default `false`). */
|
|
30
|
+
boot?: boolean;
|
|
31
|
+
/** The bootstrap intervals: `"perc"` (percentile, the default) or `"bca"` (bias-corrected and accelerated). */
|
|
32
|
+
bootCiType?: "perc" | "bca";
|
|
33
|
+
/** Confidence level of the intervals (default 0.95). */
|
|
34
|
+
confLevel?: number;
|
|
35
|
+
/** Heteroskedasticity-consistent (HC3) covariances for the quasi-Bayesian draws (default `false`). */
|
|
36
|
+
robustSE?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One effect of {@link mediate}: its estimate, interval, p-value and draws.
|
|
40
|
+
*
|
|
41
|
+
* @category Causal inference
|
|
42
|
+
*/
|
|
43
|
+
export interface MediateEffect {
|
|
44
|
+
/** The estimate (R's `d0`, `z0`, `tau.coef`, ...). */
|
|
45
|
+
estimate: number;
|
|
46
|
+
/** The confidence interval (R's `d0.ci`, ...). */
|
|
47
|
+
ci: [number, number];
|
|
48
|
+
/** The two-sided p-value, `2 min(mean(draws > 0), mean(draws < 0))` (R's `d0.p`, ...). */
|
|
49
|
+
p: number;
|
|
50
|
+
/** The simulation or bootstrap draws (R's `d0.sims`, ...). */
|
|
51
|
+
sims: number[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Result of {@link mediate}. `d` are the average causal mediation effects (ACME), `z` the average direct effects (ADE),
|
|
55
|
+
* `n` the proportions mediated, `0` under control and `1` under treatment.
|
|
56
|
+
*
|
|
57
|
+
* @category Causal inference
|
|
58
|
+
*/
|
|
59
|
+
export interface MediateResult {
|
|
60
|
+
/** ACME under control: the mean of Y(t0, M(t1)) − Y(t0, M(t0)). */
|
|
61
|
+
d0: MediateEffect;
|
|
62
|
+
/** ACME under treatment: the mean of Y(t1, M(t1)) − Y(t1, M(t0)). */
|
|
63
|
+
d1: MediateEffect;
|
|
64
|
+
/** ADE under control: the mean of Y(t1, M(t0)) − Y(t0, M(t0)). */
|
|
65
|
+
z0: MediateEffect;
|
|
66
|
+
/** ADE under treatment: the mean of Y(t1, M(t1)) − Y(t0, M(t1)). */
|
|
67
|
+
z1: MediateEffect;
|
|
68
|
+
/** The total effect: the mean of Y(t1, M(t1)) − Y(t0, M(t0)). */
|
|
69
|
+
tau: MediateEffect;
|
|
70
|
+
/** Proportion mediated under control, d0 / tau. */
|
|
71
|
+
n0: MediateEffect;
|
|
72
|
+
/** Proportion mediated under treatment, d1 / tau. */
|
|
73
|
+
n1: MediateEffect;
|
|
74
|
+
/** The average ACME, (d0 + d1) / 2. */
|
|
75
|
+
dAvg: MediateEffect;
|
|
76
|
+
/** The average ADE, (z0 + z1) / 2. */
|
|
77
|
+
zAvg: MediateEffect;
|
|
78
|
+
/** The average proportion mediated, (n0 + n1) / 2. */
|
|
79
|
+
nAvg: MediateEffect;
|
|
80
|
+
/** The treated value used. */
|
|
81
|
+
treatValue: number;
|
|
82
|
+
/** The control value used. */
|
|
83
|
+
controlValue: number;
|
|
84
|
+
/** Number of observations. */
|
|
85
|
+
nobs: number;
|
|
86
|
+
/** Number of simulations or replicates. */
|
|
87
|
+
sims: number;
|
|
88
|
+
/** Whether the bootstrap was used. */
|
|
89
|
+
boot: boolean;
|
|
90
|
+
/** The bootstrap interval type. */
|
|
91
|
+
bootCiType: "perc" | "bca";
|
|
92
|
+
/** The confidence level. */
|
|
93
|
+
confLevel: number;
|
|
94
|
+
/** Whether HC3 covariances were used (false with the bootstrap, which ignores them). */
|
|
95
|
+
robustSE: boolean;
|
|
96
|
+
/** Whether the outcome model has an interaction of the treatment and the mediator (R's `INT`). */
|
|
97
|
+
INT: boolean;
|
|
98
|
+
/** R's warnings. */
|
|
99
|
+
warnings: string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Causal mediation analysis for linear and binomial (logit or probit) mediator and outcome models. Equivalent to
|
|
103
|
+
* `mediation::mediate()` in R.
|
|
104
|
+
*
|
|
105
|
+
* The average causal mediation effects (ACME, `d0` and `d1`), the average direct effects (ADE, `z0` and `z1`), the total
|
|
106
|
+
* effect (`tau`) and the proportions mediated (`n0`, `n1`) with their averages, by the quasi-Bayesian Monte Carlo
|
|
107
|
+
* approximation (the default) or the nonparametric bootstrap (`boot: true`), as in Imai, Keele and Tingley (2010).
|
|
108
|
+
* With the same {@link setSeed} the draws, estimates, intervals and p-values equal R's: the parameters are drawn with
|
|
109
|
+
* the symmetric square root of their covariance, then the mediator for every simulation and observation (normal errors
|
|
110
|
+
* with the residual standard error for a linear mediator, binomial draws for a binary one).
|
|
111
|
+
*
|
|
112
|
+
* Quasi-Bayesian estimates are the means of the draws (the proportions mediated: their medians; `nAvg` the average of
|
|
113
|
+
* the two medians); bootstrap estimates come from a final draw on the original data, after the replicates, as in R.
|
|
114
|
+
* Intervals are quantiles of type 7 of the draws (with `bootCiType: "bca"`: the bias-corrected and accelerated levels,
|
|
115
|
+
* the bias measured against the draws' mean and the acceleration from their skewness, as R).
|
|
116
|
+
*
|
|
117
|
+
* The models must be formula fits of {@link lm} or {@link glm} (binomial with logit or probit, or gaussian) on `data`,
|
|
118
|
+
* on the same rows, without weights or offsets; the treatment and the mediator are numeric variables.
|
|
119
|
+
*
|
|
120
|
+
* @param modelM The mediator model (its response is the mediator).
|
|
121
|
+
* @param modelY The outcome model (it includes the treatment and the mediator).
|
|
122
|
+
* @param data The data both models were fitted on.
|
|
123
|
+
* @param options See {@link MediateOptions}; `treat` and `mediator` are required.
|
|
124
|
+
* @returns See {@link MediateResult}.
|
|
125
|
+
* @throws TypeError or RangeError for unsupported models, data that do not reproduce the fits, a treatment or mediator
|
|
126
|
+
* that is not a numeric variable of the models, models on different rows, `sims` below 2, or
|
|
127
|
+
* `confLevel` outside (0, 1).
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const data = {
|
|
132
|
+
* X: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], C: [1.2, -0.4, 0.3, 0.8, -1.1, 0.5, -0.2, 1.4, -0.7, 0.1],
|
|
133
|
+
* M: [1.1, 0.4, 0.9, 1.6, 0.2, 1.9, 1.3, 2.6, 1.0, 1.8], Y: [2.0, 1.1, 1.5, 2.4, 0.8, 3.1, 2.2, 3.9, 1.9, 2.8],
|
|
134
|
+
* W: [3.1, 2.2, 4.0, 2.8, 3.5, 2.9, 3.8, 2.4, 3.3, 4.2],
|
|
135
|
+
* };
|
|
136
|
+
* const m = lm("M ~ X + C", data), y = lm("Y ~ X + M + C", data);
|
|
137
|
+
* setSeed(1234);
|
|
138
|
+
* const r = mediate(m, y, data, { treat: "X", mediator: "M", sims: 500 });
|
|
139
|
+
* r.d0.estimate; // 0.8851 (R: set.seed(1234); mediate(m, y, treat = "X", mediator = "M", sims = 500)$d0)
|
|
140
|
+
* r.d0.ci; // [0.5261, 1.3011]
|
|
141
|
+
* r.n0.estimate; // 0.7432
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @category Causal inference
|
|
145
|
+
*/
|
|
146
|
+
export declare function mediate(modelM: MediationModel, modelY: MediationModel, data: DataFrame, options: MediateOptions): MediateResult;
|