Closed akhst7 closed 2 years ago
You are correct that the current behavior isn't appropriate (it should throw an error if given a dgCMatrix
object).
If it were to sample would it be from the i
's, the p
's, or the Dim
's? Any thoughts or pointers would be welcomed.
@nicholasjhorton, actually it is more complicated than I initially thought. I attempted to convert dgCMatrix to the matrix and run mosaic's sample but this did not work when a dgCMatrix obj is extremely large.
As I understand correctly. I
and p
are just row and column index respectively and Dim is just a dimension of dgCMatrix. x represents a non-zero count but does not have a positional info. I have to think about this a bit.
Thanks.
@akhst7 : mosaic::sample()
is generic and does have a method for objects of class matrix (it samples rows of the matrix), but there is no method for an object of class dgcMatrix, so at best you should get whatever base::sample()
does in that situation. Based on minimal testing, that seems to be what is happening. Since base::sample()
doesn't generate an error here, we don't want to either.
I'd suggest handling your situation by manually sampling the row indices (if that's what how you mean to be sampling from your matrix). That's basically all mosaic::sample()
does for a matrix. Here's the core of the function:
n <- nrow(x)
ids <- base::sample(n, size, replace=replace, prob=prob)
data <- x [ ids, , drop=FALSE]
names(data) <- names(x)
If data <- x [ ids, , drop=FALSE]
does what you want with a dgCMatrix, then you are all set.
If that's all it takes, we could fold this into mosaic. But it isn't really the sweet spot for the mosaic package. We only have a dependency of the Matrix package to avoid awkward coexistence problems.
Hi,
I want to sample this dgCMatrix obj;
I run the mosaic sample as follows;
Sample() is not random sampling the matrix. Am I missing something here ?