Learn R Programming

geostatsp (version 0.9.9)

RFsimulate: Simulation of Random Fields

Description

This function simulates conditional and unconditional Gaussian random fields: Here, only the simulation of Gaussian random fields is described. For other kind of random fields (binary, max-stable, etc.) or more sophisticated approaches see RFsimulateAdvanced.

Usage

RFsimulate(model, x, y=NULL, z=NULL, T=NULL, grid,
 data, distances, dim, err.model, n=1, ...)
modelRandomFields(param, includeNugget=FALSE)

Arguments

model
object of class RMmodel, a vector of named model parameters, or a matrix where each column is a model parameter
x
vector of x coordinates, or object which can be coerced to GridTopology.
y
optional vector of y coordinates
z
optional vector of z coordinates
T
optional vector of time coordinates, T must always be an equidistant vector. Instead of T=seq(from=From, by=By, len=Len) one may also write T=c(From, By, Len).
grid
logical; RandomFields can find itself the correct value in nearly all cases. See also RFsimulateAdvanced.
data
For conditional simulation and random imputing only. If data is missing, unconditional simulation is performed.Object of class SpatialPointsDataFrame; coordinates and
distances
another alternative to pass the (relative) coordinates.
dim
Only used if distances are given.
err.model
For conditional simulation and random imputing only. Usually err.model=RMnugget(var=var), or not given at all (error-free measurements).
n
number of realizations to generate.
...
for advanced use: further options and control parameters for the simulation that are passed to and processed by RFoptions
param
A vector of named parameters
includeNugget
If FALSE, the nugget parameter is ignored.

Value

  • If x is a raster, RFsimulate returns a RasterLayer or RasterBrick is returned. Otherwise a SpatialPointsDataFrame or SpatialGridDataFrame . modelRandomFields returns an object of class RMmodel.

Details

If model is a matrix, a different set of parameters is used for each simulation. If data has the same number of columns as model has rows, a different column i is used with parameters in row i.

See Also

RFsimulate, RFempiricalvariogram, RFfit, RFgetModelInfo, RFgui, RMmodel, RFoptions, RFsimulateAdvanced, RFsimulate.more.examples

Examples

Run this code
model <- c(var=5, range=1,shape=0.5)


RandomFields::plot(modelRandomFields(model))

myraster = raster(nrows=60,ncols=60,xmn=0,ymn=0,xmx=10,ymx=10, 
		crs="+init=epsg:2081")

set.seed(0) 

simu <- geostatsp::RFsimulate(model, x=myraster, n=3)


plot(simu[[2]])



data("swissRain")
swissRain$sqrtrain = sqrt(swissRain$rain)


# estimate parameters
swissRes =  lgm(swissRain, locations=20, formula="sqrtrain",
	covariates=swissAltitude,  
	shape=1, fixShape=TRUE,
	aniso=FALSE, nugget=0, fixNugget=TRUE,
	nuggetInPrediction=FALSE
	)


# simulate from the random effect conditional on
#   the observed data

swissSim = geostatsp::RFsimulate(model=swissRes$param,
	data=swissRes$resid,
	x=swissRes$predict,
	n=3
)

# plot the simulated random effect
plot(swissSim[[1]])
plot(swissBorder, add=TRUE)

Run the code above in your browser using DataLab