Error: ncol(X) == ncol(con.mat) is not TRUE

22 views
Skip to first unread message

özgün özalay

unread,
Jun 4, 2018, 7:19:39 PM6/4/18
to brainGraph-help
Hi again Chris;

I see you updated the package which is very good but also has a learning curve for me. This time my question is very simple;

After creating graph list "g" as you instructed on user guide, I created contrast matrix for simple group comparison with


con.mat <- matrix(c(0, -2), nrow=1, dimnames=list('Control > Patient'))


I created data table X with Study.ID and Group variables with

X <- covars[, 1:2]


Then when i try summary function with brainGraph_GLM, dummy coding

summary(brainGraph_GLM(g, measure='E.nodal.wt', covars=covars[, 1:2], + coding='dummy', con.mat=con.mat, alt='greater'))





I get this error;

Error: ncol(X) == ncol(con.mat) is not TRUE




But ncols(X)=2 and ncols(con.mat)=2    



This is a very simple design, what am i doing wrong?   :/

I am using brainGraph ver 2.20 from GitHub

Best wishes
Ozgun

Chris Watson

unread,
Jun 5, 2018, 12:21:53 AM6/5/18
to brainGr...@googlegroups.com
It's possibly an error when using "covars[, 1:2]" to create the design matrix. Is "covars" a "data.table" object?
When you choose "coding='dummy'", this adds a column for the Intercept term; if the first 2 columns of "covars" are, for example, "Study.ID" and "Group", then I don't know what is causing the error. But if the "Group" column has data type "factor", and there are more than 2 levels in the factor, this could be causing the error. Please let me know the following:

1. What does "covars" look like?
2. What does the output of: brainGraph_GLM_design(covars[, 1:2], coding='dummy') look like, as well?

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-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/f3b38e29-68bb-4863-9a8c-8961e48ddfb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

özgün özalay

unread,
Jun 5, 2018, 12:42:23 AM6/5/18
to brainGr...@googlegroups.com

covars is a data.table object, i am attaching it. You can find the output below.

I finished permutation testing routine without an issue for both vertex and graph-level attr. 

If you want additional files please let me know.

Best
Ozgun

> brainGraph_GLM_design(covars[, 1:2], coding='dummy')
      Intercept Study.ID GroupPatient
 [1,]         1        1            0
 [2,]         1        2            0
 [3,]         1        3            0
 [4,]         1        4            0
 [5,]         1        5            0
 [6,]         1        6            0
 [7,]         1        7            0
 [8,]         1        8            0
 [9,]         1        9            0
[10,]         1       10            0
[11,]         1       11            0
[12,]         1       12            0
[13,]         1       13            0
[14,]         1       14            0
[15,]         1       15            0
[16,]         1       16            0
[17,]         1       17            0
[18,]         1       18            0
[19,]         1       19            0
[20,]         1       20            0
[21,]         1       21            0
[22,]         1       22            0
[23,]         1       23            0
[24,]         1       24            0
[25,]         1       25            0
[26,]         1       26            0
[27,]         1       27            0
[28,]         1       28            0
[29,]         1       29            0
[30,]         1       30            0
[31,]         1       31            0
[32,]         1       32            0
[33,]         1       33            0
[34,]         1       34            0
[35,]         1       35            0
[36,]         1       36            0
[37,]         1       37            0
[38,]         1       38            0
[39,]         1       39            0
[40,]         1       40            0
[41,]         1       41            0
[42,]         1       42            0
[43,]         1       43            0
[44,]         1       44            0
[45,]         1       45            0
[46,]         1       46            0
[47,]         1       47            0
[48,]         1       48            0
[49,]         1       49            0
[50,]         1       50            0
[51,]         1       51            0
[52,]         1       52            0
[53,]         1       53            0
[54,]         1       54            0
[55,]         1       55            0
[56,]         1       56            0
[57,]         1       57            1
[58,]         1       58            1
[59,]         1       59            1
[60,]         1       60            1
[61,]         1       61            1
[62,]         1       62            1
[63,]         1       63            1
[64,]         1       64            1
[65,]         1       65            1
[66,]         1       66            1
[67,]         1       67            1
[68,]         1       68            1
[69,]         1       69            1
[70,]         1       70            1
[71,]         1       71            1
[72,]         1       72            1
[73,]         1       73            1
[74,]         1       74            1
[75,]         1       75            1
[76,]         1       76            1
[77,]         1       77            1
[78,]         1       78            1
[79,]         1       79            1
[80,]         1       80            1
[81,]         1       81            1
[82,]         1       82            1
[83,]         1       83            1
[84,]         1       84            1
[85,]         1       85            1
[86,]         1       86            1
[87,]         1       87            1
[88,]         1       88            1
[89,]         1       89            1


