Description Usage Arguments Details Value Author(s) Examples
View source: R/generate-grf-object.R
Creates a list containing the elements necessary for doing essential computations with the stationary GRF approximation.
1 2 3 4 5 | generate.grf.object(x.lower = -1, x.upper = 1, y.lower = -1,
y.upper = 1, resolution.x = 100, resolution.y = 100,
range.parameter = 1, scale.parameter = 1, strength.parameter = 0,
direction.parameter = 0, initial.seed = 0, params = NULL,
num.functions = NULL, function.names = NULL)
|
x.lower, x.upper, y.lower, y.upper |
Specifies the boundaries of the rectangular region that the GRF is defined on. |
resolution.x, resolution.y |
The number of grid cells used for the regular grid, in the x- and y-direction, respectively. |
range.parameter |
The range is a positive number. A small range gives functions
that tend to have more variation over shorter distances, while a long range leads to functions where the value changes more gradually.
The reciprocal 1/ |
scale.parameter |
The scale is a positive number that controls the scale of the
functions. Setting |
strength.parameter, direction.parameter |
These parameters are used to specify a range that depends on direction. If |
initial.seed |
The initial seed value used when generating functions. |
params |
Optional, a list containing all of the above parameters. |
num.functions |
The number of functions to initialize the object with. |
function.names |
The names of the functions to initialize the object with. |
If the object is to be initialized with functions, either num.functions
or function.names
must be specified.
An object (technically, a list) containing:
model.components |
A list containing the components defining the GRF: The precision matrix |
grid |
A |
initial.seed |
The initial seed value used when generating functions. |
params |
A list of the remaining input parameters listed above (except |
Mathias Isaksen mathiasleanderi@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | library(GRFics)
# Prepare GRF object on the square [-1, 1]^2 on a 25 x 25 grid
grf.object = generate.grf.object(-1, 1, -1, 1, 25, 25,
strength.parameter = 1,
direction.parameter = pi/4,
function.names = "Original",
initial.seed = 1000)
# Extract data frame containing the 25 x 25 grid coordinates and
# the value of the GRF in each grid cell.
original.df = get.function.df(grf.object)
# Interpolate GRF on finer grid for comparison
interp.locations = generate.grid.centers(-1, 1, -1, 1, 500, 500)
interp.df = evaluate.grf(interp.locations, grf.object, rescale.method = "none", return.df = TRUE)
interp.df$name = "Interpolation"
library(ggplot2)
ggplot()+
geom_raster(data = rbind(original.df, interp.df),
aes(x = x, y = y, fill = z))+
coord_fixed()+
facet_grid(cols = vars(name))
# Create and plot vector field, using the GRF to specify direction
vector.df = generate.grid.centers(-1, 1, -1, 1, 25, 25)
# Getting an angle that is between 0 and 2*pi. Using rescale.method = "uniform" ensures that every direction is equally represented.
vector.df$theta = 2*pi*evaluate.grf(vector.df, grf.object, rescale.method = "uniform")
vector.df$vx = 0.06*cos(vector.df$theta)
vector.df$vy = 0.06*sin(vector.df$theta)
# Plot of random vector field (should be viewed in a large window)
ggplot()+
geom_segment(data = vector.df, aes(x = x-vx/2, xend = x+vx/2,
y = y-vy/2, yend = y+vy/2),
arrow = arrow(length = unit(0.012, "npc")))+
coord_fixed()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.