View source: R/main_package_2bwqs.R
bwqs_2 | R Documentation |
Fits Bayesian Weighted Quantile Sum (BWQS) regressions for continuous and binomial outcomes with two different mixture. This model allows two cosider the effect of two different mixture. This approach is useful when different mixture can lead opposite effect on the outcome variable.
bwqs_2( formula, mix_name_1, mix_name_2, data, q, DalpC1 = NULL, DalpC2 = NULL, chains = 1, iter = 10000, thin = 3, seed = 2019, start_value = NULL, c_int = c(0.025, 0.975), family = "gaussian" )
formula |
Object of class |
mix_name_1 |
A character vector listing the variables contributing to first mixture effect. |
mix_name_2 |
A character vector listing the variables contributing to second mixture effect. |
data |
The |
q |
An |
DalpC1 |
A |
DalpC2 |
A |
chains |
An |
iter |
An |
thin |
An |
seed |
An |
start_value |
A |
c_int |
A |
family |
A |
The function bwqs_2
uses the package rstan
which allows the connection with STAN,
a specific software, written in C++ for bayesian inference, for further information see https://mc-stan.org/.
bwqs
returns a list with two argument:
fit |
An |
summary_fit |
Table with the statistics of the parameters: mean, standard error of the mean,
standard deviation, lower and upper values for the credible interval (with credible level specified
by |
Nicolo Foppa Pedretti, Elena Colicino
#load libraries library(MASS) library(BWQS) library(Matrix) # fix the seed set.seed(456) # Sample sizes N <- 800 # Mean & SD of variables mu <- c(0,0,0,1,3,8,2,1,3,1) sd <- c(1,1,1,3,1,2,1,4,5,3) sd2 <- sd %*% t(sd) # Correlation Matrix #rho <- 0.65 corMat = matrix(runif(100), 10, 10) corMat = (corMat * lower.tri(corMat)) + t(corMat * lower.tri(corMat)) diag(corMat) <- 1 corMat = nearPD(corMat, posd.tol=1.e-04)$mat # Covariance Matrix Sigma <- sd2*corMat # Simulated dataset X <- as.data.frame(mvrnorm(N, mu=mu, Sigma = Sigma, empirical=TRUE)) colnames(X)<-c("X1","X2","X3","X4","X5","X6","X7","X8","X9","X10") #corrplot.mixed(cor(Xq), lower.col = "black", number.cex = .8) # Intercept values beta0<- 2 # Overall effect mix 1 beta1 <- 1 # Overall effect mix 2 beta2 <- (-2.8) # Weights W1 <- c(0.5,0.20,0.2,0.05,0.05) W2 <- c(0.05,0.15,0.7,0.05,0.05) # sigma sigma <- 1#sd(beta1*(Xq %*% W)) # Quantile extraction Xq <- as.matrix(quantile_split(X, mix_name = colnames(X), q=4)) # Outcome simulation (continuos) y <- rnorm(N, beta0 + beta1*(Xq[,1:5] %*% W1) + beta2*(Xq[,6:10] %*% W2), sigma) # Aggregate data in a data.frame Data <-as.data.frame(cbind(y,X)) fit_2bwqs <- bwqs_2(y ~ NULL, mix_name_1 = c("X1","X2","X3","X4","X5"), mix_name_2 = c("X6","X7","X8","X9","X10"), data = Data, q=4, family = "gaussian", iter = 10000, thin = 5) fit_2bwqs$summary_fit
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.