betaFeedback

WorksMathematics

One-Sample Mendelian Randomization and Instrumental Variable Analyses in R and Stata: The OneSampleMR and ivonesamplemr Packages

Abstract

Mendelian randomization (MR) uses genetic variants as instrumental variables (IVs) to estimate the causal effect of an exposure on an outcome. When individual-level data on the instruments, exposure, and outcome are available in a single sample (one-sample MR), a range of IV estimators can be used beyond the standard two-stage least squares estimator, including structural mean models (SMMs) and two-stage predictor substitu- tion (TSPS) and two-stage residual inclusion (TSRI) estimators with nonlinear second stage models. These estimators are important when the outcome is binary, where in- vestigators typically wish to report causal risk ratios or causal odds ratios. However, implementations of these estimators are scattered across software packages and are of- ten unavailable with standard errors that account for the estimation of the first stage. We describe two packages which implement these estimators: OneSampleMR for R and ivonesamplemr for Stata. Both packages fit the multiplicative and logistic SMMs and TSPS and TSRI estimators with identity, log-additive, log-multiplicative, and logit links using the generalized method of moments (GMM), so that the standard errors account for the uncertainty in both stages of estimation. OneSampleMR additionally provides the Sanderson-Windmeijer conditional F-statistic for assessing instrument strength in models with multiple exposures, and ivonesamplemr additionally provides prefix commands for moving window and within-quantile estimation for exploring nonlinear exposure-outcome relationships. We illustrate both packages using the same simulated dataset and show that they give the same estimates as each other and as existing implementations.

Introduction

Mendelian randomization (MR) is an approach to estimating the causal effect of a modifiable exposure on an outcome using genetic variants as instrumental variables (IVs) [9, 20, 11, 30]. Because genotypes are allocated at gamete cell formation and then conception, they are expected to be largely independent of the environmental and behavioral factors that commonly confound observational associations. Under the IV assumptions, described in § 2, the association of the genetic variants with the outcome can be used to make inferences about the causal effect of the exposure on the outcome.

MR analyses are conducted in one of two designs. In two-sample MR, the gene-exposure and gene-outcome associations are estimated in different samples and only summary statistics are required. Software for two-sample MR is plentiful, for example the R packages MendelianRandomization ([41]) and TwoSampleMR ([16]), and the Stata package mrrobust ([33]). In one-sample MR, individual-level data on the genetic variants, exposure, and outcome are available for the same participants, for example in a cohort study or biobank. This design permits the use of the full range of IV estimators developed in biostatistics and econometrics.

For a continuous outcome, the standard one-sample analysis is linear IV estimation, such as two-stage least squares (2SLS), which is widely available. However, many outcomes in epidemiology are binary, such as disease status, and investigators usually wish to report a causal risk ratio or a causal odds ratio rather than a causal risk difference. Several estimators have been proposed for this setting ([26, 10]). These include the multiplicative structural mean model (MSMM; [28, 29, 17]), which estimates a causal risk ratio, the logistic structural mean model (LSMM; [39, 38]), which estimates a causal odds ratio, and two-stage predictor substitution (TSPS) and two-stage residual inclusion (TSRI) estimators ([37]) with nonlinear second stage models. Clarke, Palmer, and Windmeijer [7] showed how SMMs can be estimated with multiple instruments using the generalized method of moments (GMM; [15]). When there are more instruments than exposures, GMM also provides a test of the overidentifying restrictions, which can detect some violations of the independence and exclusion restriction assumptions (§ 2) only insofar as they cause the instruments to disagree about the causal effect. GMM estimation of TSPS and TSRI estimators, in which the first and second stage estimating equations are stacked, gives standard errors which correctly account for the estimation of the first stage, which naive two-step estimation does not.

In addition, assessing the strength of the instruments is an important part of any IV analysis because weak instruments bias IV estimators towards the confounded observational association. With a single exposure, the first stage FF-statistic is typically reported ([36]). With multiple endogenous exposures, as in multivariable MR, the individual first stage FF-statistics are not informative about whether each exposure is separately identified, and the conditional FF-statistic of Sanderson and Windmeijer [31] should be used instead.

Implementations of these methods exist but are scattered. In R ([27]), linear IV estimation is available in ivreg ([13]), AER ([19]), estimatr ([8]), and fixest ([2]). The ivtools package ([32]) provides G-estimation of SMMs and two-stage estimators, along with methods for survival outcomes and nonparametric bounds. A user can also code the relevant moment conditions themselves using the gmm package ([6]). In Stata ([35]), the official ivpoisson command ([34]) fits an estimator that is equivalent to the MSMM (Mullahy 1997; Windmeijer and Santos Silva [40]; Palmer et al. [26]), as does the earlier community-contributed ivpois (Nichols [23]), and ivreg2 (Baum, Schaffer, and Stillman [1]) reports Sanderson-Windmeijer FF-statistics. However, as far as we are aware, there is no other software that fits TSPS and TSRI estimators with log-multiplicative second stage models, nor any package that provides the same set of one-sample MR estimators with the same parameterizations in both R and Stata. Moreover, the existing implementations are spread across packages with different interfaces and terminology, several of which require the user to fit and combine component models. Having the main one-sample estimators in one place, with a common interface and documentation aimed at MR analysts, in the way that TwoSampleMR and MendelianRandomization do for two-sample MR, makes them easier to apply and to compare.

In this article we describe two packages that fill this gap. OneSampleMR (Palmer, Spiller, Sanderson, and Vitt [25]) is an R package available from the Comprehensive R Archive Network (CRAN) at https://CRAN.R-project.org/package=OneSampleMR. ivonesamplemr (Palmer [24]) is a Stata package available from its GitHub repository, https://github.com/remlapmot/ivonesamplemr, which is set up as a Stata user site so that the package can be installed with net install. Both are released under the GNU General Public License version 3. The packages were developed in parallel so that analysts who work in either language, or collaborators who work in different languages, can fit the same models and obtain the same results. The Stata package has been used in applied MR analyses, for example Madley-Dowd, Dardani, Wootton, Dack, Palmer, Thurston, Havdahl, Golding, Lawlor, and Rai [21].

The rest of the article is organized as follows. § 2 describes the models and estimators. § 3 compares the packages with existing software. § 4 describes the simulated dataset used in the illustrations. § 5 and § 6 illustrate OneSampleMR and ivonesamplemr, respectively. § 7 compares the estimates across implementations, and § 8 concludes with a discussion.

Models and estimators

Notation and assumptions

Let YY denote the outcome, XX the exposure (or a vector of KK exposures), which is endogenous, ZZ a vector of LL instruments (typically genotypes coded as the number of effect alleles, or genetic risk scores combining several variants), WW a vector of measured covariates, and UU the unmeasured confounders of the exposure-outcome relationship. Let Y(x)Y(x) denote the potential outcome that would be observed if the exposure were set to xx, so that Y(0)Y(0) is the exposure-free potential outcome. The instruments must satisfy three core IV assumptions (Didelez and Sheehan [11]; Hernán and Robins [17]):

IV1. Relevance: ZZ is associated with XX.

IV2. Independence: ZZ is independent of UU (conditional on WW).

IV3. Exclusion restriction: ZZ is independent of YY given XX, UU (and WW), that is, ZZ affects YY only through XX.

These assumptions alone do not point identify the causal effect, and each estimator below makes an additional structural or parametric assumption, such as no effect modification of the causal effect by the instruments.

Structural mean models

SMMs ([28, 29]) specify a model for the contrast between the mean of the observed outcome and the mean of the exposure-free potential outcome among those with the same exposure and instrument values.

The additive SMM (ASMM) is

