simField: Simulate A continous 2D spatial field using SPDE

Description Usage Arguments Value Examples

View source: R/simField.R

Description

Calculates a continous underlying spatial field for a given shape and uses an additive model to combine with covariates to create a final observed field which is a linear combination of covariates their beta values with an optional link function applied.

Usage

1
2
3
simField(N = 60, sigmaE = 1, rangeE = 0.3, rho = 0.95,
  shape = NULL, nTimes = 1, beta0 = 0, betaList = list(),
  link = arm::invlogit, ...)

Arguments

N

Number of width pixels for the projection

sigmaE

spatial variance

rangeE

spatial range

rho

temporal autocorrelation for AR1 process

shape

polygon object to populate, if NULL unit square is used

nTimes

number of time observations

beta0

itercept term added to all points

betaList

list of 2 item lists with a type item which is either random, cluster, or spatial and a value item which is the beta coefficient.

link

link function to apply to the linear combination

...

other parameters to pass to mesh

Value

field object, contains 7 items. Spatial points data frame with raster values for transformed linear combination, and beta value. A mesh that was used to create the latent field and possibly covariates. The latent field itself. A bounding shape where all observations take place. A projection matrix from the mesh to the entire field of interest. The spde for the matern approximation. The beta coefficients used to produce the underlying field.

Examples

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
## Not run: 
require(tidyr)
require(gridExtra)
require(ar.matrix)
require(dplyr)
require(ggplot2)

unitSim <- simField(
    N = 500, 
    offset = c(0.1, 0.2), 
    max.edge = c(0.05,0.2),
    beta0 = -2,
    betaList = list(
        list(type="random", value=2),
        list(type="spatial", value=-.5),
        list(type="cluster", value=-2)
    ))

plotList <- lapply(c("V1", "V2", "V3", "theta"), function(eff){
    unitSim$spdf@data %>%
        dplyr::select(-V0, -z) %>%
        gather("Effect", "Value", V1:theta) %>%
        filter(Effect==eff) %>%
        ggplot(aes(x, y, fill=Value)) +
        geom_raster() +
        coord_equal() +
        theme_void() +
        scale_fill_distiller(palette = "Spectral") +
        ggtitle(eff)
})

do.call(grid.arrange, c(plotList, ncol=2))

usSim <- simField(
    N = 600,
    shape = US.df,
    rangeE = 1.7,
    offset = c(1, 2),
    max.edge = c(.5, 1))

plot(usSim$mesh)
usSim$spdf@data  %>%
    ggplot(aes(x, y, fill=z)) +
    geom_raster() +
    coord_equal() +
    theme_void() +
    scale_fill_distiller(palette = "Spectral")


## End(Not run)

nmmarquez/PointPolygon documentation built on Dec. 10, 2020, 1:15 a.m.