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
|
R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
> library(mcmc)
>
> set.seed(42)
>
> n <- 1e5
> rho <- 0.99
>
> x <- arima.sim(model = list(ar = rho), n = n)
> gamma <- acf(x, lag.max = 1999, type = "covariance",
+ plot = FALSE)$acf
> k <- seq(along = gamma)
> Gamma <- gamma[k %% 2 == 1] + gamma[k %% 2 == 0]
> k <- min(seq(along = Gamma)[Gamma < 0])
> Gamma <- Gamma[1:k]
> Gamma[k] < 0
[1] TRUE
> Gamma[k] <- 0
>
> out <- .Call(mcmc:::C_initseq, x - mean(x))
> names(out)
[1] "gamma0" "Gamma.pos" "Gamma.dec" "Gamma.con" "var.pos" "var.dec"
[7] "var.con"
>
> all.equal(gamma[1], out$gamma0)
[1] TRUE
>
> length(out$Gamma.pos) == length(Gamma)
[1] TRUE
> all.equal(out$Gamma.pos, Gamma)
[1] TRUE
>
> Gamma.dec <- cummin(Gamma)
> all.equal(out$Gamma.dec, Gamma.dec)
[1] TRUE
>
> library(Iso)
Iso 0.0-17
> Gamma.con <- Gamma.dec[1] + cumsum(c(0, pava(diff(Gamma.dec))))
> all.equal(out$Gamma.con, Gamma.con)
[1] TRUE
>
> all.equal(0, min(out$Gamma.pos - out$Gamma.dec))
[1] TRUE
> max(diff(out$Gamma.dec)) < sqrt(.Machine$double.eps)
[1] TRUE
>
> all.equal(0, min(out$Gamma.dec - out$Gamma.con))
[1] TRUE
> min(diff(diff(out$Gamma.con))) > (- sqrt(.Machine$double.eps))
[1] TRUE
>
> all.equal(2 * sum(out$Gamma.pos) - out$gamma0, out$var.pos)
[1] TRUE
> all.equal(2 * sum(out$Gamma.dec) - out$gamma0, out$var.dec)
[1] TRUE
> all.equal(2 * sum(out$Gamma.con) - out$gamma0, out$var.con)
[1] TRUE
>
> rev(out$Gamma.pos)[1] == 0
[1] TRUE
> rev(out$Gamma.dec)[1] == 0
[1] TRUE
> all.equal(rev(out$Gamma.con)[1], 0)
[1] TRUE
>
>
> proc.time()
user system elapsed
0.688 0.016 0.695
|