E⁡(Y∣X,Z)−E⁡{Y(0)∣X,Z}=ψX.\operatorname{E}(Y \mid X,Z) - \operatorname{E}\{Y(0) \mid X,Z\} = \psi X.

Under the IV assumptions, Y−ψXY-\psi X is mean independent of ZZ, which gives the estimating equations E⁡{(1,ZT)T(Y−β0−ψX)}=0\operatorname{E}\{(1,Z^{\mathsf{T}})^{\mathsf{T}}(Y-\beta_0-\psi X)\}=0, where β0=E⁡{Y(0)}\beta_0=\operatorname{E}\{Y(0)\}. These are the estimating equations of linear IV estimators, and so the ASMM is fit by 2SLS or linear GMM. For a binary outcome, ψ\psi is a causal risk difference.

The multiplicative SMM (MSMM) is

log⁡E⁡(Y∣X,Z)−log⁡E⁡{Y(0)∣X,Z}=ψX.\log\operatorname{E}(Y \mid X,Z) - \log\operatorname{E}\{Y(0) \mid X,Z\} = \psi X.

so that exp⁡(ψ)\exp(\psi) is a causal risk ratio for a binary outcome. Under the IV assumptions Yexp⁡(−ψX)Y\exp(-\psi X) is mean independent of ZZ, giving the moment conditions

E⁡[(1,ZT)T{Yexp⁡(−ψX)−β0}]=0,(1)\operatorname{E}\left[(1,Z^{\mathsf{T}})^{\mathsf{T}}\{Y\exp(-\psi X)-\beta_0\}\right]=0, \tag*{(1)}

where again β0=E⁡{Y(0)}\beta_0=\operatorname{E}\{Y(0)\}. Clarke et al. [7] described GMM estimation of (1) with multiple instruments, and an alternative parameterization,

E⁡[(1,ZT)T{Yexp⁡(−β0∗−ψX)−1}]=0,(2)\operatorname{E}\left[(1,Z^{\mathsf{T}})^{\mathsf{T}}\{Y\exp(-\beta_0^*-\psi X)-1\}\right]=0, \tag*{(2)}

which gives the same moment conditions as the estimator of Mullahy [22] implemented in Stata’s ivpoisson command with the multiplicative option. Here exp⁡(β0∗)=E⁡{Y(0)}\exp(\beta_0^*)=\operatorname{E}\{Y(0)\}. Dukes and Vansteelandt [12] noted that these moment conditions are equivalent to those of a gamma regression. When XX and YY are binary, Clarke et al. [7] also showed that the MSMM can be fitted with 2SLS using transformed variables.

The logistic SMM (LSMM) is

logit⁡E⁡(Y∣X,Z)−logit⁡E⁡{Y(0)∣X,Z}=ψX.\operatorname{logit}\operatorname{E}(Y \mid X,Z) - \operatorname{logit}\operatorname{E}\{Y(0) \mid X,Z\} = \psi X.

so that exp⁡(ψ)\exp(\psi) is a causal odds ratio among the exposed. Unlike the ASMM and MSMM, the LSMM is not identified from the IV assumptions alone; it also requires a model for the observed outcome mean, the so-called association model, for example logit⁡E⁡(Y∣X,Z)=αT(1,X,ZT)T\operatorname{logit}\operatorname{E}(Y \mid X,Z)=\alpha^{\mathsf{T}}(1,X,Z^{\mathsf{T}})^{\mathsf{T}}. The double logistic SMM of Vansteelandt and Goetghebeur [39] jointly fits the association model and the causal model. With multiple instruments the estimating equations can again be solved by GMM ([7]).

When there are more instruments than exposures, L>KL>K, the SMMs are overidentified, and Hansen’s JJ-statistic tests the overidentifying restrictions, that is, whether the moment conditions implied by the different instruments are compatible with each other ([15]).

Under the null hypothesis that all the instruments are valid, JJ has an asymptotic χ2\chi^2 distribution with L−KL-K degrees of freedom. Rejection indicates that at least one instrument violates the independence or exclusion restriction assumptions, or that the model is misspecified, for example because the causal effect differs between subgroups defined by the instruments. The test has low power when all the instruments are invalid in a similar way, so a nonsignificant JJ-statistic does not establish that the instruments are valid.

Two-stage predictor substitution and residual inclusion

TSPS and TSRI estimators (Terza et al. [37]) proceed by fitting a first stage linear regression of the exposure on the instruments and covariates,

X=α0+αZ⊤Z+αW⊤W+e.X = \alpha_0 + \alpha_Z^\top Z + \alpha_W^\top W + e.

TSPS then fits a second stage model, with link function gg, of the outcome on the fitted values from the first stage, X^\hat{X},

g{E(Y∣X^,W)}=β0+βXX^+βW⊤W.g\{\mathrm{E}(Y \mid\hat{X}, W)\} = \beta_0 + \beta_X\hat{X} + \beta_W^\top W.

while TSRI fits the second stage model of the outcome on the exposure and the first stage residuals, e^=X−X^\hat{e}=X-\hat{X},

g{E(Y∣X,e^,W)}=β0+βXX+βee^+βW⊤W.g\{\mathrm{E}(Y \mid X,\hat{e},W)\} = \beta_0 + \beta_X X + \beta_e\hat{e} + \beta_W^\top W.

TSRI is a special case of a control function estimator. Both OneSampleMR and ivonesamplemr offer four link functions for the second stage model:

  • identity: linear regression, with second stage residual Y−ηY-\eta, where η\eta is the second stage linear predictor; βX\beta_X is a causal risk difference for a binary outcome.

  • logadd: log-additive, corresponding to Poisson or log-binomial regression, with residual Y−exp⁡(η)Y-\exp(\eta); exp⁡(βX)\exp(\beta_X) is a causal risk ratio for a binary outcome.

  • logmult: log-multiplicative, corresponding to gamma regression, with residual Yexp⁡(−η)−1Y\exp(-\eta)-1; exp⁡(βX)\exp(\beta_X) is a causal risk ratio for a binary outcome (Dukes and Vansteelandt [12]).

  • logit: logistic regression, with residual Y−logit⁡−1(η)Y-\operatorname{logit}^{-1}(\eta); exp⁡(βX)\exp(\beta_X) is a causal odds ratio for a binary outcome.

In both OneSampleMR and ivonesamplemr the first stage estimating equations, (1,Z⊤,W⊤)⊤e(1,Z^\top,W^\top)^\top e, and the second stage estimating equations, the second stage residual multiplied by the second stage regressors, are stacked and solved jointly by GMM. Any number of instruments can be used, because the instruments enter only the first stage regression. The stacked system therefore always has as many estimating equations as parameters, that is, it is exactly identified, whatever the number of instruments. As a result the point estimates equal those of the sequential two-step procedure, the GMM standard errors account for the uncertainty in the first stage estimates, and, unlike for the SMMs, no overidentification test is available. Both OneSampleMR and ivonesamplemr currently allow only a single exposure in the TSPS and TSRI estimators.

With the identity link, TSPS is numerically identical to 2SLS. With nonlinear links the TSPS and TSRI estimators are consistent for the causal effect only under additional assumptions on the first stage and on the distribution of the unmeasured confounders. In particular, with the logit link, the TSPS and TSRI estimands are generally not the population or exposed causal odds ratio, because of the noncollapsibility of the odds ratio [26, 4, 10]. The log-additive and log-multiplicative links avoid this problem for risk ratios. These estimators therefore complement, rather than replace, the SMMs.

Instrument strength with multiple exposures

