Open GoogleCodeExporter opened 9 years ago
The documentation says that the group argument must contain:
a vector of consecutive integers describing the grouping of the coefficients
So the example above fails (and still fails in the latest version) because rep(1:5, 2)
is not sorted ascending and so contains non-consecutive integers.
In practice this means that for gglasso the columns of x
must be strictly sorted by group
or results are nonsensical because the group is not applied as the analyst intends. The documentation is not very explicit on this requirement and there is no working check for this, only the following:
if (!identical(as.integer(sort(unique(group))), as.integer(1:bn)))
stop("Groups must be consecutively numbered 1,2,3,...")
This checks that there are no skipped levels e.g. c(1,1,1,2,2,2,4,4,4)
, but because unique(group)
is sorted the problems with rep(1:5, 2)
will not trigger this error.
A better check would be something with run length encoding, compare:
rle(rep(1:5, 2))
# Run Length Encoding
# lengths: int [1:10] 1 1 1 1 1 1 1 1 1 1
# values : int [1:10] 1 2 3 4 5 1 2 3 4 5
rle(rep(1:5,each = 2))
# Run Length Encoding
# lengths: int [1:5] 2 2 2 2 2
# values : int [1:5] 1 2 3 4 5
So a more sensitive test could be:
identical(rle(group)$values, 1:as.integer(max(group)))
Note: above testing and code excerpts are from CRAN version 1.4 of gglasso using R 3.6.1 on Windows
Original issue reported on code.google.com by
elong0...@gmail.com
on 9 Oct 2013 at 9:59