| sumouter {spatstat.sparse} | R Documentation |
Calculates certain quadratic forms of matrices.
sumouter(x, w=NULL, y=x) quadform(x, v) bilinearform(x, v, y)
x,y |
A matrix, whose rows are the vectors in the quadratic form. |
w |
Optional vector of weights |
v |
Matrix determining the quadratic form |
The matrices x and y will be interpreted as
collections of row vectors. They must have the same number of rows.
The entries of x and y may be
numeric, integer, logical or complex values.
The command sumouter computes the sum of the outer
products of corresponding row vectors, weighted by the entries of w:
M = sum[i] (w[i] * outer(x[i,], y[i,]))
where x[i,] is the i-th row of x
and y[i,] is the i-th row of y
(after removing any rows containing NA or other non-finite
values).
If w is missing, the weights will be taken as 1.
The result is a p * q matrix where
p = ncol(x) and q = ncol(y).
The command quadform evaluates the quadratic form, defined by
the matrix v, for each of the row vectors of x:
y[i] = x[i,] %*% v %*% t(x[i,])
The result y is a numeric vector of length n where
n = nrow(x). If x[i,] contains NA or
other non-finite values, then y[i] = NA.
The command bilinearform evaluates the more general bilinear
form defined by the matrix v. Here x and y must
be matrices of the same dimensions. For each row vector of
x and corresponding row vector of y, the bilinear form is
z[i] = x[i,] %*% v %*% t(y[i,])
The result z is a numeric vector of length n where
n = nrow(x). If x[i,] or y[i,] contains NA or
other non-finite values, then z[i] = NA.
A vector or matrix.
Adrian Baddeley Adrian.Baddeley@curtin.edu.au and Rolf Turner r.turner@auckland.ac.nz
x <- matrix(1:12, 4, 3)
dimnames(x) <- list(c("Wilma", "Fred", "Barney", "Betty"), letters[1:3])
x
sumouter(x)
w <- 4:1
sumouter(x, w)
v <- matrix(1, 3, 3)
quadform(x, v)
# should be the same as quadform(x, v)
bilinearform(x, v, x)
# See what happens with NA's
x[3,2] <- NA
sumouter(x, w)
quadform(x, v)