Learn R Programming

SpatialTools (version 0.4.1)

rcondsim: Generates realizations from a conditional normal distribution

Description

Generates realizations from a conditional normal distribution.

Usage

rcondsim(nsim = 1, krige.obj, y, V, Vp, Vop, Ve.diag, method = "eigen")

Arguments

nsim
An integer indicating the number of realizations from the distribution.
krige.obj
An object returned by krige.sk, krige.ok, or krige.uk.
y
A vector of length n containing the observed data values.
V
The covariance matrix of the observed data. The matrix should be symmetric and positive definite. The size must be $n times n$.
Vp
The covariance matrix of the responses to be predicted. The matrix should be symmetric and positive definite. The size is $np times np$.
Vop
The cross-covariance matrix between the observed data and the responses to be predicted. The size must be $n times np$.
Ve.diag
A vector of length n specifying the measurement error variances of the observed data.
method
The method for performing a decomposition of the covariance matrix. Possible values are "eigen", "chol", and "svd", Eigen value decomposition, Cholesky decomposition, or Singular Value Decomposoition, respectively.

Value

  • An $n \times nsim$ matrix containing the nsim realizations of the conditional realizations. Each column of the matrix represents a realization of the conditional normal distribution.

Details

If doing conditional simulation, the Cholesky decomposition should not work when there are coincident locations between the observed data locations and the predicted data locations. Both the Eigen and Singular Value Decompositions should work.

See Also

rmvnorm

Examples

Run this code
# create observed and predicted coordines
ocoords <- matrix(runif(100), ncol = 2)
pcoords <- matrix(runif(200), ncol = 2)

# include some observed locations in the predicted coordinates
acoords <- rbind(ocoords, pcoords)

# create design matrices
X <- as.matrix(cbind(1, ocoords))
Xa <- as.matrix(cbind(1, acoords))

# create covariance matrix
C3 <- cov.sp(coords = ocoords, sp.type = "matern", sp.par = c(2, 1), smoothness = 1, 
	finescale = 0, error = 0.5, pcoords = acoords)

# set values of regression coefficients
coeff <- matrix(c(1, 2, 3), nrow = 1)

# generate data with error
y <- rmvnorm(nsim = 1, mu = tcrossprod(X, coeff), V = C3$V) + rnorm(50, sd = sqrt(.5))

# use universal kriging to make predictions
krige.obj <- krige.uk(as.vector(y), V = C3$V, Vp = C3$Vp, Vop = C3$Vop, 
	X = X, Xp = Xa, return.w = TRUE)

# generate conditional simulations of observations
mycondsim <- rcondsim(nsim = 100, krige.obj = krige.obj, y = as.vector(y), 
	V = C3$V, Vp = C3$Vp, Vop = C3$Vop, 
	Ve.diag = rep(.5, 50), method = "eigen")

Run the code above in your browser using DataLab