It also simulates conditional random fields for
For basic simulation of Gaussian random fields, see RFsimulate. See RFsimulate.more.examples and RFsimulate.sophisticated.examples for further examples.
GridTopology
or
raster
;
if matrix, ncol(x)
x
is a matrixx
is a matrixT
must always be an equidistant vector or given in a
gridtriple format (see argument grid
); for each component
of T
, the random field is simulated at all location pointsx
,
y
, and z
or the columns of x
should be
interpreted as a grid definition (see Details). If grid=TRUE
,
either x
, y
, and model
; gives the model of the
measurement errors for the measured data
(which must be given
in this case!), see Details,
err.model=NULL
(default) corresponds to error-free
measurements, the most common aldist
representing
the upper trianguar part of the matrix of Euclidean distances
between the points at which the field is to be simulated; only
applicable for stationary and isotropic models; The output format can be switched to the "old" array format using
RFoptions
, either by globally setting
RFoptions(spConform=FALSE)
or by passing spConform=FALSE
in the call of n
and grid
in the following way:
if vdim > 1
the vdim
-variate vector makes the first dimension
if grid=TRUE
an array of the dimension of the
random field makes the next dimensions. Here, the dimensions
are ordered in the sequence x
, y
, z
, T
(if given).
Else if no time component is given, then the values are passed as a
single vector. Else if the time component is given the next 2
dimensions give the space and the time, respectively.
if n > 1
the repetitions make the last dimension
Note: Conversion between the InitRFsimulate
returns 0 if no error has occurred and a positive value
if failed.
If the wrapping function of the model
argument is a covariance
or variogram model (i.e., one of list obtained by
RFgetModelNames(type='CovType')
), by default, a Gaussian field
with the corresponding covariance structure is simulated.
By default, the simulation method is chosen automatically through internal algorithms.
The simulation method can be set explicitly by enclosing the
covariance function with a method specification.
If other than Gaussian fields are to be simulated, the model
argument must be enclosed by a function specifying the type of the
random field.
There are different possibilities of passing the locations at which
the field is to be simulated. If grid=FALSE
, all coordinate
vectors (except for the time component $T$) must have the same
length and the field is only simulated at the locations given by the
rows of $x$ or of cbind(x, y, z)
. If $T$ is not
missing, the field is simulated for all combinations
$(x[i, ], T[k])$ or $(x[i], y[i], z[i], T[k])$,
$i=1, ...,$nrow(x)
, $k=1, ...,$length(T)
,
even if model
is not explicitly a space-time model.
If grid=TRUE
, the vectors x
,
y
, z
and T
or the columns of x
and
T
are
interpreted as a grid definition, i.e. the field is simulated at all
locations $(x_i, y_j, z_k, T_l)$, as given by
expand.grid(x, y, z, T)
.
Here, c(from, stepsize, len)
is used:
If x
, y
,
z
, T
or the columns of x
are of length 3, they
are internally replaced by seq(from=from,
to=from+(len-1)*stepsize, by=stepsize)
, i.e. the field
is simulated at all locations
expand.grid(seq(x$from, length.out=x$len, by=x$stepsize),
seq(y$from, length.out=y$len, by=y$stepsize),
seq(z$from, length.out=z$len, by=z$stepsize),
seq(T$from, length.out=T$len, by=T$stepsize))
If data
is passed, conditional simulation is performed.
RFsp
,ncol(data@coords)
must equal the dimension of the index
space. Ifdata@data
contains only a single variable,
variable names are optional. Ifdata@data
contains
more than one variable, variables must be named andmodel
must be given in the tilde notationresp ~ ...
(see"resp"
must be contained
innames(data@data)
.data
is a matrix or a data.frame, eitherncol(data)
equals$(dimension of index space + 1)$and the order of the
columns is (x, y, z, T, response) or, ifdata
contains
more than one
response variable (i.e.ncol(data) > (dimension of index
space + 1)
),colnames(data)
must containcolnames(x)
or those of"x", "y", "z", "T"
that
are not missing. The response variable name is matched withmodel
, which must be given in the tilde notation. If"x", "y", "z", "T"
are missing anddata
containsNA
s,colnames(data)
must contain an element which starts
withx
is missing,NA
s in the data and performs a conditional simulation
for them. Specification of err.model
:
In geostatistics we have two different interpretations of a nugget
effect: small scale variability and measurement error.
The result of conditional simulation usually does not include the
measurement error. Hence the measurement error err.model
must be given separately. For sake of generality, any model (and not
only the nugget effect) is allowed.
Consequently, err.model
is ignored
when unconditional simulation is performed.
Original work:
Wood, A.T.A. and Chan, G. (1994) Simulation of stationary Gaussian processes in$[0,1]^d$J. Comput. Graph. Stat.3, 409-432.
The code used inRandomFieldsis based on Dietrich and Newsam (1996).
Matheron, G. (1973) The intrinsic random functions and their applications.Adv. Appl. Probab.5, 439-468.
Schlather, M. (2004) Turning layers: A space-time extension of turning bands.Submitted
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
\dontrun{
#############################################################
## ##
## Example 1: Specification of simulation method ##
## ##
#############################################################
## usage of a specific method
## -- the complete list is obtained by RFgetMethodNames()
model <- RMstable(alpha=1.5)
x <- runif(100, max=20)
y <- runif(100, max=20) # 100 points in 2 dimensional space
simulated <- RFsimulate(model = RPdirect(model), x=x, y=y,
cPrint=3) # direct matrix decomposition
plot(simulated)
#############################################################
## ##
## Example 2: Turnung band with different number of lines ##
## ##
#############################################################
model <- RMstable(alpha=1.5)
x <- seq(0, 10, if (interactive()) 0.01, 1)
z <- RFsimulate(model = RPtbm(model), x=x, y=x, grid=TRUE)
plot(z)
#############################################################
## ##
## Example 3: Shot noise fields (random coins) ##
## ##
#############################################################
x <- GridTopology(0, .1, 500)
z <- RFsimulate(model=RPpoisson(RMgauss()), x=x, mpp.intensity = 100)
plot(z)
par(mfcol=c(2,1))
plot(z@data[,1:min(length(z@data), 1000)], type="l")
hist(z@data[,1])
z <- RFsimulate(x=x, model=RPpoisson(RMball()), mpp.intensity = 0.1)
plot(z)
par(mfcol=c(2,1))
plot(z@data[,1:min(length(z@data), 1000)], type="l")
hist(z@data[,1])
#############################################################
## ##
## Example 4: a 2d random field based on ##
## covariance functions valid in 1d only ##
## ##
#############################################################
x <- seq(0, 2, 0.1)
model <- RMfbm(alpha=0.5, Aniso=matrix(nrow=1, c(1, 0))) +
RMfbm(alpha=0.9, Aniso=matrix(nrow=1, c(0, 1)))
z <- RFsimulate(x, x, grid=TRUE, model=model)
plot(z)
#############################################################
## ##
## Example 5 : Brownian sheet ##
## (using Stein's method) ##
## ##
#############################################################
# 2d
step <- 0.3 ## nicer, but also time consuming if step = 0.1
x <- seq(0, 5, step)
alpha <- 1 # in [0,2)
z <- RFsimulate(x=x, y=x, grid=TRUE, model=RMfbm(alpha=alpha))
plot(z)
# 3d
z <- RFsimulate(x=x, y=x, z=x, grid=TRUE,
model=RMfbm(alpha=alpha))
}
FinalizeExample()
Run the code above in your browser using DataLab