Learn R Programming

SBSA (version 0.2.3)

fitSBSA: Fitting Simplified Bayesian Sensitivity Models

Description

Conducts sensitivity analysis over a model involving unobserved and poorly measured covariates.

Usage

fitSBSA(y, x, w, a, b, k2=NULL, el2=NULL, cor.alpha=0, sd.alpha=1e+06, nrep=5000, sampler.jump=c(alpha=.15, beta.z=.1, sigma.sq=.5, tau.sq=.05, beta.u.gamma.x=.3, gamma.z=.15), q.steps=25, family=c("continuous", "binary"))

Arguments

y
a vector of outcomes
x
a (standardized) vector of exposures
w
a (standardized) matrix of noisy measurements
a
parameter of the prior for magnitude of measurement error on confounder $Z_j$
b
parameter of the prior for magnitude of measurement error on confounder $Z_j$
k2
(optional) magnitude of prior uncertainty about $(U|X, Z)$ regression coefficients
el2
(optional) residual variance for $(U|X, Z)$
cor.alpha
(optional) value of the $\rho$ parameter of the bivariate normal prior for $\alpha$
sd.alpha
(optional) value of the $\sigma$ parameter of the bivariate normal prior for $\alpha$
nrep
number of MCMC steps
sampler.jump
named vector of standard deviation of
  • alpha jump for block reparametrizing $\alpha$
  • beta.z jump for block reparametrizing $\beta_z$
  • sigma.sq (continuous case only) jump for block reparametrizing $\sigma^2$
  • tau.sq jump for block reparametrizing $\tau^2$
  • beta.u.gamma.x jump for block reparametrizing $\beta_u$ and $\gamma_z$
  • gamma.z jump for block reparametrizing $\gamma_z$
q.steps
number of steps in numeric integration of likelihood (only used for binary outcome variables)
family
a character string indicating the assumed distribution of the outcome. Valid values are "continuous", the default, or "binary".

Value

acc
a vector of counts of how many times each block sampler successfully made a jump. Vector elements are named by their block, as in the sampler.jump argument.
alpha
a $nrep \times\ 2$ matrix of the value of $\alpha$ parameter at each MCMC step
beta.z
a $nrep \times\ p$ matrix of the value of $\beta_z$ parameter at each MCMC step
gamma.z
a $nrep \times\ p$ matrix of the value of $\gamma_z$ parameter at each MCMC step
tau.sq
a $nrep \times\ p$ matrix of the value of $\tau^2$ parameter at each MCMC step
gamma.x
a vector of the value of $\gamma_x$ parameter at each MCMC step
beta.u
a vector of the value of $\beta_u$ parameter at each MCMC step
sigma.sq
a vector of the value of $\sigma^2$ parameter at each MCMC step

Details

The function uses a simplified Bayesian sensitivity analysis algorithm that models the outcome variable $Y$ in terms of exposure $X$ and confounders $Z=(Z_1,\ldots,Z_p$ and $U=(U_1,\ldots,U_q)$, where $U$s are unobserved, and $Z$s are measured imprecisely as $W$s. (I.e., the observed data is $(Y, X, W)$.) Parameters of the model are then estimated using MCMC with reparametrizing block-sampling. The estimated parameters are as follows:
  • $\tau$: $(W|Y, U, Z, X) \sim N_p(Z, diag(\tau^2))$
  • $\gamma_x, \gamma_z$: $(U|X, Z) \sim N(\gamma_x X + \gamma_z' Z)$
  • $\alpha, \beta_u, \beta_z, \sigma$: $(Y|U, Z, X) \sim N(\alpha_0 + \alpha_x X + \beta_u U + \beta_z' Z, \sigma^2)$

References

Gustafson, P. and McCandless, L. C and Levy, A. R. and Richardson, S. (2010) Simplified Bayesian Sensitivity Analysis for Mismeasured and Unobserved Confounders. Biometrics, 66(4):1129--1137. DOI: 10.1111/j.1541-0420.2009.01377.x

Examples

Run this code
### simulated data example
n <- 1000

### exposure and true confounders equi-correlated with corr=.6
tmp <- sqrt(.6)*matrix(rnorm(n),n,5) +
       sqrt(1-.6)*matrix(rnorm(n*5),n,5)
x <- tmp[,1]
z <- tmp[,2:5]

### true outcome relationship
y <- rnorm(n, x + z%*%rep(.5,4), .5)


### first two confounders are poorly measured, ICC=.7, .85
### third is correctly measured, fourth is unobserved
w <- z[,1:3]
w[,1] <- w[,1] + rnorm(n, sd=sqrt(1/.7-1))
w[,2] <- w[,2] + rnorm(n, sd=sqrt(1/.85-1))

### fitSBSA expects standardized exposure, noisy confounders
x.sdz <- (x-mean(x))/sqrt(var(x))
w.sdz <- apply(w, 2, function(x) {(x-mean(x)) / sqrt(var(x))} )

### prior information: ICC very likely above .6, mode at .8
### via Beta(5,21) distribution
fit <- fitSBSA(y, x.sdz, w.sdz, a=5, b=21, nrep=10000,
               sampler.jump=c(alpha=.02, beta.z=.03,
                              sigma.sq=.05, tau.sq=.004,
                              beta.u.gamma.x=.4, gamma.z=.5))

### check MCMC behaviour
print(fit$acc)
plot(fit$alpha[,2], pch=20)

### inference on target parameter in original scale
trgt <- fit$alpha[1001:10000,2]/sqrt(var(x))
print(c(mean(trgt), sqrt(var(trgt))))

Run the code above in your browser using DataLab