
ivglm
performs instrumental variable estimation of the causal exposure effect in
generalized linear models with individual-level data. Below,
ivglm(estmethod, X, Y, fitZ.L=NULL, fitX.LZ=NULL, fitX.L=NULL, fitY.LX=NULL,
fitY.LZX=NULL, data, formula=~1, ctrl=FALSE, clusterid=NULL, link, vcov.fit=TRUE,
...)
a string specifying the desired estimation method; either "ts"
for two-stage
estimation, or "g"
for G-estimation.
a string specifying the name of the exposure data
. This is not needed
if fitX.LZ
is specified.
a string specifying the name of the outcome data
. This
is not needed if fitY.LX
or fitY.LZX
is specified.
an object of class "glm"
, as returned by the glm
function
in the stats package. This is a fitted GLM for fitZ.L
may be specified as a model with an intercept only. This argument
is not used when estmethod="ts"
.
an object of class "glm"
, as returned by the glm
function
in the stats package. This is a fitted GLM for
an object of class "glm"
, as returned by the glm
function
in the stats package. This is a fitted GLM for fitX.L
may be specified as a model with an intercept only. This argument
is not used when estmethod="ts"
.
an object of class "glm"
, as returned by the glm
function
in the stats package. This is a fitted GLM for estmethod="g"
.
an object of class "glm"
, as returned by the glm
function
in the stats package. This is a fitted GLM for estmethod="ts"
. It is also not used
when estmethod="g"
and link="identity"
or link="log"
.
a data frame containing the variables in the model. The covariates, instrument,
exposure and outcome can have arbitrary names, e.g. they don't need to
be called L
, Z
, X
and Y
.
an object of class "formula"
, with no left-hand side. This specifies
the causal interaction terms ~1
, i.e.
main effect only. This argument is not used when estmethod="ts"
.
logical. Should the control function fitY.LX
? This argument is not used when estmethod="g"
.
an optional string containing the name of a cluster identification variable when
data are clustered. Specifying clusterid
corrects the standard errors
but does not affect the estimates.
a string specifying the link function for the causal generalized linear model;
see `Details'. Either "identity"
, "log"
, or "logit"
.
This argument is not used when estmethod="ts"
.
logical. Should the variance-covariance matrix be computed?
optional arguments passed on to the nleqslv
function, which is used to
solve the estimating equations when estmethod="g"
. See the help pages
for nleqslv
. This argument is not used when estmethod="ts"
.
ivglm
returns an object of class "ivglm"
, which inherits from
class "ivmod"
. An object of class "ivglm"
is a list containing
the matched call.
input
is a list containing all input arguments
a vector containing the estimate of
the variance-covariance matrix for the estimate of
a matrix of all subject-specific contributions to the estimating functions used in the estimation process.
One row for each subject, one column for each parameter. If estmethod="ts"
,
then the first columns correspond to the parameters estimated by fitX.LZ
, and
the last columns correspond to the parameters estimated by the re-fitted model
fitY.LX
. If estmethod="g"
, then the first columns correspond to fitZ.L
,
fitX.LZ
, fitX.L
and fitY.LZX
, whichever were used in the
estimation process.
the jacobian matrix of colMeans(estfunall)
.
logical. Was a solution found to the estimating equations?
the re-fitted model fitY.LX
used in the estimation process when estmethod="ts"
.
This element is NULL when estmethod="g"
.
ivglm
estimates the parameter link
argument. The vector function estmethod="ts"
, then these are specified
implicitly through the model fitY.LX
. If estmethod="g"
, then these
are specified explicitly through the formula
argument.
If estmethod="ts"
, then two-stage estimation of fitX.LZ
is used to construct predictions
fitY.LX
, with
If estmethod="g"
, then G-estimation of link="identity"
,
link="log"
, and
link="logit"
. In the latter, fitY.LZX
.
The estimated function fitX.LZ
and fitX.L
are specified, then fitX.LZ
and fitX.L
, respectively. If these are not specified, then fitZ.L
, which then must be specified.
Bowden J., Vansteelandt S. (2011). Mendelian randomization analysis of case-control data using structural mean models. Statistics in Medicine 30(6), 678-694.
Sjolander A., Martinussen T. (2019). Instrumental variable estimation with the R package ivtools. Epidemiologic Methods 8(1), 1-20.
Vansteelandt S., Bowden J., Babanezhad M., Goetghebeur E. (2011). On instrumental variables estimation of causal odds ratios. Statistical Science 26(3), 403-422.
# NOT RUN {
set.seed(9)
##Note: the parameter values in the examples below are chosen to make
##Y0 independent of Z, which is necessary for Z to be a valid instrument.
n <- 1000
psi0 <- 0.5
psi1 <- 0.2
##---Example 1: linear model and interaction between X and L---
L <- rnorm(n)
Z <- rnorm(n, mean=L)
X <- rnorm(n, mean=Z)
m0 <- X-Z+L
Y <- rnorm(n, mean=psi0*X+psi1*X*L+m0)
data <- data.frame(L, Z, X, Y)
#two-stage estimation
fitX.LZ <- glm(formula=X~Z, data=data)
fitY.LX <- glm(formula=Y~X+L+X*L, data=data)
fitIV <- ivglm(estmethod="ts", fitX.LZ=fitX.LZ, fitY.LX=fitY.LX, data=data,
ctrl=TRUE)
summary(fitIV)
#G-estimation with model for Z
fitZ.L <- glm(formula=Z~L, data=data)
fitIV <- ivglm(estmethod="g", X="X", Y="Y", fitZ.L=fitZ.L, data=data,
formula=~L, link="identity")
summary(fitIV)
#G-estimation with model for X
fitX.LZ <- glm(formula=X~L+Z, data=data)
fitX.L <- glm(formula=X~L, data=data)
fitIV <- ivglm(estmethod="g", Y="Y", fitX.LZ=fitX.LZ, fitX.L=fitX.L, data=data,
formula=~L, link="identity")
summary(fitIV)
##---Example 2: logistic model and no covariates---
Z <- rbinom(n, 1, 0.5)
X <- rbinom(n, 1, 0.7*Z+0.2*(1-Z))
m0 <- plogis(1+0.8*X-0.39*Z)
Y <- rbinom(n, 1, plogis(psi0*X+log(m0/(1-m0))))
data <- data.frame(Z, X, Y)
#two-stage estimation
fitX.LZ <- glm(formula=X~Z, family="binomial", data=data)
fitY.LX <- glm(formula=Y~X, family="binomial", data=data)
fitIV <- ivglm(estmethod="ts", fitX.LZ=fitX.LZ, fitY.LX=fitY.LX, data=data,
ctrl=TRUE)
summary(fitIV)
#G-estimation with model for Z
fitZ.L <- glm(formula=Z~1, data=data)
fitY.LZX <- glm(formula=Y~X+Z+X*Z, family="binomial", data=data)
fitIV <- ivglm(estmethod="g", X="X", fitZ.L=fitZ.L, fitY.LZX=fitY.LZX,
data=data, link="logit")
summary(fitIV)
# }
Run the code above in your browser using DataLab