permutation test error - "must have >4 observations"

357 views
Skip to first unread message

Jonatan Ottino

unread,
Jan 18, 2020, 10:55:29 AM1/18/20
to brainGraph-help
Hi,

first of all, sorry if this one has already answered elsewhere. I did my best in trying to find this specific error in the forum but I haven´t been that lucky.

I´m following the guide step by step until I get familiar with the package. I have two groups (N=971, N=870) which I´d like to compare for several graph-metrics.

After successfully getting the within-group variability estimates with bootstrapping, I was trying to conduct a permutation test between the groups with the following piece of code from p. 103.

#########################################################

kNumPerms <- 1e3

myPerms <- permute::shuffleSet(n = nrow(all.dat.resids$resids.all), 
                               nset = kNumPerms)

perms.all <- brainGraph_permute(densities, 
                                                      all.dat.resids, 
                                                      perms =  myPerms,
                                                      level = 'graph',
                                                      atlas = atlas)

#########################################################

The outcome of this was the following error:

Error in { : task 1 failed - "must have >4 observations"
In addition: Warning message:
In brainGraph_permute(densities, all.dat.resids, perms = myPerms,  :
  NAs introduced by coercion

I still struggling to get my head around this but so far I haven´t succeeded. Any insight with this would be highly appreciated! 

All the best,
J

Chris Watson

unread,
Jan 18, 2020, 7:29:58 PM1/18/20
to brainGr...@googlegroups.com
Hi Jonathan,
That is an error from "rcorr", which is the function that creates correlation
matrices; it is called from within "corr.matrix". I need a lot more information
to be able to debug this. For example:

* What versions of R, igraph, and brainGraph are you using?
* What atlas are you using? How many regions are there?
* What is the nature of your data? I assume this is structural covariance data
* What are the densities (the range, number, etc.)? Do you have complete data
for all of them?

The easiest way for me to debug, I think, would be if you sent me the data
necessary to reproduce the error: the residuals, densities, and atlas.
Chris

On Sat, Jan 18, 2020 at 09:55 AM, Jonatan Ottino <jonata...@gmail.com> wrote:

> from: Jonatan Ottino <jonata...@gmail.com>
> date: Sat, Jan 18 07:55 AM -08:00 2020
> to: brainGraph-help <brainGr...@googlegroups.com>
> reply-to: brainGr...@googlegroups.com
> subject: [brainGraph-help] permutation test error - "must have >4 observations"
> --
> 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/7deaaee3-732b-458d-8035-f84b301609cb%40googlegroups.com.

Jonatan Ottino

unread,
Jan 20, 2020, 5:59:49 PM1/20/20
to brainGraph-help
Hi Chris, thanks for your quick response.

It's a weird error because everything else seemed to have worked just fine (i.e., residuals, random graph-generator, bootstrap...). 

* I'm using R version 3.6.1 (2019-07-05), Rstudio (1.2.5001), brainGraph (2.7.3), and igraph (1.2.4.2). 
* I'm using the dk atlas with 68 cortical parcels. No missing data.
* Yes, it is structural covariance data.
* Regarding densities, they ranged from 0.08 to 0.40 (0.01 increase, N = 33 densities)

I'll be sending you the data soon. 

Best,
J
> To unsubscribe from this group and stop receiving emails from it, send an email to brainGr...@googlegroups.com.

Chris Watson

unread,
Jan 21, 2020, 3:04:53 AM1/21/20
to brainGr...@googlegroups.com
A couple of things you could check yourself quickly:

1. Does "as.numeric(resids$resids.all$Group)" return a numeric vector, without any "NA" or "NULL" values? (where "resids" is the object you input to the permute function)
2. Since you calculate "myPerms" beforehand, you can see what the output of the following command(s) is:
groups <- as.numeric(resids$resids.all$Group)    # If #1 above worked fine
dim(resids$resids.all[which(groups[myPerms[1, ]] == 1)])    # Make sure you enter the brackets and parentheses correctly
dim(resids$resids.all[which(groups[myPerms[1, ]] == 2)])
... # For as many Groups as you have data for

If the dimensions are both positive for all groups, then I will have to look at the data myself.

Chris

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/1a7163d2-94ad-49f2-aade-c81db0c99643%40googlegroups.com.

Jonatan Ottino

unread,
Jan 21, 2020, 9:11:35 AM1/21/20
to brainGraph-help
Thank you Chris,

the #1 returned all values as NAs and made me revise my code. 

Apparently, I forgot to set the stringsAsFactors to TRUE when loading 'covars' and force Study.ID to be a character type (I formally had it as numeric). Now it is working perfectly. 

Thanks again for this package and the documentation. I was looking forward to have something like this in R.

All the best,
J

Chris Watson

unread,
Jan 21, 2020, 10:08:15 AM1/21/20
to brainGr...@googlegroups.com
Got it. I'm glad it turned out to be something simple. I'll fix the function so that it forces that variable to be numeric,  without NA's.

Let me know if you run into any other problems.
Chris

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/42785802-295b-45b2-ab39-55f6b787ae01%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages