CoSMoS - A Complete Stochatic Modelling Solution

Filip Strnad, Simon Papalexiou

2019-04-09

1 Step by step guide

1.1 Define marginal distribution

library(CoSMoS)

marginaldist <- 'burrXII'
para <- list(scale = 2,
             shape1 = .75,
             shape2 = .1)

1.2 Define prob. zero

p0 <- .9

1.3 Define model order and target ACS

order <- 100
targetcorr <- acfparetoII(t = 0:order, scale = 15, shape = .3)

1.4 Calculate ACTI points

p <- actpnts(marginaldist, para, p0 = p0)

1.5 Fit the points

f <- fitactf(p)
plot(f)

1.6 Run the AR(p) model

target <- ARp(margdist = marginaldist,
              margarg = para,
              actfpara = f,
              n = 100000,
              p0 = p0,
              p = order,
              acsvalue = targetcorr)

1.7 Check the gaussian empirical + target transformed and the target process ACF

gauss <- attr(target, 'gaussian')

ggplot() +
  geom_point(aes(x = 0:order,
                 y = as.vector(acf(gauss, lag.max = order, plot = F)$acf)), colour = 'red2', alpha = .2) +
  geom_line(aes(x = 0:order,
                y = attr(target, 'trACS')), colour = 'red4') +
  theme_bw() +
  labs(x = 'Lag',
       y = 'ACF',
       title = 'Gaussian ACS')

ggplot() +
  geom_point(aes(x = 0:order,
                 y = as.vector(acf(target, lag.max = order, plot = F)$acf)), colour = 'steelblue2', alpha = .2) +
  geom_line(aes(x = 0:order,
                y = targetcorr), colour = 'steelblue4') +
  theme_bw() +
  labs(x = 'Lag',
       y = 'ACF',
       title = 'Target ACS')

1.8 Check the simulation

checksimulation(target)
>             mean   sd  skew   p0 acf_t1 acf_t2 acf_t3
> expected    0.18 1.04 12.20 0.90   0.94   0.88   0.82
> simulation1 0.16 0.95 12.14 0.91   0.94   0.88   0.83

1.9 Or check the model in general

chck <- checkmodel(margdist = marginaldist,
                   margarg = para,
                   n = 100000,
                   p = order,
                   p0 = p0,
                   acsvalue = targetcorr,
                   TSn = 15,
                   plot = T)

knitr::kable(chck)
mean sd skew p0 acf_t1 acf_t2 acf_t3
expected 0.18 1.04 12.20 0.90 0.94 0.88 0.82
simulation1 0.24 1.24 9.34 0.89 0.94 0.89 0.84
simulation2 0.21 1.05 9.87 0.89 0.93 0.86 0.80
simulation3 0.15 0.85 9.91 0.91 0.92 0.85 0.78
simulation4 0.18 0.98 9.03 0.90 0.93 0.87 0.81
simulation5 0.19 1.02 10.53 0.89 0.93 0.87 0.81
simulation6 0.18 0.94 10.51 0.90 0.93 0.86 0.80
simulation7 0.19 0.98 11.23 0.89 0.93 0.87 0.81
simulation8 0.18 1.03 11.36 0.90 0.93 0.87 0.82
simulation9 0.15 0.85 10.72 0.91 0.92 0.86 0.80
simulation10 0.18 1.00 10.18 0.90 0.93 0.87 0.81
simulation11 0.16 1.18 26.29 0.91 0.94 0.90 0.87
simulation12 0.19 1.07 13.93 0.90 0.93 0.87 0.82
simulation13 0.19 1.05 10.28 0.90 0.94 0.88 0.83
simulation14 0.19 1.01 10.29 0.90 0.93 0.87 0.82
simulation15 0.16 0.95 10.74 0.91 0.93 0.87 0.82

2 Available distributions in CoSMoS package

Package CoSMoS supports majority of continuous distributions available in R with defined quantile and probability density functions. We also provide four widely used distributions - Burr type III and XII, Generalized gamma and Pareto type II distribution.

2.1 Burr type III distribution

distribution argument/name - burrIII
parameters - list(scale, shape1, shape2)

