R: Attributable fraction for cross-sectional sampling designs.
AF.cs
R Documentation
Attributable fraction for cross-sectional sampling designs.
Description
AF.cs estimates the model-based adjusted attributable fraction for data from cross-sectional sampling designs.
Usage
AF.cs(formula, data, exposure, clusterid)
Arguments
formula
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model used for adjusting for confounders. The exposure and confounders should be specified as independent (right-hand side) variables. The outcome should be specified as dependent (left-hand side) variable. The formula is used to fit a logistic regression by glm.
data
an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment (formula), typically the environment from which the function is called.
exposure
the name of the exposure variable as a string. The exposure must be binary (0/1) where unexposed is coded as 0.
clusterid
the name of the cluster identifier variable as a string, if data are clustered.
Details
Af.cs estimates the attributable fraction for a binary outcome Y
under the hypothetical scenario where a binary exposure X is eliminated from the population.
The estimate is adjusted for confounders Z by logistic regression (glm).
Let the AF be defined as
AF = 1 - Pr(Y0 = 1) / Pr(Y = 1)
where Pr(Y0 = 1) denotes the counterfactual probability of the outcome if
the exposure would have been eliminated from the population and Pr(Y = 1) denotes the factual probability of the outcome.
If Z is sufficient for confounding control, then Pr(Y0 = 1) can be expressed as
E_z{Pr(Y = 1 |X = 0,Z)}.
The function uses logistic regression to estimate Pr(Y=1|X=0,Z), and the marginal sample distribution of Z
to approximate the outer expectation (Sj<c3><83><c2><b6>lander and Vansteelandt, 2012).
If clusterid is supplied, then a clustered sandwich formula is used in all variance calculations.
Value
AF.est
estimated attributable fraction.
AF.var
estimated variance of AF.est. The variance is obtained by combining the delta method with the sandwich formula.
P.est
estimated factual proportion of cases; Pr(Y=1).
P.var
estimated variance of P.est. The variance is obtained by the sandwich formula.
P0.est
estimated counterfactual proportion of cases if exposure would be eliminated; Pr(Y0=1).
P0.var
estimated variance of P0.est. The variance is obtained by the sandwich formula.
fit
the fitted model. Fitted using logistic regression, glm.
Author(s)
Elisabeth Dahlqwist, Arvid Sj<c3><83><c2><b6>lander
References
Greenland, S. and Drescher, K. (1993). Maximum Likelihood Estimation of the Attributable Fraction from logistic Models. Biometrics49, 865-872.
Sj<c3><83><c2><b6>lander, A. and Vansteelandt, S. (2011). Doubly robust estimation of attributable fractions. Biostatistics12, 112-121.
See Also
glm used for fitting the logistic regression model.
Examples
# Simulate a cross-sectional sample
expit <- function(x) 1 / (1 + exp( - x))
n <- 1000
Z <- rnorm(n = n)
X <- rbinom(n = n, size = 1, prob = expit(Z))
Y <- rbinom(n = n, size = 1, prob = expit(Z + X))
# Example 1: non clustered data from a cross-sectional sampling design
data <- data.frame(Y, X, Z)
AF.est.cs <- AF.cs(formula = Y ~ X + Z + X * Z, data = data, exposure = "X")
summary(AF.est.cs)
# Example 2: clustered data from a cross-sectional sampling design
# Duplicate observations in order to create clustered data
id <- rep(1:n, 2)
data <- data.frame(id = id, Y = c(Y, Y), X = c(X, X), Z = c(Z, Z))
AF.est.cs.clust <- AF.cs(formula = Y ~ X + Z + X * Z, data = data,
exposure = "X", clusterid = "id")
summary(AF.est.cs.clust)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(AF)
Loading required package: survival
Loading required package: drgee
Loading required package: nleqslv
Loading required package: Rcpp
Loading required package: data.table
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AF/AF.cs.Rd_%03d_medium.png", width=480, height=480)
> ### Name: AF.cs
> ### Title: Attributable fraction for cross-sectional sampling designs.
> ### Aliases: AF.cs
>
> ### ** Examples
>
> # Simulate a cross-sectional sample
> expit <- function(x) 1 / (1 + exp( - x))
> n <- 1000
> Z <- rnorm(n = n)
> X <- rbinom(n = n, size = 1, prob = expit(Z))
> Y <- rbinom(n = n, size = 1, prob = expit(Z + X))
>
> # Example 1: non clustered data from a cross-sectional sampling design
> data <- data.frame(Y, X, Z)
> AF.est.cs <- AF.cs(formula = Y ~ X + Z + X * Z, data = data, exposure = "X")
> summary(AF.est.cs)
Call:
AF.cs(formula = Y ~ X + Z + X * Z, data = data, exposure = "X")
Estimated attributable fraction (AF) and untransformed 95% Wald CI:
AF Std.Error z value Pr(>|z|) Lower limit Upper limit
0.1258242 0.02635683 4.773876 1.807137e-06 0.07416579 0.1774826
Exposure : X
Outcome : Y
Observations Cases
1000 588
Method for confounder adjustment: Logistic regression
Formula: Y ~ X + Z + X * Z
>
> # Example 2: clustered data from a cross-sectional sampling design
> # Duplicate observations in order to create clustered data
> id <- rep(1:n, 2)
> data <- data.frame(id = id, Y = c(Y, Y), X = c(X, X), Z = c(Z, Z))
> AF.est.cs.clust <- AF.cs(formula = Y ~ X + Z + X * Z, data = data,
+ exposure = "X", clusterid = "id")
> summary(AF.est.cs.clust)
Call:
AF.cs(formula = Y ~ X + Z + X * Z, data = data, exposure = "X",
clusterid = "id")
Estimated attributable fraction (AF) and untransformed 95% Wald CI:
AF Robust SE z value Pr(>|z|) Lower limit Upper limit
0.1258242 0.02635683 4.773876 1.807137e-06 0.07416579 0.1774826
Exposure : X
Outcome : Y
Observations Cases Clusters
2000 1176 1000
Method for confounder adjustment: Logistic regression
Formula: Y ~ X + Z + X * Z
>
>
>
>
>
> dev.off()
null device
1
>