On Tue, Jun 5, 2018 at 7:21 AM Chris Watson <cwa...@alum.mit.edu> wrote:
It's possibly an error when using "covars[, 1:2]" to create the design matrix. Is "covars" a "data.table" object?
When you choose "coding='dummy'", this adds a column for the Intercept term; if the first 2 columns of "covars" are, for example, "Study.ID" and "Group", then I don't know what is causing the error. But if the "Group" column has data type "factor", and there are more than 2 levels in the factor, this could be causing the error. Please let me know the following:

1. What does "covars" look like?
2. What does the output of: brainGraph_GLM_design(covars[, 1:2], coding='dummy') look like, as well?

Chris
On Mon, Jun 4, 2018 at 6:19 PM, özgün özalay <ozgun....@gmail.com> wrote:
Hi again Chris;

I see you updated the package which is very good but also has a learning curve for me. This time my question is very simple;

After creating graph list "g" as you instructed on user guide, I created contrast matrix for simple group comparison with


con.mat <- matrix(c(0, -2), nrow=1, dimnames=list('Control > Patient'))


I created data table X with Study.ID and Group variables with

X <- covars[, 1:2]


Then when i try summary function with brainGraph_GLM, dummy coding

summary(brainGraph_GLM(g, measure='E.nodal.wt', covars=covars[, 1:2], + coding='dummy', con.mat=con.mat, alt='greater'))





I get this error;

Error: ncol(X) == ncol(con.mat) is not TRUE




But ncols(X)=2 and ncols(con.mat)=2    



This is a very simple design, what am i doing wrong?   :/

I am using brainGraph ver 2.20 from GitHub

Best wishes
Ozgun

--
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 post to this group, send email to brainGr...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "brainGraph-help" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brainGraph-help/zdk3F6P8LAc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brainGraph-he...@googlegroups.com.
To post to this group, send email to brainGr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/CAHVz74jtSEs8_Z-uBEAUPo3_B32hZ4%2Bt6e_u1mtvSbdhnPO1PQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Department of Neuroscience
Institute of Health Sciences
Ege University, Izmir, Turkey

Department of Psychiatry
Ege University Hospital, Izmir, Turkey
covars.csv

Chris Watson

unread,
Jun 5, 2018, 1:15:49 AM6/5/18
to brainGr...@googlegroups.com
Ah, so this is a "bug" in the code actually. I wrote the functions to expect "Study.ID" to be a *character* vector, and not integer/numeric. I will update the code for the next version, but in the meantime, you should instead use:

covars[, 'Group']

(if it is a "data.table" object, which it should be). Try that out and let me know if it works.
Chris

To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "brainGraph-help" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brainGraph-help/zdk3F6P8LAc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brainGraph-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.


--
Department of Neuroscience
Institute of Health Sciences
Ege University, Izmir, Turkey

Department of Psychiatry
Ege University Hospital, Izmir, Turkey

--
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-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/CADjkCccVHs_Tx9uu%3DinThv1PUSpNj31mx%3DtUeHHYX2R_e0RrGw%40mail.gmail.com.

özgün özalay

unread,
Jun 5, 2018, 8:40:55 AM6/5/18
to brainGraph-help
I see. Here are the outputs i get for 2 different commands after suggested X <- covars[, 'Group'] (now i have 1 col X file with only 'Group' information)