In a model with KK exposures and L≥KL \ge K instruments, the Sanderson and Windmeijer [31] conditional FF-statistic for exposure jj tests whether exposure jj is weakly identified given the other exposures. It is computed from a regression of exposure jj on the instruments after partialling out the linear projection of the other exposures on the instruments, and has L−K+1L-K+1 numerator degrees of freedom. When K=1K=1 it reduces to the usual first stage FF-statistic for the excluded instruments. The conditional FF-statistics can be compared with the Stock and Yogo [36] critical values for a single exposure with L−K+1L-K+1 instruments (kz−1k_z-1 instruments in the two-exposure case considered by Sanderson and Windmeijer [31], where kzk_z is the number of instruments).

Nonlinear exposure-outcome relationships

The estimators above assume a linear (on the scale of the link function) exposure-outcome relationship. Burgess, Davies, and Thompson [5] described two approaches to exploring departures from linearity: estimating the causal effect within strata defined by quantiles of the first stage residuals (equivalently, of the IV-free exposure), and a moving (sliding) window approach in which the estimator is applied to successive overlapping windows of participants ordered by the IV-free exposure. Comparing the estimates across strata or windows indicates whether the causal effect varies with the level of the exposure. These approaches are implemented in ivonesamplemr by the ivxtile and ivmw prefix commands (§ 6). They rely on an additional assumption, that the effect of the instruments on the exposure is the same in every stratum or window (the constant genetic effect assumption). When this assumption is violated, for example when the genetic effect on the exposure varies with the level of the exposure, the stratum-specific estimates can be biased and can suggest a nonlinear relationship where none exists ([3, 14]).

Comparison with existing software

Table 1 summarizes the estimators available in OneSampleMR, ivonesamplemr, and related software.

The package with the most overlap with OneSampleMR is ivtools (Sjölander and Martinussen [32]). Its ivglm() function fits two-stage estimators (with the ctrl argument selecting between predictor substitution and residual inclusion) and G-estimators of SMMs with identity, log, and logit links, and ivtools additionally provides IV estimators for survival outcomes and

EstimatorOneSampleMRivtoolsivregivonesamplemrOfficialivreg2
ASMM (linear IV)via ivreg✓✓via ivregress✓✓
MSMM, multiple instruments✓–1–✓✓2–
LSMM✓✓–✓––
TSPS, identity/log/logit link✓✓–✓––
TSPS, log-multiplicative link✓––✓––
TSRI, identity/log/logit link✓✓–✓––
TSRI, log-multiplicative link✓––✓––
Sanderson-Windmeijer FF✓––via ivreg2–✓
Overidentification test✓–✓✓✓✓
Moving window / quantiles–––✓––

caption: Estimators available in OneSampleMR, ivonesamplemr, and related software. 1 2

nonparametric bounds. Its interface requires the user to fit and supply the component models, for example a model for the instrument for G-estimation. In contrast, OneSampleMR uses the three-part formula interface, y ~ x + w | z + w, of ivreg() from ivreg and AER, fits the MSMM and LSMM with multiple instruments by GMM with an overidentification test, offers the log-multiplicative link for TSPS and TSRI, and computes the Sanderson-Windmeijer conditional FF-statistic for IV models fitted by ivreg, AER, estimatr, and fixest. This makes OneSampleMR simple to use, because each model is specified in a single function call in the same way as a linear IV model, rather than by fitting and combining several component models.

In Stata, ivmsmm is a wrapper for ivpoisson gmm with the multiplicative option, and so adds the interpretation of this estimator as an MSMM and exponentiated output rather than new functionality. The remaining ivonesamplemr commands, ivlsmm, ivtsps, ivtsri, ivmw, and ivxtile, provide estimators that are not otherwise available in official Stata or, to our knowledge, in other community-contributed packages, other than via user-written moment conditions for Stata’s gmm command.

The most distinctive feature of the two packages is that they share estimators, parameterizations, and link function names, so that the same analysis can be reproduced in either language. We demonstrate this in § 7. In addition, both packages build on the syntax of the most widely used linear IV commands, ivreg() in R and ivregress in Stata, so users who are familiar with linear IV estimation can fit the other estimators by changing only the function or command name and, for TSPS and TSRI, the link function. Table 2 lists the estimators and the corresponding R functions and Stata commands.

EstimatorDescriptionOneSampleMRivonesamplemr
Additive SMM (ASMM)Linear IV estimator; causal risk difference for a binary outcomeivreg() from ivreg (see ?asmm)ivregress or ivreg2 (see help ivasmm)
Multiplicative SMM (MSMM)Causal risk ratiomsmm()ivmsmm
Logistic SMM (LSMM)Causal odds ratio among the exposedlsmm()ivlsmm
Two-stage predictor substitution (TSPS)Second stage on the predicted exposure, with identity, logadd, logmult, or logit linktsps()ivtsps
Two-stage residual inclusion (TSRI)Second stage on the exposure and first stage residuals, with the same links as TSPStsri()ivtsri
Sanderson-Windmeijer conditional FF-statisticInstrument strength with multiple exposuresfsw()ivreg2, first
Within-quantile estimationAny of the above within quantiles of the first stage residuals–ivxtile:
Moving window estimationAny of the above within moving windows of the first stage residuals–ivmw:

Table 2. Estimators and the corresponding functions in OneSampleMR and commands in ivonesamplemr.

Simulated example data

Individual-level data from MR studies, such as UK Biobank or birth cohort studies, generally cannot be shared publicly. We therefore illustrate the packages using a simulated dataset of n=10,000n = 10{,}000 participants, generated by the replication script code.R and saved as mrdata.csv so that exactly the same data are analyzed in R and Stata. There are three instruments, z1, z2z_2, and z3z_3, which mimic single nucleotide polymorphisms coded 0, 1, 2; a binary measured confounder, ww, which affects both the exposures and the outcomes; an unmeasured confounder, U∼Uniform⁡(0,1)U \sim\operatorname{Uniform}(0,1); two continuous exposures, xx and x2x_2; a binary outcome, yy; and a continuous outcome, ycy_c. In the data generating model these variables are denoted by the corresponding capital letters, for example Z1Z_1 for z1z_1 and YcY_c for ycy_c:

Z1∼Bin⁡(2,0.30),Z2∼Bin⁡(2,0.25),Z3∼Bin⁡(2,0.40),W∼Bernoulli⁡(0.5),U∼Uniform⁡(0,1),X=0.5Z1+0.4Z2+0.3Z3+0.5W+U+ε1,X2=0.4Z1+0.1Z2+0.3Z3+0.3W+U+ε2,Pr⁡(Y=1∣X,W,U)=exp⁡{−3+log⁡(1.3)X+U+0.3W},Yc=0.5X+0.3X2+W+U+ε3,\begin{aligned} Z_1 &\sim\operatorname{Bin}(2, 0.30), \quad Z_2 \sim\operatorname{Bin}(2, 0.25), \quad Z_3 \sim\operatorname{Bin}(2, 0.40), \\ W &\sim\operatorname{Bernoulli}(0.5), \quad U \sim\operatorname{Uniform}(0, 1), \\ X &= 0.5Z_1 + 0.4Z_2 + 0.3Z_3 + 0.5W + U + \varepsilon_1, \\ X_2 &= 0.4Z_1 + 0.1Z_2 + 0.3Z_3 + 0.3W + U + \varepsilon_2, \\ \Pr(Y = 1 \mid X, W, U) &= \exp\{-3 + \log(1.3)X + U + 0.3W\}, \\ Y_c &= 0.5X + 0.3X_2 + W + U + \varepsilon_3, \end{aligned}

where ε1,ε2,ε3\varepsilon_1,\varepsilon_2,\varepsilon_3 are independent standard normal errors. The binary outcome follows a log-linear model with no effect modification of the exposure effect by the instruments, so that the MSMM is correctly specified with a true causal risk ratio of 1.3 per unit increase in xx. The continuous outcome has causal effects of 0.5 and 0.3 of xx and x2x_2, respectively. About 16% of participants have Y=1Y = 1. In R, the first three rows of the simulated data are:

R> library("OneSampleMR")
R> library("ivreg")
R> mrdata <- read.csv("mrdata.csv")
R> head(mrdata, 3)
yycxx2wz1z2z3
100.5190.10121.17261010
202.4751.22010.43291110
301.8661.73310.88430200

The OneSampleMR package for R

OneSampleMR can be installed from CRAN and loaded with

R> install.packages("OneSampleMR")
R> library("OneSampleMR")

The package exports five functions, msmm(), lsmm(), tsps(), tsri(), and fsw(), together with print() and summary() methods for their results. It imports gmm [6] for GMM estimation, ivreg [13] for 2SLS, Formula [42] for multi-part formulas, lmtest [43] for the Wald tests in fsw(), and msm [18] for delta method standard errors.

The estimation functions share the interface of ivreg() from ivreg. Models are specified with a three-part formula, y ~ x + w | z1 + z2 + z3 + w, in which the first part is the outcome, the second part lists the exposure and any covariates, and the third part lists the instruments and the same covariates. Variables appearing in both the second and third parts are treated as exogenous covariates, and causal effect estimates are only reported for the exposures. The functions also accept the data, subset, na.action, and contrasts arguments of ivreg(), and starting values for the GMM optimizer can be supplied with t0.

Additive structural mean model

As described in § 2, the ASMM is fitted by any linear IV estimator, and so OneSampleMR does not provide a separate function; its ?asmm help page directs users to ivreg(). For the binary outcome, the estimated causal risk difference per unit increase in x is 0.035 (95% confidence interval, CI, 0.019 to 0.051).

R> fit_asmm <- ivreg(y ~ x + w | z1 + z2 + z3 + w, data = mrdata)
R> summary(fit_asmm, diagnostics = TRUE)$diagnostics
df1df2statisticp-value
Weak instruments39995630.19970.00000
Wu-Hausman199965.52710.01874
Sargan2NA0.75910.68417

The first stage FF-statistic of 630 indicates strong instruments.

Multiplicative structural mean model

msmm() fits the MSMM. Its estmethod argument selects between GMM estimation of moment conditions (1) ("gmm", the default), GMM estimation of the alternative moment conditions (2) ("gmmalt"), and, for binary XX and YY, the two 2SLS approaches of Clarke et al. [7] ("tsls" and "tslsalt"). The outcome must be a nonnegative integer, so that msmm() can be used for binary and count outcomes. Multiple exposures are permitted with the GMM methods.

R> fit_msmm <- msmm(y ~ x | z1 + z2 + z3, data = mrdata)
R> fit_msmm

Estimation method: gmm

Method
    twoStep

Objective function value:  0.00015

Theta[1]  Theta[2]
 0.10947   0.21181

Convergence code =  0

E[Y(0)] with 95% CI:
       0.025 0.975
0.109  0.090 0.129

Causal risk ratio with 95% CI:
    CRR  0.025  0.975
x  1.24   1.12  1.37

The estimated causal risk ratio is 1.24 (95% CI 1.12 to 1.37), consistent with the true value of 1.3. The first parameter is the estimated mean exposure-free potential outcome, E{Y(0)}E\{Y(0)\}. The summary() method additionally prints the gmm coefficient table and the Hansen JJ-test of the overidentifying restrictions, which here is 1.50 on 2 degrees of freedom (p=0.47p = 0.47), giving no evidence against the validity of the instruments.

Covariates are adjusted for by including them in both parts of the formula. This corresponds to a log-linear model for the exposure-free potential outcome mean in the covariates, and is the same model as fitted by ivpoisson in Stata with exogenous covariates. Here we use the alternative moment conditions and adjust for ww.

R> fit_msmm_alt <- msmm(y ~ x + w | z1 + z2 + z3 + w, data = mrdata,
+   estmethod = "gmmalt")
R> fit_msmm_alt

Estimation method: gmmalt

Method
    twoStep
Objective function value: 0.0001872

Theta[1]  Theta[2]  Theta[3]
-2.35342   0.20110   0.29947

Convergence code = 0

E[Y(0)] when the covariates are 0 with 95% CI:
           0.025  0.975
0.0950  0.0802 0.1126

Causal risk ratio with 95% CI:
    CRR  0.025  0.975
x  1.22    1.1   1.36

Adjusted for: w

The causal risk ratio is only reported for the exposure, and E{Y(0)}E\{Y(0)\} is now estimated at covariate values of 0.

Logistic structural mean model

lsmm() fits the double logistic SMM by two-step GMM. The association model is a logistic regression of the outcome on the exposures, instruments, and covariates, and the association and causal model moment conditions are fitted jointly, using the same initial weight matrix, optimal weight matrix, and starting values as ivlsmm in ivonesamplemr. Covariates are included in both the association model and the causal model.

R> fit_lsmm <- lsmm(y ~ x + w | z1 + z2 + z3 + w, data = mrdata)
R> fit_lsmm

Method
twoStep

Objective function value:  7.2e-05

assoc:(Intercept)          assoc:x             assoc:z1
       -2.402243            0.426996            -0.080224
       assoc:z2             assoc:z3             assoc:w
       -0.062534           -0.051071             0.290310
              x                    w                E[Y(0)]
        0.265207             0.362480             0.090613

Convergence code = 0

E[Y(0)] when the covariates are 0 with 95% CI:
           0.025  0.975

0.0906 0.0748 0.1065

Causal odds ratio with 95% CI: COR 0.025 0.975 x 1.3 1.16 1.47

Adjusted for: w

The parameters prefixed assoc: belong to the association model, and the coefficient of x in the causal model gives a causal odds ratio among the exposed of 1.30 (95% CI 1.16 to 1.47). The summary() method reports the Hansen JJ-test, here 0.72 on 2 degrees of freedom (pp = 0.70).

Two-stage predictor substitution

tsps() fits TSPS estimators, with the second stage link function chosen by the link argument, one of "identity" (the default), "logadd", "logmult", and "logit". Here we adjust for the covariate w in both stages and estimate a causal risk ratio with the log-additive link.

R> fit_tsps <- tsps(y ~ x + w | z1 + z2 + z3 + w, data = mrdata,
+     link = "logadd")
R> fit_tsps
Second stage model link function: logadd

Method
  twoStep

Objective function value: 1.905e-27

stage1:(Intercept)             stage1:z1             stage1:z2
        0.52301                0.49345                0.38829
stage1:z3                       stage1:w             (Intercept)
        0.31523                0.44639               -2.32105
                                     x                    w
                                  0.21540              0.29672

Convergence code = 0

Estimates with 95% CI limits:
                         Estimate  0.025  0.975
stage1:(Intercept)          0.523  0.478  0.568
stage1:z1                   0.493  0.462  0.525
stage1:z2                   0.388  0.355  0.422
stage1:z3                   0.315  0.286  0.345
stage1:w                    0.446  0.406  0.487
(Intercept)                -2.321 -2.467 -2.175
x             0.215  0.119  0.312
w             0.297  0.197  0.397

Causal risk ratio with 95% CI limits:
    Estimate 0.025 0.975
x      1.24  1.13  1.37

