Description Usage Arguments Details Value Note Author(s) References Examples
generates data from the Gaussian copula model with Negative Binomial or Poisson marginals of length n
1 | generate_data(n, a, b, marginal_dist, marginal_parameters)
|
n |
length of times series |
a |
autoregressive parameters |
b |
moving average parameters |
marginal_dist |
"poisson" or "nbinom" or "zeroinf_poisson" or "zeroinf_nbinom" |
marginal_parameters |
If negbin then c(nb.s, nb.p), If poisson then lambda |
Simulates 1 time series from the GCNB or GCP model
An integer-valued time series of length n
Marginals fixed to be Poisson, nb, zero_inf_poisson or zero_inf_negbin at present. The example below has ARMA(2,2) dependence structure, NB(p,s) marginal structure which is coupled together using a Gaussian copula Note:
"nbinom" uses p and s representation. "zeroinf_nbinom" uses negbinomial() which uses the alternate parametrization via mean mu and an index parameter k An alternative parametrization (often used in ecology) is by the mean mu, and size, the dispersion parameter, where prob = size/(size+mu). The variance is mu + mu^2/size in this parametrization.
Hannah Lennon <drhannahlennon@gmail.com>
Schmidt (2007)
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 | library("VGAM")
generate_data(4, 0.7, -0.5, "poisson", 3)
generate_data(4, 0.7, -0.5, "nbinom", c(3, 0.3))
generate_data(4, 0.7, -0.5, "zeroinf_poisson", 3)
generate_data(4, 0.7, -0.5, "zeroinf_nbinom", c(3, 0.3))
tabulate(generate_data(40, 0.7, -0.5, "nbinom", c(3, 0.5)) $x);
tabulate(generate_data(4, 0.7, -0.5, "zeroinf_nbinom", c(3, 0.5)) $x)
set.seed(12)
data <- generate_data(10000, c(0.2, 0.3), c(-0.1, 0.5), "nbinom", c(5, 0.5))
ins.data21 <- data$x
ins.data21y <- data$y
hist(ins.data21)
## Code currentlt is defined as:
function (n, a, b, marginal_dist, marginal_parameters){
if(marginal_dist=="poisson"){ lambda <- marginal_parameters[1]}
if(marginal_dist=="zeroinf_poisson"){lambda <- marginal_parameters[1]}
if(marginal_dist=="nbinom"){ nb.s <- marginal_parameters[1]
nb.p <- marginal_parameters[2]}
if(marginal_dist=="zeroinf_nbinom"){ nb.s <- marginal_parameters[1]
nb.p <- marginal_parameters[2]}
ar.sigma <- arma_cov(a, b, 0)
ar.sigma <- sqrt(1/ar.sigma)
if(a[1]==0){ y <- arima.sim(list(ma = b), n, sd = ar.sigma)}
else if(b[1]==0){ y <- arima.sim(list(ar = a), n, sd = ar.sigma)}
else{ y <- arima.sim(list(ar = a, ma = b), n, sd = ar.sigma)}
if(marginal_dist=="poisson") x <- qpois(pnorm(y), lambda)
if(marginal_dist=="nbinom") x <- qnbinom(pnorm(y), size = nb.s, prob = nb.p)
if(marginal_dist=="zeroinf_poisson") {
library(VGAM)
x <- qzipois(pnorm(y), lambda, pstr0 = 0)
}
if(marginal_dist=="zeroinf_nbinom") {
library(VGAM)
x <- qzinegbin(pnorm(y), size=nb.s, prob=nb.p, pstr0 = 0)
}
list(x = x, y = y)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.