A representation of a numeric matrix with row weights, represented
on either linear (linwmatrix) or logarithmic (logwmatrix)
scale.
logwmatrix(
data = NA,
nrow = 1,
ncol = 1,
byrow = FALSE,
dimnames = NULL,
w = NULL
)
linwmatrix(
data = NA,
nrow = 1,
ncol = 1,
byrow = FALSE,
dimnames = NULL,
w = NULL
)
is.wmatrix(x)
is.logwmatrix(x)
is.linwmatrix(x)
as.linwmatrix(x, ...)
as.logwmatrix(x, ...)
# S3 method for class 'linwmatrix'
as.linwmatrix(x, ...)
# S3 method for class 'logwmatrix'
as.linwmatrix(x, ...)
# S3 method for class 'logwmatrix'
as.logwmatrix(x, ...)
# S3 method for class 'linwmatrix'
as.logwmatrix(x, ...)
# S3 method for class 'matrix'
as.linwmatrix(x, w = NULL, ...)
# S3 method for class 'matrix'
as.logwmatrix(x, w = NULL, ...)
# S3 method for class 'wmatrix'
print(x, ...)
# S3 method for class 'logwmatrix'
print(x, ...)
# S3 method for class 'linwmatrix'
print(x, ...)
# S3 method for class 'logwmatrix'
compress_rows(x, ...)
# S3 method for class 'linwmatrix'
compress_rows(x, ...)
# S3 method for class 'wmatrix'
decompress_rows(x, target.nrows = NULL, ...)
# S3 method for class 'wmatrix'
x[i, j, ..., drop = FALSE]
# S3 method for class 'wmatrix'
x[i, j, ...] <- valuepassed to matrix.
row weights on the appropriate scale.
an object to be coerced or tested.
extra arguments, currently unused.
the approximate number of rows the uncompressed matrix should have; if not achievable exactly while respecting proportionality, a matrix with a slightly different number of rows will be constructed.
rows and columns and values for extraction or
replacement; as matrix.
Used for consistency with the generic. Ignored, and
always treated as FALSE.
An object of class linwmatrix/logwmatrix and wmatrix,
which is a matrix but also has an attribute w containing
row weights on the linear or the natural-log-transformed scale.
Note that wmatrix itself is an "abstract" class: you cannot
instantiate it.
Note that at this time, wmatrix is designed as, first and
foremost, as class for storing compressed data matrices, so most
methods that operate on matrices may not handle the weights
correctly and may even cause them to be lost.
(m <- matrix(1:3, 2, 3, byrow=TRUE))
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 1 2 3
(m <- rbind(m, 3*m, 2*m, m))
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 1 2 3
#> [3,] 3 6 9
#> [4,] 3 6 9
#> [5,] 2 4 6
#> [6,] 2 4 6
#> [7,] 1 2 3
#> [8,] 1 2 3
(mlog <- as.logwmatrix(m))
#> A row-weighted matrix with natural-log-scaled weights:
#> Weight
#> [1,] 1 2 3 0
#> [2,] 1 2 3 0
#> [3,] 3 6 9 0
#> [4,] 3 6 9 0
#> [5,] 2 4 6 0
#> [6,] 2 4 6 0
#> [7,] 1 2 3 0
#> [8,] 1 2 3 0
(mlin <- as.linwmatrix(m))
#> A row-weighted matrix with linear-scaled weights:
#> Weight
#> [1,] 1 2 3 1
#> [2,] 1 2 3 1
#> [3,] 3 6 9 1
#> [4,] 3 6 9 1
#> [5,] 2 4 6 1
#> [6,] 2 4 6 1
#> [7,] 1 2 3 1
#> [8,] 1 2 3 1
(cmlog <- compress_rows(mlog))
#> A row-weighted matrix with natural-log-scaled weights:
#> Weight
#> [1,] 1 2 3 1.3862944
#> [2,] 2 4 6 0.6931472
#> [3,] 3 6 9 0.6931472
(cmlin <- compress_rows(mlin))
#> A row-weighted matrix with linear-scaled weights:
#> Weight
#> [1,] 1 2 3 4
#> [2,] 2 4 6 2
#> [3,] 3 6 9 2
stopifnot(all.equal(as.linwmatrix(cmlog),cmlin))
cmlog[2,] <- 1:3
(cmlog <- compress_rows(cmlog))
#> A row-weighted matrix with natural-log-scaled weights:
#> Weight
#> [1,] 1 2 3 1.7917595
#> [2,] 3 6 9 0.6931472
stopifnot(sum(rowweights(cmlog))==nrow(m))
(m3 <- matrix(c(1:3,(1:3)*2,(1:3)*3), 3, 3, byrow=TRUE))
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 2 4 6
#> [3,] 3 6 9
(rowweights(m3) <- c(4, 2, 2))
#> [1] 4 2 2
stopifnot(all.equal(compress_rows(as.logwmatrix(m)), as.logwmatrix(m3),check.attributes=FALSE))
stopifnot(all.equal(rowweights(compress_rows(as.logwmatrix(m))),
rowweights(as.logwmatrix(m3)),check.attributes=FALSE))