This is a follow-up to the vignette“ThreeWays to Test the Same Hypothesis”. A new feature,pcor_sum, was added toBGGM that allowsfor testing partial correlation sums. This differs from the Bayes factorapproach (“Approach #3”), in that only the posterior distribution isused to determine whether there is a difference in the sums.
# need the developmental versionif (!requireNamespace("remotes")) { install.packages("remotes") } # install from githubremotes::install_github("donaldRwilliams/BGGM")library(BGGM)This first example looks at one group, where a sum is tested withinthe same ptsd network. I focus on the relations between there-experiencing (B) and avoidance (C)communities. In particular, the sum of relations between the “Intrusion”(5 nodes) community and the “Avoidance” (two nodes) community istested.
For the avoidance symptom “avoidance of thoughts”C1,this can be written inR code with
# ptsdY <- ptsd# paste together sumspaste0(colnames(Y)[1:5], "--C1", collapse = " + ")#> "B1--C1 + B2--C1 + B3--C1 + B4--C1 + B5--C1"whereas, for the avoidance symptom “avoidance of reminders”(C2), this is written as
paste0(colnames(Y)[1:5], "--C2", collapse = " + ")#> "B1--C2 + B2--C2 + B3--C2 + B4--C2 + B5--C2"Note that typically this would have to be written out.paste0 was used in this case to avoid typing out all of therelations.
Here an ordinal GGM is fitted
fit <- estimate(Y+1, type = "ordinal", iter = 1000)where the+1 changes the first category from 0 to 1(required).
The next step is to use thepcor_sum function. First, Icombine the sums into one string separated with;.
# sum 1sum1 <- paste0(colnames(Y)[1:5], "--C1", collapse = " + ")# sum 2sum2 <- paste0(colnames(Y)[1:5], "--C2", collapse = " + ")# paste togethersums <- paste(sum1, sum2, sep = ";")# printsums#> "B1--C1 + B2--C1 + B3--C1 + B4--C1 + B5--C1;B1--C2 + B2--C2 + B3--C2 + B4--C2 + B5--C2"Nextpcor_sum is used
test_sum <- pcor_sum(fit, relations = sums)# printtest_sum# BGGM: Bayesian Gaussian Graphical Models # --- # Network Stats: Posterior Sum# Posterior Samples: 1000 # --- # Estimates # # Sum: # Post.mean Post.sd Cred.lb Cred.ub# B1--C1+B2--C1+B3--C1+B4--C1+B5--C1 0.215 0.096 0.034 0.404# B1--C2+B2--C2+B3--C2+B4--C2+B5--C2 0.334 0.097 0.145 0.514# --- # # Difference:# B1--C1+B2--C1+B3--C1+B4--C1+B5--C1 - B1--C2+B2--C2+B3--C2+B4--C2+B5--C2 # # Post.mean Post.sd Cred.lb Cred.ub Prob.greater Prob.less# -0.119 0.145 -0.409 0.173 0.205 0.795# ---Prob.greater is the posterior probability that the firstsum is larger than the second sum.
The objecttest_sum can then be plotted. Note thisreturns three plots, but only the difference is shown here
plot(test_sum)$diffThe histogram is not very smooth in this case becauseiter = 1000, but this of course can be changed.
This next example is for two groups. The data are calledbfi and they are in theBGGM package. Icompare a sum of two relations for questions measuring agreeableness inmales and females. The relations tested are as follows
sums <- c("A3--A4 + A4--A5")whereA1 is “know how to comfort others”,A4 is “love children”, andA5 is “make peoplefeel at ease”.
The next step is to fit the models
# dataY <- bfi# malesY_males <- subset(Y, gender == 1, select = -c(education, gender))[,1:5]# femalesY_females <- subset(Y, gender == 2, select = -c(education, gender))[,1:5]fit_female <- estimate(Y_females, seed = 2)# fit malesfit_male <- estimate(Y_males, seed = 1)Then test the sum
test_sum <- pcor_sum(fit_female, fit_male, relations = sums)# printtest_sum#> BGGM: Bayesian Gaussian Graphical Models #> --- #> Network Stats: Posterior Sum#> Posterior Samples: 5000 #> --- #> Estimates #> #> Sum: #> Post.mean Post.sd Cred.lb Cred.ub#> g1: A3--A4+A4--A5 0.292 0.026 0.241 0.342#> g2: A3--A4+A4--A5 0.305 0.036 0.234 0.375#> --- #> #> Difference:#> g1: A3--A4+A4--A5 - g2: A3--A4+A4--A5 #> #> Post.mean Post.sd Cred.lb Cred.ub Prob.greater Prob.less#> -0.014 0.045 -0.1 0.074 0.386 0.614#> ---For a kind of sanity check, here is the sum for the male groupobtained from the point estimates.
pcor_mat(fit_male)["A3", "A4"] + pcor_mat(fit_male)["A4", "A5"] #> 0.305This matches the output.
By default, the print function forpcor_sum provides 95% credible intervals. This can be changed by directly using the printfunction, for exampleprint(test_sum, cred = 0.99),provides 99 % credible intervals.
Currently, this function only supports sums, due to this being ofinterest for the psychological network literature in particular. Thiscan be extended to accommodate multiplication, subtraction, testingvalues other than zero, etc. Please make a feature request at eithergithub orBGGM-usersgroup.