| bd_wproduct | R Documentation |
Compute weighted operations using a diagonal weight from w:
"xtwx": X' diag(w) X (row weights; length(w) = nrow(X))
"xwxt": X diag(w) X' (column weights; length(w) = ncol(X))
"xw" : X diag(w) (column scaling; length(w) = ncol(X))
"wx" : diag(w) X (row scaling; length(w) = nrow(X))
Inputs may be base numeric matrices .
bd_wproduct(X, w, op)
X |
Numeric matrix (n x p). |
w |
Numeric weight vector (length |
op |
Character string (case-insensitive): one of
|
w is interpreted as the diagonal of a weight matrix; its required length depends on the operation:
rows for "xtwx" and "wx", columns for "xwxt" and "xw".
Numeric matrix with dimensions depending on op:
p x p for "xtwx", n x n for "xwxt", and n x p for "xw"/"wx".
set.seed(1)
n <- 10; p <- 5
X <- matrix(rnorm(n * p), n, p)
u <- runif(n); w <- u * (1 - u)
bd_wproduct(X, w, "xtwx") # p x p
bd_wproduct(X, w, "wx") # n x p (row scaling)
v <- runif(p)
bd_wproduct(X, v, "xw") # n x p (col scaling)
bd_wproduct(X, v, "xwxt") # n x n
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.