Design Matrix in brainGraph_GLM

36 views
Skip to first unread message

kcampbell

unread,
Aug 13, 2020, 5:33:47 PM8/13/20
to brainGraph-help
Hello Chris, 

I've been working through your brainGraph R user guide - thank you for this, it's been tremendously helpful so far!!

My analysis is on between-group differences in several graph-level and vertex-level metrics. I have three groups (group 1 is the reference group in the coding below). 

I have a question regarding brainGraph_GLM. I noticed that I obtain very different results with the following two scenarios: 

1. Create a design matrix with brain_GLM_design, then supply this to the X argument in brainGraph_GLM. 
> X.design.effect <- brainGraph_GLM_design(X, coding = 'effect')
> X.con.effect <- matrix(c(0,-2,-1,0,-1,-2,0,1,-1), nrow = 3, ncol = 3, byrow = T) 
> summary(m1 <- brainGraph_GLM(g.list = g.glm, covars = covar.sna[,1:2],
measure = "transitivity", X = X.design.effect, con.mat = X.con.effect, level = 'graph',
con.type = 't', alternative = 'greater')) 

...versus:

2. Provide design matrix information to arguments passed to brainGraph_GLM_design in the brainGraph_GLM function.
> X.con.effect <- matrix(c(0,-2,-1,0,-1,-2,0,1,-1), nrow = 3, ncol = 3, byrow = T) 
> summary(m2 <- brainGraph_GLM(g.list = g.glm, covars = covar.sna[,1:2],
measure = "transitivity", coding = 'effect', con.mat = X.con.effect, level = 'graph',
con.type = 't', alternative = 'greater'))

When I compared m1$X vs. m2$X, I noticed that m2$X is no longer in the same order as 'Study.ID' (but m1$X retains the correct order). This occurs for when using the 'dummy' coding method as well. I'm assuming this is the reason for the differing results; however, which outcome is the accurate one?

Thanks for your help!

Kayleigh


Chris Watson

unread,
Aug 13, 2020, 5:55:04 PM8/13/20
to brainGr...@googlegroups.com
It depends on what the "Study.ID" variable type in "covar.sna" is, and what the ordering is. As well as the ordering in "g.glm". I would tend to trust the 2nd method more, as it *should* reorder data as-needed. If you are unsure you can send me *all* data that is required to run your code. In particular, "g.glm", "covar.sna".

Another thing I notice is that under 1) you supply "X" to create the design matrix; what is the "X" variable?

Chris

--
You received this message because you are subscribed to the Google Groups "brainGraph-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/83eac3fa-ec96-4171-8ea1-f2f1d62ba9b7n%40googlegroups.com.

kcampbell

unread,
Aug 13, 2020, 7:35:01 PM8/13/20
to brainGraph-help
Hi Chris, 

Thanks for your response!

'Study.ID' is class character, ordered by group. The ordering of subjects in 'Study.ID' in X matches the order of subjects g.glm. 
X <- covar.sna[,1:2] # columns 1 and 2 are 'Study.ID' and 'Group', respectively. 
setkey(X, Group, Study.ID)
X[, levels(Group)] # three level, first one is reference group in design and contrast metrics.

I just tried further exploring this question by comparing brainGraph_GLM results to the results from R's lm base function. I used dummy coding instead to match how R treats the 'Group' variable ('contr.treatment').

To create a lm..
> y <- sapply(g.glm, graph_attr, name = 'transitivity') # pulled out graph-level attributes from g.glm
> Xy <- cbind(X, y)
> summary(m3 <- lm(y ~ Group, data = Xy))
> m3$contrasts$Group
[1] "contr.treatment" 
> contrasts(covar.sna$Group, sparse = F, contrasts = T) 
            Group2  Group3
Group1     0          0
Group2     1          0
Group3     0          1

I then created a design and contrast matrix with dummy coding. Only difference is that I have ncol(design matrix) = ncol(contrast matrix) - accounts for the intercept. 
> X.design.dummy <- brainGraph_GLM_design(X, coding = 'dummy')
> X.con.dummy <- matrix(c(1,0,0,0,1,0,0,0,1), nrow = 3, ncol = 3, byrow = T) 

And then generated results for Scenarios 1 and 2 in my original question (but a two-sided test this time to match what R's lm did):
1. Supply design matrix (as X argument) to brainGraph_GLM
> summary(m4 <- brainGraph_GLM(g.list = g.glm, covars = covar.sna[,1:2], measure = "transitivity", X = X.design.dummy, con.mat = X.con.dummy, level = 'graph', con.type = 't', alternative = 'two.sided')) 

2. Provide desired design matrix type to 'codinng' argument passed to brainGraph_GLM_design in the brainGraph_GLM function.
> summary(m5 <- brainGraph_GLM(g.list = g.glm, covars = covar.sna[,1:2], measure = "transitivity", coding = 'dummy', con.mat = X.con.dummy, level = 'graph', con.type = 't', alternative = 'two.sided'))

The results from m3 (R's lm output) and m5 (brainGraph_GLM with 'coding' supplied) are identical!

Is there a potential bug in X argument in brainGraph_GLM? 
I am performing a 2x3 ANOVA (Sex x Group interaction) in my next set of analyses. Should I just avoid using the X argument all together and put all information directly into brainGraph_GLM's arguments passed to brainGraph_GLM_design (i.e. coding, int, mean.center, binarize..)?

Thanks for your help again!

Kayleigh

Chris Watson

unread,
Aug 13, 2020, 8:09:05 PM8/13/20
to brainGr...@googlegroups.com
I would say that yes, there may have been a bug when passing a design matrix via the "X" argument. In the upcoming v3.0, these kinds of bugs should be fixed. And the function runs significantly faster (assuming you are doing permutations). Thanks for digging into the problem.

Chris

Reply all
Reply to author
Forward
0 new messages