Description Usage Arguments Details Value Author(s) References See Also Examples
AFivglm
estimates the model-based adjusted attributable fraction from a Instrumental Variable regression from a ivglm
object. The IV regression can be estimated by either G-estimation or Two Stage estimation for a binary exposure and outcome.
1 |
object |
a fitted Instrumental Variable regression of class " |
data |
an optional data frame, list or environment (or object coercible by |
AFivglm
estimates the attributable fraction for an IV regression
under the hypothetical scenario where a binary exposure X
is eliminated from the population.
The estimate can be adjusted for IV-outcome confounders L
in the ivglm
function.
Let the AF function be defined as
AF = 1 - \frac{Pr(Y0=1)}{Pr(Y=1)}
where Pr(Y0=1) denotes the counterfactual outcome prevalence had everyone been unexposed and Pr(Y=1) denotes the factual outcome prevalence.
If the instrument Z
is valid, conditional on covariates L
, i.e. fulfills the IV assumptions 1) the IV should have a (preferably strong) association with
the exposure, 2) the effect of the IV on the outcome should only go through the exposure and 3) the IV-outcome association should be unconfounded
(Imbens and Angrist, 1994) then Pr(Y0=1) can be estimated.
AF.est |
estimated attributable fraction. |
AF.var |
estimated variance of |
Elisabeth Dahlqwist, Arvid Sj<c3><b6>lander
Dahlqwist E., Kutalik Z., Sj<c3><b6>lander, A. (2019). Using Instrumental Variables to estimate the attributable fraction. Manuscript.
ivglm
used for fitting the causal risk ratio or odds ratio using the G-estimator or Two stage estimator.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # Example 1
set.seed(2)
n <- 5000
## parameter a0 determines the outcome prevalence
a0 <- -4
psi.true <- 1
l <- rbinom(n, 1, 0.5)
u <- rbinom(n, 1, 0.5)
z <- rbinom(n, 1, plogis(a0))
x <- rbinom(n, 1, plogis(a0+3*z+ u))
y <- rbinom(n, 1, exp(a0+psi.true*x+u))
d <- data.frame(z,u,x,y,l)
## Outcome prevalence
mean(d$y)
####### G-estimation
## log CRR
fitz.l <- glm(z~1, family=binomial, data=d)
gest_log <- ivglm(estmethod="g", X="x", Y="y",
fitZ.L=fitz.l, data=d, link="log")
AFgestlog <- AFivglm(gest_log, data=d)
summary(AFgestlog)
## log COR
## Associational model, saturated
fit_y <- glm(y~x+z+x*z, family="binomial", data=d)
## Estimations of COR and AF
gest_logit <- ivglm(estmethod="g", X="x", Y="y",
fitZ.L=fitz.l, fitY.LZX=fit_y,
data=d, link="logit")
AFgestlogit <- AFivglm(gest_logit, data = d)
summary(AFgestlogit)
####### TS estimation
## log CRR
# First stage
fitx <- glm(x ~ z, family=binomial, data=d)
# Second stage
fity <- glm(y ~ x, family=poisson, data=d)
## Estimations of CRR and AF
TSlog <- ivglm(estmethod="ts", X="x", Y="y",
fitY.LX=fity, fitX.LZ=fitx, data=d, link="log")
AFtslog <- AFivglm(TSlog, data=d)
summary(AFtslog)
## log COR
# First stage
fitx_logit <- glm(x ~ z, family=binomial, data=d)
# Second stage
fity_logit <- glm(y ~ x, family=binomial, data=d)
## Estimations of COR and AF
TSlogit <- ivglm(estmethod="ts", X="x", Y="y",
fitY.LX=fity_logit, fitX.LZ=fitx_logit,
data=d, link="logit")
AFtslogit <- AFivglm(TSlogit, data=d)
summary(AFtslogit)
## Example 2: IV-outcome confounding by L
####### G-estimation
## log CRR
fitz.l <- glm(z~l, family=binomial, data=d)
gest_log <- ivglm(estmethod="g", X="x", Y="y",
fitZ.L=fitz.l, data=d, link="log")
AFgestlog <- AFivglm(gest_log, data=d)
summary(AFgestlog)
## log COR
## Associational model
fit_y <- glm(y~x+z+l+x*z+x*l+z*l, family="binomial", data=d)
## Estimations of COR and AF
gest_logit <- ivglm(estmethod="g", X="x", Y="y",
fitZ.L=fitz.l, fitY.LZX=fit_y,
data=d, link="logit")
AFgestlogit <- AFivglm(gest_logit, data = d)
summary(AFgestlogit)
####### TS estimation
## log CRR
# First stage
fitx <- glm(x ~ z+l, family=binomial, data=d)
# Second stage
fity <- glm(y ~ x+l, family=poisson, data=d)
## Estimations of CRR and AF
TSlog <- ivglm(estmethod="ts", X="x", Y="y",
fitY.LX=fity, fitX.LZ=fitx, data=d,
link="log")
AFtslog <- AFivglm(TSlog, data=d)
summary(AFtslog)
## log COR
# First stage
fitx_logit <- glm(x ~ z+l, family=binomial, data=d)
# Second stage
fity_logit <- glm(y ~ x+l, family=binomial, data=d)
## Estimations of COR and AF
TSlogit <- ivglm(estmethod="ts", X="x", Y="y",
fitY.LX=fity_logit, fitX.LZ=fitx_logit,
data=d, link="logit")
AFtslogit <- AFivglm(TSlogit, data=d)
summary(AFtslogit)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.