summary(brainGraph_GLM(g, measure = 'E.nodal.wt', covars = covars[, 'Group'], coding = 'dummy', con.mat= con.mat, alt='greater'))


gives,

Error in `[.data.table`(covars, !complete.cases(covars), Study.ID) : 
  j (the 2nd argument inside [...]) is a single symbol but column name 'Study.ID' is not found. Perhaps you intended DT[, ..Study.ID]. This difference to data.frame is deliberate and explained in FAQ 1.1.

and


summary(brainGraph_GLM(g, measure = 'E.nodal.wt', covars = covars[, 1:2], coding = 'dummy', con.mat= con.mat, alt='greater'))


gives same error again


Error: ncol(X) == ncol(con.mat) is not TRUE


I will replace Study.IDs with characters to see if i can reproduce this error again. By the way, new version has a much tidier coding, great job really, thank you!

Best wishes
Ozgun 
To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.
To post to this group, send email to brainGr...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "brainGraph-help" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brainGraph-help/zdk3F6P8LAc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brainGraph-he...@googlegroups.com.
To post to this group, send email to brainGr...@googlegroups.com.


--
Department of Neuroscience
Institute of Health Sciences
Ege University, Izmir, Turkey

Department of Psychiatry
Ege University Hospital, Izmir, Turkey

--
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 post to this group, send email to brainGr...@googlegroups.com.

Chris Watson

unread,
Jun 5, 2018, 10:10:44 AM6/5/18
to brainGr...@googlegroups.com
Yes, sorry; remove the quotation marks surrounding "Group". So it should just be:

covars[, Group]

To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/de54b338-31d3-4bc5-8b99-ed8826743300%40googlegroups.com.

Chris Watson

unread,
Jun 5, 2018, 10:40:20 AM6/5/18
to brainGr...@googlegroups.com
And you are correct, for now you will have to convert "Study.ID" to be a character vector. This can simply be:
covars[, Study.ID := as.character(Study.ID)]

Thank you for the comments! I had been trying to focus more on cleaner, more efficient code to improve on the package.

Chris

özgün özalay

unread,
Jun 7, 2018, 9:50:59 AM6/7/18
to brainGraph-help
I've converted Study.ID to the character but now i need to ask something else;

In this example, you gave on the user guide

brainGraph_GLM(g.glm, measure='E.nodal.wt', covars=covars.dti[, 1:2],
coding
='effects', con.mat=con.mat, alt='greater')))

What exactly is this g.glm object? 

Is it different from that we create in, 
g <- lapply(corrs, function(x)
apply
(x$r.thresh, 3, function(y)
graph_from_adjacency_matrix
(x$R * y, mode='undirected', diag=F, weighted=T)))




g
<- Map(function(x, y) llply(x, set_brainGraph_attr, atlas=atlas,
modality
=modality, group=y, .progress='text'),
g
, as.list(groups))

I know that g is a list with Control and Patients, do we need to convert to another format? If i provide my "g" as avariable to braingraph_GLM i get an error 
Error in vcount(g.list[[1]]) : Not a graph object

I'm sure i am missing something again,
Any suggestions?

Best
Ozgun

Chris Watson

unread,
Jun 7, 2018, 12:40:46 PM6/7/18
to brainGr...@googlegroups.com
Hi Ozgun, "g.glm" was just used as an example input. It is a "flat" list object that is created by concatenating the graph objects from multiple subject groups at a single threshold/density. So, for example, if you created the object "g" as in the code, and let's say you have 3 groups at 10 thresholds each, you could create a similar object as:

g.glm <- c(g[[1]][[5]], g[[2]][[5]])

And this would perform an analysis including subjects from groups 1 and 2, with graphs from the 5th threshold/density. However, it looks like you are using structural covariance networks; these often do not produce single-subject graphs, which means the function will not work for that type of data. However, if you *do* have single-subject graphs, it should work.

Does this explanation clarify the issue? Please let me know if it works.
Chris

To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-help+unsubscribe@googlegroups.com.
To post to this group, send email to brainGraph-help@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/babdabff-d180-447c-bc57-db23e2f42289%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages