View source: R/BayesianEvSyn.r
BayesianEvSyn | R Documentation |
Bayesian evidence synthesis (BayesianEvSyn) aggregates the evidence for theory-based hypotheses from multiple studies that may use diverse designs to investigate the same central theory. There is also an interactive web application on my website to perform BayesianEvSyn: https://www.uu.nl/staff/RMKuiper/Websites%20%2F%20Shiny%20apps.
BayesianEvSyn(
TypeEv,
S,
Param_studies,
CovMx_studies,
N,
SameHypo,
NrHypos,
Hypo_studies,
Safeguard = "unconstrained",
Name_studies = 1:S,
PrintPlot = T
)
TypeEv |
The type of evidence-synthesis approach: Equal-evidence approach (0) or Added-evidence approach (1). In case of an equal-evidence approach, aggregating evidence from, say, 5 studies with n=100 observations is the same as obtaining evidence from 1 study (as if it was possible) with n=500 observations (like meta-analysis does). In the added-evidence approach, the aggregated evidence from, says, 5 studies is stronger than as if the data were combined (as if that was possible). |
S |
The number of (primary) studies. That is, the results (evidence) of S studies will be aggregated. |
Param_studies |
List of S 'named' vectors with the k_s (standardized) parameter estimates of interest of Study s. Thus, there are S items in the list and each item is a 'named' vector with k_s elements: the k_s number of parameter estimates relevant for that study. In case each study has the same number of parameters (k) which denote the same (in terms of hypothesis specification), Param_studies can be an S x k 'named' matrix. Note: The names of the vectors (or the column names of the S x 'k' matrix) with estimates should be used in the hypothesis specification. |
CovMx_studies |
List of the S covariance matrices of the (standardized) parameter estimates of interest (of size k_s x k_s). In case number of parameters are the same, it can also be a S*k_s x k_s matrix. Note: The columns (and rows) do not need to be named. |
N |
Vector of size S, with the sample size for each study. |
SameHypo |
Indicator whether the same hypotheses are used (1) or not (0) in all S studies. If SameHypo = 1, then the same estimates in Param_studies should have the same name. |
NrHypos |
The number of theory-based hypotheses that will be evaluated within each study (is a scalar with an integer value). |
Hypo_studies |
A vector of strings containing the NrHypos theory-based hypotheses. If SameHypo = 0, then there should be S specifications of the NrHypos theory-based hypotheses, that is S times NrHypos strings. |
Safeguard |
Indicator of which safeguard-hypothesis should be used: "unconstrained" (default; i.e., all possible theories including the one specified), "none" (only advised when set of hyptheses cover all theories), or (only when 'NrHypos = 1') "complement" (i.e., the remaining theories). |
Name_studies |
Optional. Vector of S numbers or S characters to be printed at the x-axis of the plot with posterior model probabilities (PMPs). Default: Name_studies = 1:S. |
PrintPlot |
Optional. Indicator whether plot of posterior model probabilities (PMPs) should be printed (TRUE; default) or not (FALSE). The posterior model probabilities per study are plotted and the cumulative posterior model probabilities (where those for the last study are the final ones). |
The output comprises, among other things, the cumulative and final evidence for the theory-based hypotheses.
# TO DO voeg in voorbeelden hieronder N (vector of length S) toe!
#### Note ####
#BayesianEvSyn uses the R package 'bain'; make sure that this is installed.
### Example 1: 2 ANOVA studies (Monin and Holubar) ###
### We will use the estimates of the ANOVA models
S <- 2
est_1 <- c(1.88, 2.54, 0.02)
names(est_1) <- c("group1", "group2", "group3")
vcov_est_1 <- diag(c(0.2149074, 0.2149074, 0.1408014))
est_2 <- c(0.98, 0.02, 0.27)
names(est_2) <- c("gr1", "gr2", "gr3") # Use different names to show use of different set of hypotheses
vcov_est_2 <- diag(c(0.1382856, 0.1024337, 0.0987754))
# If number of parameters differ per study (but can also be used when they are the same): make lists
#
# beta values from the analyses
Param_studies <- list(est_1, est_2)
#
# standard error of the beta's (from the S primary studies)
CovMx_studies <- list(vcov_est_1, vcov_est_2)
# Set of hypotheses for each study
# Note: in this case we could make the names of the estimates in est_1 and est_2 the same.
# In general, when not same number of parameters they names will not be the same and/or the set of hypotheses, so we use that here.
SameHypo <- 0
NrHypos <- 2
# names(est_1) # Specify restrictions using those names
H11 <- 'group1 = group2 & group2 > group3'
H12 <- 'group2 > group1 & group1 > group3'
# names(est_2) # Specify restrictions using those names
H21 <- 'gr1 = gr2 & gr2 > gr3' # Note: cannot use gr1 == gr2 > gr3
H22 <- 'gr2 > gr1 & gr1 > gr3' # Note: cannot use gr2 > gr1 > gr3
Hypo_studies <- c(H11, H12, H21, H22)
#
# Evidence synthesis
TypeEv <- 1 # Added-evidence approach
BayesianEvSyn(TypeEv, S, Param_studies, CovMx_studies, SameHypo, NrHypos, Hypo_studies)
### Example 2: 4 trust studies discussed in Kuiper et al. (2013) ###
### Different statistical models are used: linear regression, probit regression, and three-level logististic regression
S <- 4 # Number of primary studies for which the evidence for a central theory should be determined and synthesized.
# Example 1a #
# If same number of parameters per study
#
NrParam <- 1 # In this example, each study has one parameter of interest (i.e., hypotheses below address only this parameter).
# beta values from the analyses
Param_studies <- matrix(c(0.09, 0.14, 1.09, 1.781), nrow = S, ncol = NrParam)
colnames(Param_studies) <- "beta1" # Should have names and should have the same as in the hypotheses below
#
# standard error of the beta's (from the S primary studies)
CovMx_studies <- matrix(c(0.029^2, 0.054^2, 0.093^2, 0.179^2), nrow = S, ncol = NrParam) # Note: no names needed
#
# OR
# Example 1b #
# If number of parameters differ per study (but can also be used when they are the same)
#
# beta values from the analyses
est_1 <- matrix(c(0.09), nrow = 1)
colnames(est_1) <- "beta1"
est_2 <- matrix(c(0.14), nrow = 1)
colnames(est_2) <- "beta1"
est_3 <- matrix(c(1.09), nrow = 1)
colnames(est_3) <- "beta1"
est_4 <- matrix(c(1.781), nrow = 1)
colnames(est_4) <- "beta1"
Param_studies <- list(est_1, est_2, est_3, est_4)
#
# standard error of the beta's (from the S primary studies)
vcov_est_1 <- matrix(c(0.029^2), nrow = 1)
vcov_est_2 <- matrix(c(0.054^2), nrow = 1)
vcov_est_3 <- matrix(c(0.093^2), nrow = 1)
vcov_est_4 <- matrix(c(0.179^2), nrow = 1)
CovMx_studies <- list(vcov_est_1, vcov_est_2, vcov_est_3, vcov_est_4)
# Set of hypotheses for each study
# Note: in this case the same for each study
SameHypo <- 1
NrHypos <- 3
H0 <- "beta1 = 0"
Hpos <- "beta1 > 0"
Hneg <- "beta1 < 0"
Hypo_studies <- c(H0, Hpos, Hneg)
# Since this covers the whole space / covers all theories, we do not need a safeguard-hypothesis
Safeguard <- "none"
#
# Evidence synthesis
TypeEv <- 1 # Added-evidence approach
BayesianEvSyn(TypeEv, S, Param_studies, CovMx_studies, SameHypo, NrHypos, Hypo_studies, Safeguard)
### Example 3: 3 'fictional' studies; for ease, all 3 use linear regression ###
### where continuous predictor variable need to be standardized and
### where we will the complement of our theory as competing hypothesis ###
S <- 3
ratio <- c(1,1.1,1.2)
n <- c(30, 50, 100)
# Generate data1
n1 <- n[1]
x11 <- rnorm(n1)
x12 <- rnorm(n1)
x13 <- rnorm(n1)
data <- cbind(x11, x12, x13)
# Standardize data - since parameters for continuous variables will be compared
data1 <- as.data.frame(scale(data))
y1 <- ratio[1]*data1$x11 + ratio[2]*data1$x12 + ratio[3]*data1$x13 + rnorm(n1)
# Note: since there is one outcome, the outcome does not need to be standardized
# Fit regression model
fit.lm1 <- lm(y1 ~ 1 + x11 + x12 + x13, data = data1)
# Generate data2
n2 <- n[2]
x21 <- rnorm(n2)
x22 <- rnorm(n2)
x23 <- rnorm(n2)
data <- cbind(x21, x22, x23)
# Standardize data - since parameters for continuous variables will be compared
data2 <- as.data.frame(scale(data))
y2 <- ratio[1]*data2$x21 + ratio[2]*data2$x22 + ratio[3]*data2$x23 + rnorm(n2)
# Note: since there is one outcome, the outcome does not need to be standardized
# Fit regression model
fit.lm2 <- lm(y2 ~ 1 + x21 + x22 + x23, data = data2)
# Generate data3
n3 <- n[3]
x31 <- rnorm(n3)
x32 <- rnorm(n3)
x33 <- rnorm(n3)
data <- cbind(x31, x32, x33)
# Standardize data - since parameters for continuous variables will be compared
data3 <- as.data.frame(scale(data))
y3 <- ratio[1]*data3$x31 + ratio[2]*data3$x32 + ratio[3]*data3$x33 + rnorm(n3)
# Note: since there is one outcome, the outcome does not need to be standardized
# Fit regression model
fit.lm3 <- lm(y3 ~ 1 + x31 + x32 + x33, data = data3)
# Extract estimates and their covariance matrix (per study)
est_1 <- coef(fit.lm1)
est_2 <- coef(fit.lm2)
est_3 <- coef(fit.lm3)
vcov_est_1 <- vcov(fit.lm1)
vcov_est_2 <- vcov(fit.lm2)
vcov_est_3 <- vcov(fit.lm3)
#
## If same number and type of parameters per study (since they will obtain the same name)
NrParam <- length(est_1)
# Parameter estimate values from the S primary studies
Param_studies <- matrix(c(est_1, est_2, est_3), byrow = T, nrow = S, ncol = NrParam)
colnames(Param_studies) <- c("intercept", "x1", "x2", "x3")
# standard error of the beta's (from the S primary studies)
CovMx_studies <- matrix(c(vcov_est_1, vcov_est_2, vcov_est_3), byrow = T, nrow = S*NrParam, ncol = NrParam) # Note: no names needed
# Set of hypotheses for each study
# Note: in this case the same for each study
SameHypo <- 1
# colnames(est) # Specify restrictions using those names
H1 <- 'x1 < x2 & x2 < x3' # Note: cannot use x1 < x2 < x3
# Since estimates of continuous variables are compared in our theory, we standardized the data before to obtain comparable estimates.
# Since no restrictions on intercept, you can leave it out in 'Param_studies' and 'CovMx_studies'; this does not impact the posterior model probabilities.
NrHypos <- 1
# Since we have only one theory-based hypothesis, we will use the (more powerful) complement of the hypothesis (Vanbrabant, Van Loey, Kuiper, 2019).
# The complement represents the remaining 11 theories, while the unconstrained reflects all 12 possible theories including H1.
Safeguard <- "complement"
#
# Evidence synthesis
TypeEv <- 1 # Added-evidence approach
BayesianEvSyn(TypeEv, S, Param_studies, CovMx_studies, SameHypo, NrHypos, Hypo_studies = H1, Safeguard)
# Change labels on x-axis in PMPs plot #
# For example, let us say that the studies come from the years 2016, 2017, 2019.
# Because of unequal spacing, you may want to use numbers instead of characters:
Name_studies <- c(2016, 2017, 2019)
BayesianEvSyn(TypeEv, S, Param_studies, CovMx_studies, SameHypo, NrHypos, Hypo_studies = H1, Safeguard, Name_studies)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.