If argument center is passed to rowWeightedMads(), it is passed as is to weightedMad() for each row calculated. That is, it will only work for center=NULL or length(center) == 1. If one tries to pass a vector as one would do with, say, rowMads(), on gets garbage results or an error:
library("matrixStats")
x <- matrix(rnorm(20), nrow=5, ncol=4)
center <- rowMedians(x)
mu0 <- rowMads(x)
mu1 <- rowMads(x, center=center)
stopifnot(identical(mu1, mu0))
mu2 <- rowWeightedMads(x, w=rep(1,ncol(x)))
stopifnot(identical(mu2, mu0))
mu3 <- rowWeightedMads(x, w=rep(1,ncol(x)), center=center)
Error in weightedMedian(x, w = w, na.rm = NA) :
Argument 'x' and 'w' are of different lengths: 5 != 4
In addition: Warning message:
In x - center :
longer object length is not a multiple of shorter object length
This problem also occurs for column-wise calculations.
If argument
center
is passed torowWeightedMads()
, it is passed as is toweightedMad()
for each row calculated. That is, it will only work forcenter=NULL
orlength(center) == 1
. If one tries to pass a vector as one would do with, say,rowMads()
, on gets garbage results or an error:This problem also occurs for column-wise calculations.
Troubleshooting
This is because
center
is passed as is via...
: