File: RPmaxstableAdvanced.Rd

package info (click to toggle)
r-cran-randomfields 3.3.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,916 kB
  • sloc: cpp: 52,159; ansic: 3,015; makefile: 2; sh: 1
file content (125 lines) | stat: -rw-r--r-- 3,482 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
\name{Max-stable random fields, advanced }
\alias{maxstableAdvanced}
\alias{RPmaxstableAdvanced}


\title{Simulation examples of advanced Max-Stable Random Fields}
\description{
  Here, an advanced example is given used to test whether the
  algorithms work correctly.
}

%\details{
%}
\references{
  Strokorb, K. (2013) Ph.D. thesis.
}
\seealso{
  \command{\link{RPmaxstable}}
}

\me
\keyword{spatial}


\examples{\dontshow{StartExample()}%\dontshow{StartExample(reduced=50)}
\dontshow{\dontrun{
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
##                   RFoptions(seed=NA) to make them all random again

n <- 100

model <- RMexp(var=1.62 / 2) 
x <- seq(0, 5, 0.2)
y <- seq(0, 10, 0.2)


auswertung <- function(simu, model, threshold=2) {
  x <- as.vector(coordinates(simu))
  simu <- as.array(simu)
  below <- simu <= threshold
  freq <- rowMeans(below)
  meanfreq <- mean(freq)
  Print(freq, meanfreq, exp(-1/threshold)) ## univariate kontrolle
  both <- t(below) & below[1, ]
  ecf <-  2-log(colMeans(both)) / log(meanfreq)
  plot(x, ecf)

  ## alle 3 Linien ergeben das Gleiche:
  spC <- RFoptions()$general$spConform
  RFoptions(spConform = FALSE)
  lines(x, m1 <- RFcov(RMbrownresnick(model), x), col="yellow")
  lines(x, m2 <- RFcov(RMschlather(RMbr2eg(model)), x), col="red", lty=2) # OK
  m3 <- RFcov(RMbernoulli(RMbr2bg(model), centred=FALSE), x)
  lines(x, m3, col="blue", lty=3)
  RFoptions(spConform = spC)

  erfc <- function(x) 2 * pnorm(x, 0, sd=1/sqrt(2), lower=FALSE)
  lines(x, m4 <- erfc(0.45 * sqrt(1-exp(-x))), lty=4)
 
  ## theoretical curves correct?
  if (!all.equal(m1, m2) || !all.equal(m1, m3) || !all.equal(m1, m4))
    stop("calculation error")

  if ( (n <- ncol(simu)) >= 1000) {
    ## margins correct?
    mar.threshold <- 4 * 0.5 / sqrt(n)
    mmar.threshold <- 3 * 0.5 / sqrt(n)
    Print(abs(freq - exp(-1/threshold)), mar.threshold)
    if (abs(freq[sample(length(freq), 1)] - exp(-1/threshold)) > mar.threshold)
      stop("marginal distribution wrong? (single margin)")
    if (abs(meanfreq - exp(-1/threshold)) > mmar.threshold)
      stop("marginal distribution wrong? (mean margin)")
 
    ## extremal correlation function correct?
    meanthreshold <- 4 / sqrt(n)
    maxthreshold <- 2 * sqrt(nrow(simu)) / sqrt(n)
    Print(abs(ecf - m1), meanthreshold, maxthreshold)
    if (mean(abs(ecf - m2)) > meanthreshold)
      stop("ecf not correct? (mean deviation too large)")
    if (max(abs(ecf - m2)) > maxthreshold)
      stop("ecf not correct? (max deviation too large)")
  }
}


## BR currently not programmed
\dontshow{\dontrun{ ## to to
## Brown-Resnick
z <- RFsimulate(RPbrownresnick(model), y, y)
plot(z)
simu <- RFsimulate(RPbrownresnick(model), x, n=n,  max_gauss=5)
auswertung(simu, model)
}}

%\dontshow{\dontrun{ ## Windows hat Fehler. Unklar wieso
## Extremal Gaussian
z <- RFsimulate(RPschlather(RMbr2eg(model)), y, y)
plot(z)
simu <- RFsimulate(RPschlather(RMbr2eg(model)), x,  n=n)
auswertung(simu, model)

## Extremal Binary Gaussian
binary.model <- RPbernoulli(RMbr2bg(model))
z <- RFsimulate(RPschlather(binary.model), y, y)
plot(z)
simu <- RFsimulate(RPschlather(binary.model), x, n=n, max_gauss=5)
auswertung(simu, model)


\dontshow{\dontrun{ ## OK!
zaehler <- 0
repeat {
  Print(zaehler)
  zaehler <- zaehler + 1
  simu <- RFsimulate(RPschlather(RMbr2eg(model)), x, spConform=FALSE, n=n,
                    pch="")
  auswertung(simu, model)
}
}}

}}

\dontshow{FinalizeExample()}

}