Learn R Programming

geostatsp (version 0.7.0)

GaussRF: Simulate Gaussian Random Fields

Description

This function is a wrapper for the GaussRF function in the RandomFields package, where the arguments and output are Raster or SpatialPoints objects.

Usage

GaussRF(x, param=c(variance=1, range=1, rough=1), ...)
	## S3 method for class 'Raster':
GaussRF(x,param=c(variance=1, range=1, rough=1),...)
	## S3 method for class 'SpatialPoints':
GaussRF(x,param=c(variance=1, range=1, rough=1),...)
	## S3 method for class 'SpatialPointsDataFrame':
GaussRF(x,param=c(variance=1, range=1, rough=1),...)

Arguments

x
An object of class raster, SpatialPoints, or SpatialPointsDataFrame, or an object of a class acceptable to the GaussRF .
param
A vector of named model parameters with, at a minimum names variance, range and rough. For Geometric Anisotropy add aniso.ratio and either aniso.angle.degrees or aniso.angle.r
...
additional arguments, see GaussRF in the RandomFields package.

Value

  • If x is of class raster, a random field is simulated on a grid and returned as a raster. If x is of class Spatial Points or SpatialPointsDataFrame, a random field is simulated at the points specified and a vector is returned.

Details

The formula for the Matern correlation function is $$M(x) = \frac{variance}{\Gamma(rough)} 2^{rough-1} x (\sqrt{8 rough}/ range)^{rough} besselK(x \sqrt{8 rough}/ range, rough)$$

The range parameter is sqrt(8*rough)*phi (for phi in the geoR package), sqrt(8*rough)*scale (for 'scale' as in the whittle model in RandomFields), and 2*scale (for 'scale' in the matern model in RandomFields).

If an argument model is specified, parameters are passed directly to the RandomFields package and the parametrizations from that package are used.

Examples

Run this code
mymodel = c(variance=1, range=2, rough=2, aniso.ratio=0.6, aniso.angle.degrees=30)

myraster = raster(nrows=40,ncols=40,xmn=-20,xmx=20,ymn=-15,ymx=15)

myGRF=GaussRF(myraster, param=mymodel)

plot(myGRF, main="a GRF")

mypoints = SpatialPointsDataFrame(cbind(runif(10), runif(10)),data=data.frame(id=1:10))

mypoints$rf= GaussRF(mypoints, param=mymodel) 

spplot(mypoints, "rf", col.regions=terrain.colors(5), main="GRF at points")


x = cbind(sample(1:50), sample(1:50))
temp=GaussRF(x,  
		param=c(variance=1,	range=6, rough=2))
quantile(temp)

# passing parameters straight to RandomFields
fromRF = GaussRF(myraster, param=c(mean=0.5, variance=1, nugget=0, 
				scale=4, alpha=2), model="matern")
plot(fromRF, main="from RandomFields")

Run the code above in your browser using DataLab