sim.GMRF: Simulate correlated data from a precision matrix.

Description Usage Arguments Value References Examples

View source: R/simGMRF.R

Description

Takes in a square precision matrix of a gaussian Markov random field, which ideally should be sparse, and using algorithm 3.1 from Gaussian Markov Random Fields by Rue & Held simulates data from a mean 0 process where the inverse of the precision matrix represents the variance-covariance of the points in the process. The resulting simulants represent samples of a Gaussian Markov random field (GMRF).

Usage

1
sim.GMRF(n, Q, tol = 1e-12)

Arguments

n

int > 0, number of observations to simulate from the GMRF.

Q

matrix, a square precision matrix of a GMRF.

tol

numeric, The tolerance for the removal of zero eigenvalues.

Value

Matrix object, matrix where each row is a single obsrevation from a GMRF with precision structure Q.

References

Rue, H. Held, L. Gaussian Markov Random Fields: Theory and Applications. Chapman and Hall. 2005.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
require("ggplot2")

# simulate 2D rw1 process
# pairwise variance
sigma <- .5

# 2 dimensions of simulations
years <- 20
ages <- 10

# kronnecker product to get joint precision
Q2D <- kronecker(Q.RW1(M=years, sigma), Q.RW1(M=ages, sigma))

# simulate the data and place it in a data frame
Q2D.df <- data.frame(obs=c(sim.GMRF(1, Q2D)), age=rep(1:ages, years),
                     year=rep(1:years, each=ages))

# graph results
ggplot(data=Q2D.df, aes(year, obs, group=age, color=age)) + geom_line()

nmmarquez/ar.matrix documentation built on May 23, 2019, 9:28 p.m.