Error in compareGroups.default(X = X, y = y, include.label = include.label, : None variable can be computed."

1,263 views
Skip to first unread message

davyd....@gmail.com

unread,
Feb 22, 2017, 11:36:45 PM2/22/17
to compareGroups Forum
Hi,

I am using compareGroups to analyze a dataset (please see below my data frame).
An error message appears like:

"Error in compareGroups.default(X = X, y = y, include.label = include.label, : None variable can be computed."

I use R-3.3.2
Could you please help me?
Thank you in advance.
David

group gender episod mother father
1 2 0 0 0
1 1 2 0 0
0 1 4 0 0
1 2 4 0 0
0 2 0 0 0
0 2 2 0 0
0 1 3 0 0
0 1 3 0 0
0 1 0 0 0
1 2 2 0 0
1 2 0 0 0
1 1 0 0 0
1 1 3 0 0
1 1 1 0 0
0 2 0 0 0
0 1 0 0 0
0 2 1 0 0
0 1 4 0 0
1 1 0 0 0
1 1 4 0 0
1 1 3 0 0
0 1 1 0 0
1 2 1 0 0
1 2 2 0 0
0 2 0 0 0
0 1 2 0 0
1 2 0 0 0
1 1 1 0 0
1 1 2 0 0
0 2 1 0 0
0 1 4 0 0
0 2 4 0 0
1 2 0 0 0
1 2 4 0 0
1 2 1 0 0
0 1 3 0 0
0 1 1 0 0
1 1 4 0 0
0 1 4 0 0
1 1 1 0 0
0 1 2 0 0
0 2 0 0 0
1 2 0 0 0
0 1 2 0 0
1 2 3 0 0
1 2 3 0 0
1 2 1 0 0
1 2 1 0 0
0 2 3 1 0
1 1 1 0 0
0 2 2 0 0
0 2 2 0 0
1 1 3 0 0
1 1 3 0 0
0 2 1 0 0
0 2 3 0 0
1 2 1 0 0
0 2 1 0 0
1 2 2 0 0
1 2 4 0 0
1 1 0 0 0
1 2 1 1 0
1 2 4 0 0
0 1 3 0 0
0 2 2 0 0
1 2 4 0 0
0 2 3 0 0
0 1 2 1 0
0 1 1 0 0
0 2 4 0 0
1 1 1 0 0
1 2 2 0 0
0 1 4 0 0
1 1 2 0 0
1 1 3 0 0
1 2 3 0 0
1 2 2 0 0
1 1 1 0 0
1 1 3 0 0
1 1 3 0 0
1 1 0 0 0
0 2 3 0 0
0 2 2 0 0
1 2 2 1 0
0 2 0 1 0
0 2 1 0 0
1 2 3 0 0
0 2 1 0 0
0 1 1 0 0
1 2 4 0 0
1 1 0 0 0
1 2 4 1 0
1 2 3 0 0
1 1 0 0 0
0 2 3 0 0

compareGroups

unread,
Feb 23, 2017, 3:54:06 AM2/23/17
to compareGroups Forum
Could you provide the syntax to produce the table (compareGroups / createTable functions calls)?

Isaac.

davyd....@gmail.com

unread,
Feb 23, 2017, 9:09:47 AM2/23/17
to compareGroups Forum
Dear Isaac,
Thank you very much for you help
This is my syntax : res <- compareGroups(group ~ . , data = dbase)

David

compareGroups

unread,
Feb 27, 2017, 11:34:58 AM2/27/17
to compareGroups Forum
I tried to reproduce your analyses with your data and syntax, and it gives only an error on father variable since it is a constant and cannot perform a comparison tests between groups. I cannot figure out why it returns this error and says that it can compute any test for no variable. Have you checked if variables are numeric or are they factors?

Isaac.

davyd....@gmail.com

unread,
Feb 27, 2017, 11:42:48 AM2/27/17
to compareGroups Forum
Thank you Dear Isaac.
I declared all my variables as categorial (factor), I even tried to make the comparison with only two variables, but it always displays the same error.

compareGroups

unread,
Feb 28, 2017, 10:10:58 AM2/28/17
to compareGroups Forum
I have read your data by coping your data to the "clipboard" from this forum and then typing:

> dbase <- read.table("clipboard", header = TRUE)

Once I have read the data I have transformed all variables to factors by

> for (i in 1:ncol(dbase)) dbase[,i] <- factor(dbase[,i])

Finally, I have run compareGroups function and there is only a warning, but it provide without any error.

> res <- compareGroups(group ~ . , data = dbase)
Warning message:
In chisq.test(xx, correct = correction) :
  Chi-squared approximation may be incorrect

> res


-------- Summary of results by groups of 'group'---------


  var    N  p.value method      selection
1 gender 95 1.000   categorical ALL      
2 episod 95 0.975   categorical ALL      
3 mother 95 1.000   categorical ALL      
4 father 95 .       categorical ALL      
-----
Signif. codes:  0 '**' 0.05 '*' 0.1 ' ' 1 





toma...@gmail.com

unread,
Apr 5, 2017, 4:57:57 PM4/5/17
to compareGroups Forum
Hello,

Sorry for adding a new question to this thread.
I am running a comparison between two groups, and when I run the code, I get the exact Warning Message as the one mentioned above.
This is what I get:
Warning messages:
1: In chisq.test(xx, correct = correction) :


Chi-squared approximation may be incorrect

2: In chisq.test(xx, correct = correction) :


Chi-squared approximation may be incorrect

3: In chisq.test(xx, correct = correction) :


Chi-squared approximation may be incorrect

4: In chisq.test(xx, correct = correction) :


Chi-squared approximation may be incorrect

5: In chisq.test(xx, correct = correction) :


Chi-squared approximation may be incorrect

6: In chisq.test(xx, correct = correction) :


Chi-squared approximation may be incorrect

Although I can then obtain the table of comparisons, I wonder how to interpret these error messages. In particular I want to make sure that I don't end up showing results that should be invalid.

Thank you for your time! Any help will be much appreciated.

Best,
Tomas

compareGroups

unread,
Apr 11, 2017, 3:10:05 AM4/11/17
to compareGroups Forum
Hi Tomas,

This is internal warning of compareGroups functions. It appears when first compareGoups tries to perform a Chi-squared test. But when any cell has expected count smaller than 5 it performs a Fisher exact test. So, the final p-value comes from a Fisher test and therefore results are reliable even for small count data.

Regards,

Isaac.

vdr...@gmail.com

unread,
Apr 24, 2017, 10:39:45 AM4/24/17
to compareGroups Forum
Hello!

I just ran into a very similar problem and it may be linked to using 'data.frame' like objects (such as the 'tbl_df' object, used commonly in dplyr).

I tracked the error down to line 66 and 67 here (https://github.com/cran/compareGroups/blob/master/R/compareGroups.formula.R).
I think the issue is that subsetting a tbl_df using row.names (which returns a character vector) does not work so the X and Xext objects only contain NAs.

I was able to fix this issue by simply calling 'as.data.frame' on my data before passing to compareGroups.

If the maintainers think it appropriate, they could add a check to the beginning of the compareGroups call that converts the data object to a data.frame.


vdr...@gmail.com

unread,
Apr 24, 2017, 12:03:20 PM4/24/17
to compareGroups Forum
Sorry, I meant line 65 + 66

Isaac Subirana

unread,
Jun 4, 2017, 8:09:42 AM6/4/17
to compareGroups Forum
As you pointed, data must be converted to data.frame object. It seems that compareGroups does not support tbl_df objects. 
So, we will consider to add a condition to incorporate tbl_df objects.
Thanks for your suggestions.

Isaac.
Reply all
Reply to author
Forward
0 new messages