New functions ivxtile() and ivmw() explore whether the causal effect varies with the level of the exposure, as described by Burgess et al. (2014), by fitting an IV estimator (ivreg::ivreg(), msmm(), lsmm(), tsps(), or tsri()) within quantile groups of the first stage residuals or within moving windows of observations ordered by the first stage residuals. They have print() and plot() methods (the plot() methods have ylim and legend arguments) and are the equivalents of the ivxtile and ivmw commands in the Stata package ivonesamplemr.
The help page titles now consistently use title case.
The examples in ?fsw now only use the suggested packages AER, estimatr, and fixest if they are installed.
Fixed the covariate adjustment example in ?msmm, in which the covariate was generated from the same random numbers as one of the instruments, so that the fit did not converge.
Fixed the p-values of fsw(), which used the number of endogenous variables, K, as the numerator degrees of freedom instead of L - K + 1, where L is the number of excluded instruments. The reported conditional F-statistics and degrees of freedom were correct, and the p-values were only affected when L - K + 1 differed from K.
New coef(), vcov(), confint(), nobs(), and formula() methods for the objects returned by msmm(), lsmm(), tsps(), and tsri() (see ?OneSampleMR-methods). The fitted objects now also contain the call and formula.
The summary() methods for these objects now report the call, a coefficient table formatted with printCoefmat() with Wald z statistics and p-values, and, for overidentified GMM fits of msmm() and lsmm(), the Hansen J-test of the overidentifying restrictions. The summary objects have new call, coefficients, and (for msmm() and lsmm()) jtest elements.
The parameters of msmm() with estmethod = "gmm" or "gmmalt" are now labelled (E[Y(0)] or log E[Y(0)], then the exposures and covariates) instead of Theta[1], Theta[2], ..., and msmm() gives a clear error message if t0 has the wrong length. For the "tsls" and "tslsalt" methods crrci is now a labelled matrix, as for the GMM methods.
tsps() and tsri() are roughly twice as fast. The first stage regression is now fitted once with .lm.fit(), the second stage starting values are obtained with glm.fit() or .lm.fit() on the model matrices instead of by resolving formulas, and the GMM moment functions work directly on the model matrices instead of extracting columns from a data frame on every evaluation. As a result a variable named y can now be used in their formulas. The estimates are unchanged.
lsmm() is faster, because its first GMM step no longer computes an unused HAC variance matrix, and its starting values are obtained with .lm.fit() and glm.fit() on the model matrices.
The Newton-Raphson step used to obtain the starting values for the logmult link of tsps() and tsri() now uses a Cholesky factorization of the Hessian.
Use wooldridge::mroz instead of downloading mroz.dta from fmwww.bc.edu in F-statistic vignette and tests
New function lsmm() fits the double logistic structural mean model (LSMM) of Vansteelandt and Goetghebeur (2003), which estimates a causal odds ratio, by two-step GMM with multiple instruments as described by Clarke et al. (2015). It has print() and summary() methods, the summary includes the Hansen J-test of the overidentifying restrictions, and covariates are handled as in msmm(). It is the same estimator as the ivlsmm command in the Stata package ivonesamplemr, and its estimates agree with ivlsmm.
tsps() and tsri() with link = "logmult" now converge to the solution of the estimating equations. Previously the GMM optimizer often stopped at its iteration limit, giving slightly inaccurate estimates and a non-convergence warning. The starting values are now obtained by solving the second stage estimating equations exactly by Newton-Raphson, rather than from a gamma regression with zero outcomes replaced by 0.001. The estimates now agree with the Stata commands ivtsps and ivtsri in the ivonesamplemr package.
tsps() and tsri() no longer give a spurious non-convergence warning when the optimizer has reached the minimum of the GMM objective function (which is 0 because these models are exactly identified).
msmm() with estmethod = "gmm" or "gmmalt" now uses a tighter convergence tolerance for the Nelder-Mead optimizer (reltol = .Machine$double.eps, maxit = 1E4), so that the estimates converge to the minimum of the GMM objective function. Previously the default tolerance could stop the optimizer early, so estimates depended on the starting values and could differ in the second or third decimal place from the solution of the estimating equations. Estimates from exactly identified models now agree with ivtools::ivglm() G-estimation and with Stata's ivpoisson gmm, multiplicative.
The parameters in the output of tsps() and tsri() are now labelled by stage and variable name. First stage parameters are prefixed stage1:, the second stage exposure and covariate parameters take their variable names (previously, e.g., xhatxhat and xhatcovariates for tsps()), and the first stage residual in tsri() is labelled stage1:residuals (previously resres). The same labels are used when the user specifies t0, and tsps() and tsri() now give a clear error message if t0 has the wrong length. The documentation of t0 has been corrected.
The print and summary methods for tsps() and tsri() fits now only exponentiate the exposure parameter in the causal risk ratio or causal odds ratio table. Previously all the second stage parameters were exponentiated and presented as causal ratios, including the intercept, any covariates, and, for tsri(), the coefficient of the first stage residuals.
msmm() now distinguishes covariates (variables included in both the exposure and instrument parts of the formula) from exposures. The causal risk ratio table (crrci) now only contains the exposures; previously it also reported the exponentiated covariate coefficients as causal risk ratios. The covariate adjusted model itself is unchanged, and is the same model as fitted by Stata's ivpoisson gmm, multiplicative with exogenous covariates. The returned object has a new covariates element, the print methods list the covariates adjusted for and note that E[Y(0)] is then estimated at covariate values of 0, and covariate adjustment is documented with an example in ?msmm. Covariates with the "tsls" and "tslsalt" methods now give a clear error message.
Bump roxygen2 to 8.0.0.
Fixed a bug in fsw() for models fitted by ivreg::ivreg() which reported conditional F statistics for the wrong variables when exogenous covariates were listed before the exposures in the model formula
Fixed a bug in tsps() and tsri() which produced incorrect estimates when exogenous covariates were listed before the exposure or the instruments in the model formula
tsps() and tsri() now give a clear error message when more than one exposure is specified, when a variable is named y (which is reserved for internal use), and their print methods no longer error when a user specified unnamed t0 is used with a log-link or logit-link model
fsw() now detects ordered factor exposures, and its factor exposure error message is restored for the ivreg::ivreg() method and fixed for the fixest::feols() method
msmm() now gives its intended error message for non-integer outcomes and a corrected message for negative outcomes
tsps() and tsri() are now roughly 2 times faster because the first stage regression is computed once instead of on every evaluation of the GMM moment functions, and the moment conditions in all three GMM based estimators are now vectorised
Internal refactoring: the four fsw() methods now share a common engine, the eight tsps()/tsri() moment functions are reduced to one per estimator, and dead code has been removed
fsw() can now calculate Sanderson-Windmeijer conditional F statistics for models fitted by AER::ivreg(), estimatr::iv_robust(), and fixest::feols() (thanks @nvitt)Fixed a bug in fsw() when an exogenous covariate was a factor (thanks @ZoeReed)
The fsw() function now returns an error if any of the exposures are factors
Add CITATION file
Tweak formatting of code in helpfile examples and vignettes
Add subsection to README about GNU Fortran requirement for old versions of the gmm package on macOS
Bumped the minimum required version of R to be 4.1.0. This is because of the same requirement in pbkrtest, which is a dependency of car which is a dependency of ivreg
Bumped version of roxygen2 used to create the package documentation
Made use of ellipsis ... in several function definitions safer using the ellipsis package
Bumped required version of R to 4.3.0 because the Matrix package, which is a dependency of ivreg now requires R 4.4.0. CRAN retain a binary version of Matrix 1.6-5 for the previous release of R, and so the minimum version of R can be 4.3.0 rather than 4.4.0.
Update roxygen2 version used to generate documentation
Reduce the number of functions imported from other packages
Make use of packages in Suggests list conditional on their availability
Remove ivtools from Suggests due to the current failure of its ahaz dependency package to build on 3 of the CRAN Linux sub-architectures
R CMD check note in R 4.2.0