Learn R Programming

SpatioTemporal (version 0.9.2)

calc.iS.X: Matrix Multiplication with Block Matrices

Description

Computes either the product between a block diagonal, square matrix iS and a block matrix X; the quadratic form of a block diagonal, square matrix, t(X)*iS*X; or a block matrix multiplied by a vector, X*alpha.

Usage

calc.iS.X(X, iS, dim)

calc.X.iS.X(X, iS.X, dim)

calc.mu.B(dim, X, alpha)

Arguments

X
A list of matrices with which to form the block matrix. Usually mesa.data.model$X, where mesa.data.model is obtained from create.da
iS
A block diagonal, square matrix, with dim$m blocks each of size dim$n - by - dim$n.
iS.X
Matrix containing the product of iS and X. Output from calc.iS.X.
dim
Information regarding parameter dimension, output from loglike.dim.
alpha
A list of dim$m vectors, with the i:th vector being of length dim$p[i].

Value

  • Returns iS*X, X'*iS*X, or X*alpha.

encoding

latin1

See Also

Block matrices can be created by make.sigma.B, make.sigma.B.full and make.sigma.nu. Other block matrix functions makeCholBlock, block.mult, calc.tF.times.mat, dot.prod, sumLogDiag. This function is called by loglike.

Examples

Run this code
## Create a block diagonal matrix, ...
iS <- rbind(c(2,1,0,0),c(1,3,0,0),
            c(0,0,3,2),c(0,0,2,4))
## ... a block matrix ...
X <- list(matrix(c(1,2)),matrix(c(2,2,3,4),2,2))
## ... with alternative form, ...
Xt <- rbind(cbind(X[[1]],matrix(0,2,2)),
            cbind(matrix(0,2,1),X[[2]]))
## ... and a vector alpha.
alpha <- list(c(1),c(-2,1))
## Create matching dimension structure.
dim <- list(p=c(1,2), m=2, n=2)

## Compute iS * X
iS.X <- calc.iS.X(X,iS,dim)
## or
iS %*% Xt
if( max(abs(iS.X - (iS %*% Xt))) > 1e-13 ){
  stop("calc.iS.X: Results not equal")
}
## Compute X'* iS * X
calc.X.iS.X(X, iS.X, dim)
## or
t(Xt) %*% iS %*% Xt
if( max(abs(calc.X.iS.X(X, iS.X, dim) -
            (t(Xt) %*% iS %*% Xt))) > 1e-13 ){
  stop("calc.X.iS.X: Results not equal")
}
## Compute X* alpha
calc.mu.B(dim, X, alpha)
## or
cbind(X[[1]] %*% alpha[[1]], X[[2]] %*% alpha[[2]])
if( max(abs(cbind(X[[1]] %*% alpha[[1]], X[[2]] %*% alpha[[2]]) -
            calc.mu.B(dim, X, alpha))) > 1e-13 ){
  stop("calc.mu.B: Results not equal")
}

Run the code above in your browser using DataLab