Degrees of Freedom and Effect Size for brainGraph_GLM Outputs

15 views
Skip to first unread message

Lindsay

unread,
Aug 29, 2019, 11:09:40 AM8/29/19
to brainGraph-help
Hi,

I'm just in the process of writing up my results from a functional connectivity analysis using brainGraph. Re values I would typically report, I was wondering why degrees of freedom aren't included in the brainGraph_GLM$DT? Somewhat similarly, is anyone aware of an R function for calculating effect size (cohen's d in particular) that would accept a brainGraph function or output object? Thanks very much in advance!

Best,

Lindsay 


Chris Watson

unread,
Aug 29, 2019, 11:55:49 PM8/29/19
to brainGr...@googlegroups.com
Hi Lindsay, I never included "df" in the data table because it is very
simple to calculate, but I certainly considered it before. It is
something I can include in the future; I plan on (i.e., next major
release) including an element "df.residual" with the outputs, and
write a simple method for extracting it which will mimic other of R's
stats functions (e.g., lm, glm, etc.).

In the meantime, you can calculate it as nrow(X) - ncol(X) where X is
the design matrix.

For Cohen's D, you can calculate it as follows:

fit <- RcppEigen::fastLmPure(X, y, method=2)
coeffs <- fit$coefficients
fitted_values <- X %*% coeffs
residuals <- y - fitted_values
sigma.squared <- crossprod(residuals) / (nrow(X) - qr(con.mat)$rank)
cohen <- gamma / sqrt(sigma.squared)

Where "gamma" is the contrast of parameter estimates, which is reported in "DT".

Of course this is quite verbose, but I am writing methods for all of
these so in the future you will only have to call, e.g., effect_size
<- cohen.d(glm_output)

Please let me know if you have any trouble with the code; I have not tested it.
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/4062e026-d237-4a9a-bd4d-ba1fb5592792%40googlegroups.com.
>

Chris Watson

unread,
Aug 30, 2019, 12:22:57 AM8/30/19
to brainGr...@googlegroups.com
Hi Lindsay, actually it should be simpler.

fit <- fastLmPure(X, y, method=2)
resids <- fit$residuals
sigma.squared <- fit$s
cohen <- gamma / sqrt(sigma.squared)

If you have vertex-level statistics, you will have to loop over "y", i.e.,

fits <- apply(y, 2, function(x) fastLmPure(X, x, method=2))
resids <- sapply(fits, with, residuals)
sigma.squared <- sapply(fits, with, s)
gamma <- result$DT[, gamma]
cohen <- sapply(seq_along(gamma), function(x) gamma[x] / sqrt(sigma.squared[x]))

I think that should work if you have a single contrast. If you have
multiple, you can wrap all of the above code in a "for" loop, by
looping over the "contrast" index:

# Each element of "cohen" is for a different contrast
cohen <- vector('list', nrow(result$con.mat))
for (i in seq_along(cohen)) {
...
gamma <- result$DT[contrast == i, gamma]
cohen[[i]] <- gamma / sqrt(sigma.squared)
}

There are "cleaner" ways to do this, but off the top of my head this
should work fine.
Chris

Lindsay

unread,
Aug 30, 2019, 4:26:11 PM8/30/19
to brainGraph-help
Hi Chris,

Thanks so much for your response. That makes sense re df, and thanks for the code regarding cohen's d. I haven't tried it yet, but will shortly. I appreciate the help, and am a big fan of the package.

Best,

Lindsay

Chris Watson

unread,
Aug 30, 2019, 4:54:40 PM8/30/19
to brainGr...@googlegroups.com
Thanks for the kind words. Please feel free to request any other
features or statistics you would find useful, and I will try to
implement them.

Chris
>> >> email to brainGr...@googlegroups.com <javascript:>.
>> >> To view this discussion on the web visit
>> >>
>> https://groups.google.com/d/msgid/brainGraph-help/4062e026-d237-4a9a-bd4d-ba1fb5592792%40googlegroups.com.
>>
>>
>> >>
>> >
>>
>
> --
> 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/f4c32384-609d-477d-b892-cbbc9faf9363%40googlegroups.com.
>
Reply all
Reply to author
Forward
0 new messages