\[f_{\text{BrIII}}(x)=\frac{\left(\frac{x}{\beta }\right)^{-\frac{1}{\gamma _2}-1} \left(\frac{\left(\frac{x}{\beta }\right)^{-\frac{1}{\gamma _2}}}{\gamma _1}+1\right){}^{-\gamma _1 \gamma _2-1}}{\beta } \\ F_{\text{BrIII}}(x)=\left(\frac{\left(\frac{x}{\beta }\right)^{-\frac{1}{\gamma _2}}}{\gamma _1}+1\right){}^{-\gamma _1 \gamma _2} \\ Q_{\text{BrIII}}(u)=\beta \left(\gamma _1 \left(u^{-\frac{1}{\gamma _1 \gamma _2}}-1\right)\right){}^{-\gamma _2} \\ m_{\text{BrIII}}(q)=\frac{\beta ^q \gamma _1^{\gamma _2 (-q)} \Gamma \left(\left(q+\gamma _1\right) \gamma _2\right) \Gamma \left(1-q \gamma _2\right)}{\Gamma \left(\gamma _1 \gamma _2\right)}\]

2.2 Burr type XII distribution

distribution argument/name - burrXII
parameters - list(scale, shape1, shape2)

\[f_{\text{BrXII}}(x)=\frac{\left(\frac{x}{\beta }\right)^{\gamma _1-1} \left(\gamma _2 \left(\frac{x}{\beta }\right)^{\gamma _1}+1\right){}^{-\frac{1}{\gamma _1 \gamma _2}-1}}{\beta } \\ F_{\text{BrXII}}(x)=1-\left(\gamma _2 \left(\frac{x}{\beta }\right)^{\gamma _1}+1\right){}^{-\frac{1}{\gamma _1 \gamma _2}} \\ Q_{\text{BrXII}}(u)=\beta \left(-\frac{1-(1-u)^{-\gamma _1 \gamma _2}}{\gamma _2}\right){}^{\frac{1}{\gamma _1}} \\ m_{\text{BrXII}}(q)=\frac{\beta ^q \gamma _2^{-\frac{q}{\gamma _1}-1} B\left(\frac{q+\gamma _1}{\gamma _1},\frac{1-q \gamma _2}{\gamma _1 \gamma _2}\right)}{\gamma _1}\]

2.3 Generalized gamma distribution

distribution argument/name - ggamma
parameters - list(scale, shape1, shape2)

\[f_{\mathcal{G}\mathcal{G}}(x)=\frac{\gamma _2 e^{-\left(\frac{x}{\beta }\right)^{\gamma _2}} \left(\frac{x}{\beta }\right)^{\gamma _1-1}}{\beta \Gamma \left(\frac{\gamma _1}{\gamma _2}\right)} \\ F_{\mathcal{G}\mathcal{G}}(x)=Q\left(\frac{\gamma _1}{\gamma _2},0,\left(\frac{x}{\beta }\right)^{\gamma _2}\right) \\ Q_{\mathcal{G}\mathcal{G}}(u)=\beta Q^{-1}\left(\frac{\gamma _1}{\gamma _2},0,u\right){}^{\frac{1}{\gamma _2}} \\ m_{\mathcal{G}\mathcal{G}}(q)=\frac{\beta ^q \Gamma \left(\frac{q}{\gamma _2}+\frac{\gamma _1}{\gamma _2}\right)}{\Gamma \left(\frac{\gamma _1}{\gamma _2}\right)}\]

2.4 Paretto type II distribution

distribution argument/name - burrIII
parameters - list(scale, shape)

\[f_{\text{PII}}(x)=\frac{\left(\frac{\gamma x}{\beta }+1\right)^{-\frac{1}{\gamma }-1}}{\beta } \\ F_{\text{PII}}(x)=1-\left(\frac{\gamma x}{\beta }+1\right)^{-1/\gamma } \\ Q_{\text{PII}}(u)=\frac{\beta \left((1-u)^{-\gamma }-1\right)}{\gamma } \\ m_{\text{PII}}(q)=\frac{\Gamma (q+1) \left(\frac{\beta }{\gamma }\right)^q \Gamma \left(\frac{1}{\gamma }-q\right)}{\Gamma \left(\frac{1}{\gamma }\right)}\]

3 References

Papalexiou, S.M., 2018. Unified theory for stochastic modelling of hydroclimatic processes: Preserving marginal distributions, correlation structures, and intermittency. Advances in Water Resources 115, 234-252. link