# calc.tFX: Compute Matrix Product Bewteen Temporal Trends and a Matrix In SpatioTemporal: Spatio-Temporal Model Estimation

## Description

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.

## Usage

 `1` ```calc.tFX(F, X, loc.ind, n.loc = max(loc.ind)) ```

## Arguments

 `F` A (number of obs.) - by - (number of temporal trends) matrix containing the temporal trends. Usually `mesa.model\$F`, where `mesa.model` is obtained from `createSTmodel`. `X` A vector or matrix; needs to be a multiple of `dim(F)[1]`. `loc.ind` A vector indicating which location each row in `F` corresponds to, usually `mesa.model\$obs\$idx`. `n.loc` Number of locations.

## Value

Returns a matrix of size `n.loc*dim(F)[2]`-by-coden.x.

## Author(s)

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`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50``` ```##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])) ```