The output reports all the parameters of the stacked GMM model. The parameters prefixed stage1: are the first stage coefficients and the remaining parameters are the second stage coefficients. Only the coefficient of the exposure is exponentiated, giving an estimated causal risk ratio of 1.24 (95% CI 1.13 to 1.37).

Two-stage residual inclusion

tsri() has the same arguments as tsps(). Here we estimate a causal odds ratio using the logit link.

R> fit_tsri <- tsri(y ~ x + w | z1 + z2 + z3 + w, data = mrdata,
+   link = "logit")
R> fit_tsri
Second stage model link function: logit

Method
  twoStep

Objective function value:  1.04e-18

stage1:(Intercept)          stage1:z1          stage1:z2
         0.52301             0.49345             0.38829
        stage1:z3             stage1:w          (Intercept)
         0.31523             0.44639            -2.31417
                 x    stage1:residuals                   w
         0.26327             0.16315             0.36263

Convergence code =  0

Estimates with 95% CI limits:
                         Estimate  0.025  0.975
stage1:(Intercept)          0.523  0.4779  0.568
stage1:z1                   0.493  0.4619  0.525
stage1:z2                   0.388  0.3550  0.422
stage1:z3                   0.315  0.2856  0.345
stage1:w                    0.446  0.4056  0.487
(Intercept)                -2.314 -2.4929 -2.135
x                           0.263  0.1437  0.383
stage1:residuals             0.163  0.0322  0.294
w0.3630.24100.484

Causal odds ratio with 95% CI limits: Estimate 0.025 0.975 x 1.3 1.15 1.47

The coefficient of x gives a causal odds ratio of 1.30 (95% CI 1.15 to 1.47). As discussed in § 2, this is a conditional odds ratio, which differs from the causal risk ratio estimated by the MSMM both because odds ratios exceed risk ratios for a common outcome and because of noncollapsibility. The coefficient of the first stage residuals, stage1:residuals, differs from zero (95% CI 0.032 to 0.294), which is evidence of confounding of the exposure-outcome association.

Conditional F-statistics

fsw() computes the Sanderson-Windmeijer conditional FF-statistics for an IV model fitted by ivreg() from ivreg or AER, iv_robust() from estimatr, or feols() from fixest. Here we fit a multivariable MR model of the continuous outcome on both exposures.

R> fit_two <- ivreg(yc ~ x + x2 + w | z1 + z2 + z3 + w, data = mrdata)
R> fsw(fit_two)
Model sample size: 10000

Sanderson-Windmeijer conditional F-statistics for first stage model:
    F value d.f. Residual d.f. Pr(>F)
x   63.24   2          9995 <2e-16 ***
x2  59.82   2          9995 <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Although the usual first stage FF-statistics for x and x2 are 630 and 340, the conditional FF-statistics are an order of magnitude smaller, 63 and 60, because the instruments have similar associations with both exposures. Following Sanderson and Windmeijer [31], the conditional FF-statistics can be compared with the critical values of Stock and Yogo [36] for a single exposure with L−K+1=2L - K + 1 = 2 instruments. With 2 instruments only the critical values based on the size of the Wald test are available. The 5% critical value for a test of the null hypothesis that the actual size of a nominal 5% Wald test on the IV estimate is more than 10% is 19.93. Both conditional FF-statistics are well above this, so we reject the null hypothesis that either exposure is weakly identified. The 2SLS estimates, 0.447 (standard error 0.058) for x and 0.350 (0.078) for x2, are close to the true values of 0.5 and 0.3.

The ivonesamplemr package for Stata

ivonesamplemr can be installed from its GitHub repository, which is a Stata user site, together with its dependencies ivreg2, ranktest, and ivpois from the Statistical Software Components (SSC) archive, with

