calc.tFX {SpatioTemporal} | R Documentation |
Computes the matrix products between the transpose of a sparse matrix F
containing temporal trends the and a vector/matrix.
See the examples for details.
calc.tFX(F, X, loc.ind, n.loc = max(loc.ind))
F |
A (number of obs.) - by - (number of temporal trends) matrix
containing the temporal trends. Usually |
X |
A vector or matrix; needs to be a multiple of |
loc.ind |
A vector indicating which location each row in |
n.loc |
Number of locations. |
Returns a matrix of size n.loc*dim(F)[2]
-by-coden.x.
Johan Lindstrom and Adam Szpiro
Other block matrix functions: blockMult
,
calc.FXtF2
, calc.FX
,
calc.mu.B
, calc.tFXF
,
makeCholBlock
, makeSigmaB
,
makeSigmaNu
Other temporal trend functions: calc.FXtF2
,
calc.FX
, calc.tFXF
,
expandF
##This starts with a couple of simple examples, more elaborate examples ##with real data can be found further down. require(Matrix) ##create a trend trend <- cbind(1:5,sin(1:5)) ##an index of locations idx <- c(rep(1:3,3),1:2,2:3) ##a list of time points for each location/observation T <- c(rep(1:3,each=3),4,4,5,5) ##create a random observations matrix obs <- rnorm(length(T)) ##expand the F matrix to match the locations/times in idx/T. F <- trend[T,] F ##compute tF %*% obs tFobs <- calc.tFX(F, obs, idx) ##or posibly expanded if we have unobserved, trailing locations tFobs.exp <- calc.tFX(F, obs, idx, 5) ##alternatievly this can be computed as observtions for each location ##multiplied by the trend function at the corresponding time points. tFobs.alt <- t(expandF(F, idx)) %*% obs ##compare results print( cbind(tFobs,tFobs.alt) ) ##some examples using real data data(mesa.model) ##Some information about the size(s) of the model. dim <- loglikeSTdim(mesa.model) ##compute F' %*% obs tFobs <- calc.tFX(mesa.model$F, mesa.model$obs$obs, mesa.model$obs$idx) ##The resulting matrix contains 75 elements (3 temporal trend at 25 ##sites). The first element are the observations at the first site ##multiplied by the constant temporal trend, e.g. print( tFobs[1] ) print( sum(mesa.model$obs$obs[mesa.model$obs$idx==1]) ) ##The 27:th element are the observations at the second site (27-25) ##multiplied by the first temporal trend (second element in F) print( tFobs[dim$n.obs+2] ) print( sum(mesa.model$obs$obs[mesa.model$obs$idx==2] * mesa.model$F[mesa.model$obs$idx==2,2]))