const-ae / const-ae/sparseMatrixStats

`row/colVars()` and `row/colSds()` methods for xgCMatrix objects silently ignore the supplied `center`

Open
#13 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
55
Forks
3
PR merge metrics
No merged PRs in 30d

Description

See for example the definition of the `rowVars()` method:
```
library(sparseMatrixStats)

selectMethod("rowVars", "xgCMatrix")
# Method Definition:
#
# function (x, rows = NULL, cols = NULL, na.rm = FALSE, center = NULL, ...)
# {
# .local <- function (x, rows = NULL, cols = NULL, na.rm = FALSE)
# {
# if (!is.null(rows)) {
# x <- x[rows, , drop = FALSE]
# }
# if (!is.null(cols)) {
# x <- x[, cols, drop = FALSE]
# }
# dgCMatrix_rowVars(x, na_rm = na.rm)
# }
# .local(x, rows, cols, na.rm, ...)
# }
#
#
#
# Signatures:
# x
# target "xgCMatrix"
# defined "xgCMatrix"
```

Here is a concrete example using a dgCMatrix object:
```
library(Matrix)
i <- 1:5
j <- 2:6
m0 <- sparseMatrix(i, j, x=10*i+j, dims=c(5, 7)) # dgCMatrix object
```

`center` not supplied:
```
matrixStats::rowVars(as.matrix(m0))
# [1] 20.57143 75.57143 165.14286 289.28571 448.00000
rowVars(m0)
# [1] 20.57143 75.57143 165.14286 289.28571 448.00000
```

`center` supplied:
```
matrixStats::rowVars(as.matrix(m0), center=0)
# [1] 24.00000 88.16667 192.66667 337.50000 522.66667
rowVars(m0, center=0) # 'center' is ignored!
# [1] 20.57143 75.57143 165.14286 289.28571 448.00000
```

Thanks,
H.

**sessionInfo():**
```
R Under development (unstable) (2020-10-28 r79382)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.7 LTS

Matrix products: default
BLAS: /home/hpages/R/R-4.1.r79382/lib/libRblas.so
LAPACK: /home/hpages/R/R-4.1.r79382/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] Matrix_1.2-18 sparseMatrixStats_1.3.0 MatrixGenerics_1.3.0
[4] matrixStats_0.57.0

loaded via a namespace (and not attached):
[1] compiler_4.1.0 Rcpp_1.0.5 grid_4.1.0 lattice_0.20-41
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.