. net install ivonesamplemr, ///
>   from("https://raw.githubusercontent.com/remlapmot/ivonesamplemr/main/")
. foreach p in ranktest ivreg2 ivpois {
2.   ssc install `p'
3. }

The package provides the commands listed in Table 2, together with an overview help file (help ivonesamplemr), and an iv prefix so that, for example, ivlsmm can also be called as iv lsmm. The package requires Stata 13 or later, because ivmsmm uses ivpoisson, which was introduced in Stata 13, and its certification scripts have been run under Stata 17.0, 18.0, StataNow 18.5, and StataNow 19.5.

All estimation commands use the syntax of ivregress:

command depvar [varlist1] (varlist2 = varlist_iv) [, options]

where varlist1 are the exogenous covariates, varlist2 the exposures, and varlist_iv the instruments. We first read in the same simulated data.

. import delimited using mrdata.csv, clear
(8 vars, 10,000 obs)

Structural mean models

ivmsmm fits the MSMM using the moment conditions in (2), and reports the causal risk ratio by default (the noirr option suppresses exponentiation). Options of ivpoisson, such as vce(), are passed through. Here we adjust for w.

. ivmsmm y w (x = z1 z2 z3)
Final GMM criterion Q(b) = .0001887

Exponential mean model with endogenous regressors

Number of parameters =  3                         Number of obs =     10,000
Number of moments    =  5
Initial weight matrix: Unadjusted
GMM weight matrix:      Robust

------------------------------------------------------------------------------
             |                     Robust
           y |        IRR   std. err.         z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
           x |   1.222707    .0649926      3.78   0.000     1.101735     1.356963
           w |   1.349156    .0725141      5.57   0.000     1.214261     1.499037
       _cons |    .0950487   .0082171    -27.22   0.000      .0802341     .1125987
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.
Endogenous: x
Exogenous:  w z1 z2 z3

The causal risk ratio for x matches that from msmm(..., estmethod = "gmmalt") in § 5. The row for w is the exponentiated covariate coefficient of the model for the exposure-free potential outcome, not a causal effect. Stata’s estat overid postestimation command reports the Hansen JJ-test.

ivlsmm fits the double logistic SMM. By default the association model contains the exposure, instruments, and covariates; this can be changed with the amxb() option.

. ivlsmm y w (x = z1 z2 z3)

(output omitted)
------------------------------------------------------------------------------
             |                             Robust
             | Coefficient  std. err.        z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       /xb_x |  .4269958    .027912     15.30   0.000     .3722892    .4817024
      /xb_z1 | -.0802244    .0332937    -2.41   0.016    -.1454789   -.01497
      /xb_z2 | -.0625341    .0257154    -2.43   0.015    -.1129353   -.0121329
      /xb_z3 | -.0510708    .0210212    -2.43   0.015    -.0922716   -.0098701
       /xb_w |  .2903099    .0570288     5.09   0.000     .1785354    .4020843
         /b0 | -2.402243    .0687134   -34.96   0.000    -2.536919   -2.267567
     /cmxb_x |  .2652068    .0607984     4.36   0.000     .1460441    .3843694
     /cmxb_w |  .3624805    .061985      5.85   0.000     .2409921    .4839688
        /ey0 |  .0906126    .0080846    11.21   0.000     .074767     .1064582
------------------------------------------------------------------------------
Instruments for equation 1: x z1 z2 z3 w _cons
Instruments for equation 2: z1 z2 z3 w _cons

    Test of overidentifying restriction:

    Hansen's J chi2(2) = .719958 (p = 0.6977)

    Causal odds ratio for: x

 ( 1)  [cmxb_x]_cons = 0

------------------------------------------------------------------------------
             |       exp(b)   Std. err.       z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
         (1) |       1.3037    .0792629     4.36   0.000     1.157247    1.468688
------------------------------------------------------------------------------

The xb_ and b0 parameters belong to the association model, and cmxb_x is the log causal odds ratio of the causal model, giving a causal odds ratio among the exposed of 1.30 (95% CI 1.16 to 1.47). The estimates match those from lsmm() in § 5, where the association model parameters are labelled assoc: and cmxb_w is the coefficient of w in the causal model.

Two-stage predictor substitution and residual inclusion

ivtsps and ivtsri take the link() option with the same four link functions as OneSampleMR. The causal effect is the parameter b1, which is reported for the exposure, exponentiated for the nonlinear links, after the coefficient table. The estonly option fits the two regressions without the subsequent GMM step, which is useful with the bootstrap prefix.

. ivtsri y w (x = z1 z2 z3), link(logit)

Final GMM criterion Q(b) = 1.62e-33

note: model is exactly identified.

GMM estimation

Number of parameters =  9
Number of moments     =  9
Initial weight matrix: Unadjusted                 Number of obs     =      10,000

------------------------------------------------------------------------------
             |               Robust
             | Coefficient  std. err.        z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    /s1xb_z1 |   .4934457    .0161039     30.64   0.000     .4618827    .5250088
    /s1xb_z2 |   .3882909    .0170055     22.83   0.000     .3549609    .421621
    /s1xb_z3 |   .3152321    .0151272     20.84   0.000     .2855834    .3448809
     /s1xb_w |   .4463881     .020786     21.48   0.000     .4056482    .487128
         /a0 |   .5230142    .0230039     22.74   0.000     .4779273    .568101
         /b1 |   .2632662    .0610221      4.31   0.000      .143665    .3828673
         /b2 |   .1631531    .0668092      2.44   0.015     .0322095    .2940966
 /s2exogxb_w |   .3626276    .0620558      5.84   0.000     .2410005    .4842547
         /b0 |  -2.314169    .0912082    -25.37   0.000    -2.492934   -2.135404
------------------------------------------------------------------------------
Instruments for equation 1: z1 z2 z3 w _cons
Instruments for equation 2: x residuals w _cons

Causal odds ratio for: x

 ( 1)  [b1]_cons = 0

------------------------------------------------------------------------------
             |      exp(b)   Std. err.        z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       (1)   |    1.301173    .0794003      4.31   0.000     1.154497    1.466483
------------------------------------------------------------------------------

The s1xb_ and a0 parameters are the first stage coefficients, b1 is the causal effect, b2 the coefficient of the first stage residuals (which is not a causal effect and so is not exponentiated), and s2exogxb_w and b0 the remaining second stage coefficients. The estimates are identical to those from tsri() in Section 5.

Conditional F-statistics

ivonesamplemr does not provide its own command for the Sanderson-Windmeijer conditional FF-statistic, because it is reported by ivreg2 with the first option.

. ivreg2 yc w (x x2 = z1 z2 z3), first

(output omitted)
Summary results for first-stage regressions
-------------------------------------------
                         (Underid)          (Weak id)
Variable   | F(  3,  9995) P-val | SW Chi-sq(  2) P-val | SW F(  2,  9995)
x          |       630.20    0.0000 |       126.54    0.0000 |       63.24
x2         |       340.03    0.0000 |       119.70    0.0000 |       59.82
(output omitted)

These match the output of fsw() in Section 5.

Nonlinear exposure-outcome relationships

The ivxtile and ivmw prefix commands apply any of ivregress, ivreg2, ivmsmm, ivlsmm, ivtsps, or ivtsri within quantiles of the first stage residuals, or within moving windows of a given number of participants ordered by the first stage residuals, respectively. The par() option names the parameter to collect, and the saving() option saves the results to a dataset. Both commands also plot the estimates against the median exposure in each quantile or window. Here we fit the MSMM within quintiles; the resulting plot is shown in Figure 1.

Figure 1. Log causal risk ratio estimates (with 95% confidence intervals) from the MSMM fitted within quintiles of the first stage residuals, plotted against the median exposure in each quintile, produced by ivxtile.

. ivxtile, nq(5) par(x): ivmsmm y (x = z1 z2 z3)

    quantile        beta          se     medendog       lowci       uppci
           1      .33837    .1423763     .0592363     .0593123     .6174276
           2     .1091023   .1353864     .8888213    -.156255      .3744597
           3     .0988285   .1234447    1.469166     -.1431231     .3407801
           4     .1669726   .1034489    2.005172     -.0357872     .3697325
           5     .2901259   .0792011    2.914309      .1348917     .4453601

The output gives the log causal risk ratio, its standard error and 95% CI, and the median exposure (medendog) in each quintile. The overlapping confidence intervals are consistent with the constant causal risk ratio of the data generating model. For the moving window approach, for example ivmw, window(2000) par(x): ivmsmm y (x = z1 z2 z3) fits the MSMM in successive windows of 2000 participants.

Agreement across implementations

Table 3 compares the estimates of the causal effect of xx on yy from the two packages, all adjusted for ww. The estimates were produced by the comparison sections of the replication scripts code.R and code.do. For every estimator available in both packages, the estimates and confidence limits agree to three decimal places, as do the Sanderson-Windmeijer FF-statistics in § 5 and § 6. The only estimator without a counterpart is the MSMM with moment conditions (1), which is not implemented in Stata.

The risk ratio estimates are all somewhat below the true value of 1.3, although their confidence intervals include it. This is due to sampling variability in this dataset of 10,000 participants rather than to bias. In a dataset of 100,000 participants simulated from the same model (see code.R), the MSMM estimates were 1.318 and 1.315, the TSPS and TSRI log-additive estimates 1.303 and 1.304, and the ASMM risk difference estimate 0.044.

We also compared msmm() with G-estimation of the MSMM in ivtools. Because ivglm()’s G-estimation uses a model for a single instrument, we used the unweighted allele score z1+z2+z3z1 + z2 + z3 as the instrument in both packages:

R> mrdata$score <- with(mrdata, z1 + z2 + z3)
R> fitZ <- glm(score ~ 1, data = mrdata)
R> fit_g <- ivtools::ivglm(estmethod = "g", X = "x", Y = "y",
+     fitZ.L = fitZ, data = mrdata, link = "log")
R> fit_m <- msmm(y ~ x | score, data = mrdata)
R> rbind(ivtools = exp(c(fit_g$est,
+     fit_g$est + c(-1, 1) * qnorm(0.975) * sqrt(diag(fit_g$vcov)))),
+     OneSampleMR = fit_m$crrci[1, ])
           x
ivtools    1.221 1.105 1.35
EstimatorOneSampleMRivonesamplemr
ASMM (2SLS), risk difference0.035 (0.019, 0.051)0.035 (0.019, 0.051)
MSMM, moment conditions (1), risk ratio1.233 (1.110, 1.369)–
MSMM, moment conditions (2), risk ratio1.223 (1.102, 1.357)1.223 (1.102, 1.357)
LSMM, odds ratio1.304 (1.157, 1.469)1.304 (1.157, 1.469)
TSPS, identity, risk difference0.035 (0.019, 0.051)0.035 (0.019, 0.051)
TSPS, log-additive, risk ratio1.240 (1.127, 1.366)1.240 (1.127, 1.366)
TSPS, log-multiplicative, risk ratio1.226 (1.110, 1.353)1.226 (1.110, 1.353)
TSPS, logit, odds ratio1.297 (1.154, 1.457)1.297 (1.154, 1.457)
TSRI, identity, risk difference0.035 (0.019, 0.051)0.035 (0.019, 0.051)
TSRI, log-additive, risk ratio1.235 (1.123, 1.359)1.235 (1.123, 1.359)
TSRI, log-multiplicative, risk ratio1.231 (1.104, 1.373)1.231 (1.104, 1.373)
TSRI, logit, odds ratio1.301 (1.154, 1.466)1.301 (1.154, 1.466)

caption: Estimates (95% CI) of the causal effect of xx on yy, adjusted for ww, from OneSampleMR and ivonesamplemr applied to the same simulated data. The data were generated with a constant causal risk ratio of 1.3, which implies an average marginal causal risk difference per unit increase in xx of 0.042. Because the odds ratio is noncollapsible and is not constant under this model, there is no single true causal odds ratio.

:::

OneSampleMR 1.221 1.105 1.35

With a single instrument the model is exactly identified and both packages solve the same estimating equation, E{(Z−EZ)Yexp⁡(−ψX)}=0E\{(Z-EZ)Y\exp(-\psi X)\}=0. The estimates of ψ\psi from ivtools, msmm(), and the root of the estimating equation found by uniroot() agree to seven decimal places (0.1999973).

Summary and discussion

We have described OneSampleMR for R and ivonesamplemr for Stata, which implement IV estimators for one-sample MR analyses with a common set of estimators, parameterizations, and link function names. The packages do not introduce new methodology. Rather, they make established estimators, which are particularly relevant for binary outcomes, easy to apply with correct standard errors and an interface familiar to users of ivreg() in R and ivregress in Stata. Because the two packages give the same results, analyses can be checked across languages, and collaborators using different languages can fit the same models.

The packages currently differ slightly in their coverage. The moving window and within-quantile estimation commands are available only in ivonesamplemr, and the MSMM with moment conditions (1) only in OneSampleMR. Conversely, fsw() in OneSampleMR provides the Sanderson-Windmeijer conditional FF-statistic, which in Stata is available from ivreg2. A limitation of both packages is that the TSPS and TSRI estimators allow only a single exposure. Future work includes implementing the nonlinear exploration methods in OneSampleMR and allowing multiple exposures in the TSPS and TSRI estimators in both packages.

Users should bear in mind that all the estimators rely on the IV assumptions, which cannot be fully tested, and on additional modeling assumptions which differ between estimators. The estimators also target different estimands: a causal risk difference (ASMM, and TSPS and TSRI with the identity link), a causal risk ratio (MSMM, and TSPS and TSRI with the log-additive and log-multiplicative links), a causal odds ratio among the exposed (LSMM), and a conditional causal odds ratio (TSPS and TSRI with the logit link). In our example the risk ratio estimators agree closely because the data were generated from a model in which their assumptions hold, with a constant causal risk ratio, a linear first stage, and no effect modification by the instruments. When the assumptions of an estimator do not hold, for example when the causal effect is modified by the instruments or the first stage model is misspecified, estimators that rely on different assumptions can give different results [26, 7]. Fitting several estimators, as facilitated by the packages, and comparing their results, together with the overidentification tests when multiple instruments are available, can therefore help assess the sensitivity of conclusions to these assumptions.

Computational details

The results in this paper were obtained using R 4.6.1 with OneSampleMR 0.1.9, gmm 1.9-1, ivreg 0.6-8, and ivtools 2.3.0, and StataNow 19.5 MP with ivonesamplemr (distribution date 21 October 2026), ivreg2 4.1.12, ranktest 2.0.04, and ivpois 1.1.8. R itself and all R packages used are available from CRAN at https://CRAN.R-project.org/. The replication materials consist of code.R, which simulates the data and produces the R results, and code.do, which produces the Stata results.

Acknowledgments

TP acknowledges funding from NIHR510725. TP acknowledges support from MC_UU_00032/2. TP, ES, and NV acknowledge support from MC_UU_00032/1. ES and NV acknowledge funding from the Medical Research Council UKRI077.

Affiliation:

Tom M. Palmer MRC Integrative Epidemiology Unit Population Health Sciences Bristol Medical School

University of Bristol Augustine’s Courtyard, Orchard Lane Bristol, BS1 5DS, United Kingdom E-mail: [email protected] URL: https://remlapmot.github.io/

References

  1. [1]Baum CF, Schaffer ME, Stillman S (2007). “Enhanced Routines for Instrumental Variables/Generalized Method of Moments Estimation and Testing.” The Stata Journal, 7(4), 465–506. doi:10.1177/1536867X0800700402.DOI
  2. [2]Bergé LR, Butts K, McDermott G (2026). “Fast and User-Friendly Econometrics Estimations: The R Package fixest.” arXiv:2601.21749. doi:10.48550/arXiv.2601.21749.
  3. [3]Burgess S (2023). “Violation of the Constant Genetic Effect Assumption Can Result in Biased Estimates for Non-Linear Mendelian Randomization.” Human Heredity, 88(1), 79–90. doi:10.1159/000531659.DOI
  4. [4]Burgess S, CRP CHD Genetics Collaboration (2013). “Identifying the Odds Ratio Estimated by a Two-Stage Instrumental Variable Analysis with a Logistic Regression Model.” Statistics in Medicine, 32(27), 4726–4747. doi:10.1002/sim.5871.DOI
  5. [5]Burgess S, Davies NM, Thompson SG (2014). “Instrumental Variable Analysis with a Nonlinear Exposure-Outcome Relationship.” Epidemiology, 25(6), 877–885. doi:10.1097/EDE.0000000000000161.DOI
  6. [6]Chaussé P (2010). “Computing Generalized Method of Moments and Generalized Empirical Likelihood with R.” Journal of Statistical Software, 34(11), 1–35. doi:10.18637/jss.v034.i11.DOI
  7. [7]Clarke PS, Palmer TM, Windmeijer F (2015). “Estimating Structural Mean Models with Multiple Instrumental Variables Using the Generalised Method of Moments.” Statistical Science, 30(1), 96–117. doi:10.1214/14-STS503.
  8. [8]Coppock A, Blair G, Cooper J, Sonnet L (2026). estimatr: Fast Estimators for Design-Based Inference. doi:10.32614/CRAN.package.estimatr. R package version 2.0.1.
  9. [9]Davey Smith G, Ebrahim S (2003). ““Mendelian Randomization’: Can Genetic Epidemiology Contribute to Understanding Environmental Determinants of Disease?” International Journal of Epidemiology, 32(1), 1–22. doi:10.1093/ije/dyg070.
  10. [10]Didelez V, Meng S, Sheehan NA (2010). “Assumptions of IV Methods for Observational Epidemiology.” Statistical Science, 25(1), 22–40. doi:10.1214/09-STS316.DOI
  11. [11]Didelez V, Sheehan N (2007). “Mendelian Randomization as an Instrumental Variable Approach to Causal Inference.” Statistical Methods in Medical Research, 16(4), 309–330. doi:10.1177/0962280206077743.DOI
  12. [12]Dukes O, Vansteelandt S (2018). “A Note on G-Estimation of Causal Risk Ratios.” American Journal of Epidemiology, 187(5), 1079–1084. doi:10.1093/aje/kwx347.DOI
  13. [13]Fox J, Kleiber C, Zeileis A (2026). ivreg: Instrumental Variables Regression by ‘2SLS’, ‘2SM’, or ‘2SMM’, with Diagnostics. doi:10.32614/CRAN.package.ivreg. R package version 0.6-8.
  14. [14]Hamilton FW, Hughes DA, Spiller W, Tilling K, Davey Smith G (2024). “Non-Linear Mendelian Randomization: Detection of Biases Using Negative Controls with a Focus on BMI, Vitamin D and LDL Cholesterol.” European Journal of Epidemiology, 39(5), 451–465. doi:10.1007/s10654-024-01113-9.DOI
  15. [15]Hansen LP (1982). “Large Sample Properties of Generalized Method of Moments Estimators.” Econometrica, 50(4), 1029–1054. doi:10.2307/1912775.DOI
  16. [16]Hemani G, Zheng J, Elsworth B, Wade KH, Haberland V, Baird D, Laurin C, Burgess S, Bowden J, Langdon R, Tan VY, Yarmolinsky J, Shihab HA, Timpson NJ, Evans DM, Relton C, Martin RM, Davey Smith G, Gaunt TR, Haycock PC (2018). “The MR-Base Platform Supports Systematic Causal Inference across the Human Phenome.” eLife, 7, e34408. doi:10.7554/eLife.34408.DOI
  17. [17]Hernán MA, Robins JM (2006). “Instruments for Causal Inference: An Epidemiologist’s Dream?” Epidemiology, 17(4), 360–372. doi:10.1097/01.ede.0000222409.00878.37.DOI
  18. [18]Jackson CH (2011). “Multi-State Models for Panel Data: The msm Package for R.” Journal of Statistical Software, 38(8), 1–28. doi:10.18637/jss.v038.i08.DOI
  19. [19]Kleiber C, Zeileis A (2008). Applied Econometrics with R. Springer-Verlag, New York. doi:10.1007/978-0-387-77318-6.DOI
  20. [20]Lawlor DA, Harbord RM, Sterne JAC, Timpson N, Davey Smith G (2008). “Mendelian Randomization: Using Genes as Instruments for Making Causal Inferences in Epidemiology.” Statistics in Medicine, 27(8), 1133–1163. doi:10.1002/sim.3034.DOI
  21. [21]Madley-Dowd P, Dardani C, Wootton RE, Dack K, Palmer T, Thurston R, Haydahl A, Golding J, Lawlor D, Rai D (2022). “Maternal Vitamin D during Pregnancy and Offspring Autism and Autism-Associated Traits: A Prospective Cohort Study.” Molecular Autism, 13, 44. doi:10.1186/s13229-022-00523-4.
  22. [22]Mullahy J (1997). “Instrumental-Variable Estimation of Count Data Models: Applications to Models of Cigarette Smoking Behavior.” The Review of Economics and Statistics, 79(4), 586–593. doi:10.1162/003465397557169.DOI
  23. [23]Nichols A (2007). ivpois: Stata Module for IV/GMM Poisson Regression. Boston College Department of Economics. Statistical Software Components S456890, URL https://ideas.repec.org/c/boc/bocode/s456890.html.
  24. [24]Palmer T (2026). ivonesamplemr: Stata Package for One-Sample Mendelian Randomization and Instrumental Variable Analyses. Stata package, URL https://github.com/remlapmot/ivonesamplemr.
  25. [25]Palmer T, Spiller W, Sanderson E, Vitt N (2026). OneSampleMR: One Sample Mendelian Randomization and Instrumental Variable Analyses. doi:10.32614/CRAN.package.OneSampleMR. R package version 0.1.9.
  26. [26]Palmer TM, Sterne JAC, Harbord RM, Lawlor DA, Sheehan NA, Meng S, Granell R, Davey Smith G, Didelez V (2011). “Instrumental Variable Estimation of Causal Risk Ratios and Causal Odds Ratios in Mendelian Randomization Analyses.” American Journal of Epidemiology, 173(12), 1392–1403. doi:10.1093/aje/kwr026.DOI
  27. [27]R Core Team (2026). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.
  28. [28]Robins JM (1989). “The Analysis of Randomized and Non-Randomized AIDS Treatment Trials Using a New Approach to Causal Inference in Longitudinal Studies.” In L Sechrest, H Freeman, A Mulley (eds.), Health Service Research Methodology: A Focus on AIDS, pp. 113–159. U.S. Public Health Service, National Center for Health Services Research, Washington, DC.
  29. [29]Robins JM (1994). “Correcting for Non-Compliance in Randomized Trials Using Structural Nested Mean Models.” Communications in Statistics – Theory and Methods, 23(8), 2379–2412. doi:10.1080/03610929408831393.DOI
  30. [30]Sanderson E, Glymour MM, Holmes MV, Kang H, Morrison J, Munafò MR, Palmer T, Schooling CM, Wallace C, Zhao Q, Davey Smith G (2022). “Mendelian Randomization.” Nature Reviews Methods Primers, 2, 6. doi:10.1038/s43586-021-00092-5.DOI
  31. [31]Sanderson E, Windmeijer F (2016). “A Weak Instrument F-Test in Linear IV Models with Multiple Endogenous Variables.” Journal of Econometrics, 190(2), 212–221. doi:10.1016/j.jeconom.2015.06.004.DOI
  32. [32]Sjölander A, Martinussen T (2019). “Instrumental Variable Estimation with the R Package ivtools.” Epidemiologic Methods, 8(1), 20180024. doi:10.1515/em-2018-0024.DOI
  33. [33]Spiller W, Davies NM, Palmer TM (2019). “Software Application Profile: mrrobust – A Tool for Performing Two-Sample Summary Mendelian Randomization Analyses.” International Journal of Epidemiology, 48(3), 684–690. doi:10.1093/ije/dyy195.DOI
  34. [34]StataCorp (2025a). Stata Base Reference Manual: ivpoisson – Poisson Model with Continuous Endogenous Covariates. StataCorp LLC, College Station, TX.
  35. [35]StataCorp (2025b). Stata Statistical Software: Release 19. StataCorp LLC, College Station, TX.
  36. [36]Stock JH, Yogo M (2005). “Testing for Weak Instruments in Linear IV Regression.” In DWK Andrews, JH Stock (eds.), Identification and Inference for Econometric Models: Essays in Honor of Thomas Rothenberg, pp. 80–108. Cambridge University Press, Cambridge.
  37. [37]Terza JV, Basu A, Rathouz PJ (2008). “Two-Stage Residual Inclusion Estimation: Addressing Endogeneity in Health Econometric Modeling.” Journal of Health Economics, 27(3), 531–543. doi:10.1016/j.jhealeco.2007.09.009.DOI
  38. [38]Vansteelandt S, Bowden J, Babanezhad M, Goetghebeur E (2011). “On Instrumental Variables Estimation of Causal Odds Ratios.” Statistical Science, 26(3), 403–422. doi:10.1214/11-STS360.DOI
  39. [39]Vansteelandt S, Goetghebeur E (2003). “Causal Inference with Generalized Structural Mean Models.” Journal of the Royal Statistical Society B, 65(4), 817–835. doi:10.1046/j.1369-7412.2003.00417.x.DOI
  40. [40]Windmeijer FAG, Santos Silva JMC (1997). “Endogeneity in Count Data Models: An Application to Demand for Health Care.” Journal of Applied Econometrics, 12(3), 281–294. doi:10.1002/(SICI)1099-1255(199705)12:3<281::AID-JAE436>3.0.CO;2-1.doi.org/10.1002/(sici)1099-1255(199705)12:3<281::aid-jae436>3.0.co;2-1
  41. [41]Yavorska OO, Burgess S (2017). “MendelianRandomization: An R Package for Performing Mendelian Randomization Analyses Using Summarized Data.” International Journal of Epidemiology, 46(6), 1734–1739. doi:10.1093/ije/dyx034.DOI
  42. [42]Zeileis A, Croissant Y (2010). “Extended Model Formulas in R: Multiple Parts and Multiple Responses.” Journal of Statistical Software, 34(1), 1–13. doi:10.18637/jss.v034.i01.DOI
  43. [43]Zeileis A, Hothorn T (2002). “Diagnostic Checking in Regression Relationships.” R News, 2(3), 7–10. URL https://CRAN.R-project.org/doc/Rnews/.

Paper details

vlnc:W_3engfz5q
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Mathematics

Not recorded for this paper

View statement
Looking for related papers…
Contents