bws {bws} | R Documentation |
Bayesian Weighted Sums
Description
Fits a Bayesian Weighted Sums as described in Bayesian Weighted Sums: A Flexible Approach to Estimate Summed Mixture Effects. Ghassan B. Hamra 1, Richard F. MacLehose, Lisa Croen, Elizabeth M. Kauffman and Craig Newschaffer. 2021. International Journal of Environmental Research and Public Health. An extension for binary outcome is included.
Usage
bws(iter, y, X, Z = NULL, alpha = NULL, family = "gaussian", ...)
Arguments
iter |
Number of Hamiltonian Monte Carlo iterations |
y |
Am n-vector of outcomes |
X |
An n-by-p matrix of mixtures to be weighted-summed |
Z |
Default NULL. A matrix of confounders whose linear effects are estimated |
alpha |
A p-vector of hyperparameters for the Dirichlet prior on the weights. Default to be a vector of 1's. |
family |
A string "gaussian" for linear regression and "binomial" for logistic regression |
... |
Additional arguments for |
Value
An object of class stanfit
returned by rstan::sampling
Examples
N <- 50; P <- 3; K <- 2
X <- matrix(rnorm(N*P), N, P)
Z <- matrix(rnorm(N*K), N, K) # confounders
theta0 <- 0.5; theta1 <- 1.25
w <- c(0.3, 0.2, 0.5)
beta <- c(0.5, 0.3)
y <- theta0 + theta1*(X%*%w) + Z%*%beta + rnorm(N)
fit <- bws::bws(iter = 2000, y = y, X = X, Z = Z, family = "gaussian",
chains = 2, cores = 2, refresh = 0)