Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37f7882
commit d49d7e5
Showing
33 changed files
with
1,237 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
Package: FGN | ||
Version: 2.0-1 | ||
Date: 2012-12-10 | ||
Title: Fractional Gaussian Noise (FGN) and simple models for hyperbolic | ||
decay time series | ||
Version: 2.0-4 | ||
Date: 2013-03-11 | ||
Title: Fractional Gaussian Noise and hyperbolic decay time series model | ||
fitting | ||
Author: A.I. McLeod and Justin Veenstra | ||
Maintainer: A.I. McLeod <aimcleod@uwo.ca> | ||
Depends: R (>= 2.1.0), ltsa, hypergeo, akima | ||
Description: Efficient exact MLE and Whittle MLE estimation of four | ||
simple long memory time series models. | ||
Depends: R (>= 2.1.0), ltsa, akima | ||
Description: Exact MLE and Whittle MLE estimation for various | ||
hyperbolic decay time series models. | ||
Classification/ACM: G.3, G.4, I.5.1 | ||
Classification/MSC: 62M10, 91B84 | ||
Imports: ltsa | ||
LazyLoad: yes | ||
LazyData: yes | ||
License: GPL (>= 2) | ||
License: CC BY-NC-SA 3.0 | ||
URL: http://www.stats.uwo.ca/faculty/aim | ||
Packaged: 2012-12-12 21:38:51 UTC; aim | ||
Packaged: 2013-03-11 21:33:58 UTC; IanMcLeod | ||
NeedsCompilation: yes | ||
Repository: CRAN | ||
Date/Publication: 2012-12-13 06:28:49 | ||
Date/Publication: 2013-03-12 09:52:55 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
`ARToPacf` <- | ||
function(phi){ | ||
phik=phi | ||
L=length(phi) | ||
if(L==0) return(0) | ||
pi=numeric(L) | ||
for (k in 1:L){ | ||
LL=L+1-k | ||
a <- phik[LL] | ||
pi[L+1-k] <- a | ||
phikp1 <- phik[-LL] | ||
if(is.na(a) || abs(a)==1) | ||
stop("transformation is not defined, partial correlation = 1") | ||
phik <- (phikp1+a*rev(phikp1))/(1-a^2) | ||
} | ||
pi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`InvertibleQ` <- | ||
function(phi){ | ||
identical(TRUE,try(all(abs(ARToPacf(phi))<1),silent=TRUE)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
`PacfToAR` <- | ||
function(zeta){ | ||
L=length(zeta) | ||
if (L==0) return(numeric(0)) | ||
if (L==1) return(zeta) | ||
phik=zeta[1] | ||
for (k in 2:L){ | ||
phikm1=phik | ||
phik=c(phikm1-zeta[k]*rev(phikm1),zeta[k]) | ||
} | ||
phik | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
WLoglikelihood <- function(z, beta, p, q, lmodel) { | ||
ialpha <- ifelse(identical(lmodel,"NONE"), 0, 1) | ||
alpha <- ifelse(ialpha==1, beta[1], 1) | ||
phi <- theta <- numeric(0) | ||
n <- length(z) | ||
Ip <- (spec.pgram(z, fast=FALSE, detrend=FALSE, plot=FALSE, taper=0)$spec)/(2*pi) | ||
if (alpha<=0 || alpha >=2 || (ialpha==1&&(p>0||q>0)&&abs(beta[-1]) >= 1)) | ||
L <- LL <- (-n/2*log(sum(z^2)/n))-10^4 else { | ||
if(p>0) phi <- PacfToAR(beta[(1+ialpha):(p+ialpha)]) | ||
if(q>0) theta <- PacfToAR(beta[(ialpha+p+1):(p+q+ialpha)]) | ||
fp <- sdfhd(n, alpha=alpha, phi=phi, theta=theta, lmodel=lmodel) | ||
sigHat <- mean(Ip/fp) | ||
L <- ifelse(lmodel%in%c("FGN", "PLA", "PLS"), -2*sum(log(sigHat*fp)), -2*sigHat) | ||
r <- switch(lmodel, | ||
FD=tacvfARFIMA(phi = phi, theta = theta, dfrac = 0.5-alpha/2, maxlag = n-1), | ||
FGN=tacvfARFIMA(phi = phi, theta = theta, H = 1-alpha/2, maxlag = n-1), | ||
PLA=tacvfARFIMA(phi = phi, theta = theta, alpha = alpha, maxlag = n-1), | ||
NONE=tacvfARFIMA(phi = phi, theta = theta, maxlag = n-1) ) | ||
LL <- DLLoglikelihood(r, z) | ||
} | ||
ans <- c(L, LL) | ||
names(ans) <- c("Whittle", "Exact") | ||
ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
earfima <- function(z, order=c(0,0,0), lmodel=c("FD", "FGN", "PLA", "NONE")) { | ||
lmodel <- match.arg(lmodel) | ||
p <- order[1] | ||
d <- order[2] | ||
q <- order[3] | ||
stopifnot(p >= 0, q >= 0, d >= 0) | ||
is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol | ||
stopifnot(is.wholenumber(p), is.wholenumber(d), is.wholenumber(q)) | ||
w <- if(d>0) diff(z, differences=d) else z | ||
w <- w-mean(w) | ||
n <- length(w) | ||
alg <- 1 | ||
binit <- numeric(p+q+1) | ||
binit[1] <- 1 | ||
penaltyLoglikelihood <- (-n/2*log(sum(w^2)/n))*0.01 | ||
Entropy<-function(beta, p, q) { | ||
alpha <- beta[1] | ||
phi <- theta <- numeric(0) | ||
if (alpha<=0 || alpha >=2 || (p>0||q>0)&&abs(beta[-1]) >= 1) | ||
LL <- -penaltyLoglikelihood else { | ||
if(p>0) phi <- PacfToAR(beta[2:(p+1)]) | ||
if(q>0) theta <- PacfToAR(beta[(p+2):(p+q+1)]) | ||
r <- switch(lmodel, | ||
FD=tacvfARFIMA(phi = phi, theta = theta, dfrac = 0.5-alpha/2, maxlag = n-1), | ||
FGN=tacvfARFIMA(phi = phi, theta = theta, H = 1-alpha/2, maxlag = n-1), | ||
PLA=tacvfARFIMA(phi = phi, theta = theta, alpha = alpha, maxlag = n-1), | ||
NONE=tacvfARFIMA(phi = phi, theta = theta, maxlag = n-1) ) | ||
LL <- -DLLoglikelihood(r, w) | ||
} | ||
LL | ||
} | ||
if (p+q>0 || lmodel!="NONE") { | ||
ans<-optim(par=binit, fn=Entropy, p=p, q=q, method="L-BFGS-B", lower=c(0.01,rep(-0.99,p+q)), upper=c(1.99,rep(0.99,p+q)), control=list(trace=0)) | ||
if(ans$convergence != 0) {#convergence problem. Use Nelder-Mead with penalty function | ||
alg<-2 | ||
ans<-optim(par=binit, fn=Entropy, method="Nelder-Mead") | ||
} | ||
bHat <- ans$par | ||
LL <- -ans$value | ||
convergence <- ans$convergence | ||
} else { | ||
bHat <- numeric(0) | ||
LL <- -Entropy(1, 0, 0) | ||
convergence <- 0 | ||
} | ||
alphaHat <- bHat[1] | ||
HHat <- 1-alphaHat/2 | ||
dHat <- HHat - 0.5 | ||
phiHat <- thetaHat <- numeric(0) | ||
list(bHat=bHat, alphaHat=alphaHat, HHat = HHat, dHat=dHat, phiHat=phiHat, thetaHat=thetaHat, LL=LL, convergence=convergence) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
sdfarma <- function(n, phi=numeric(0), theta=numeric(0)) { | ||
lams <- 2*pi*seq(from=1/n, to=1/2, by=1/n) | ||
nf <- length(lams) | ||
a <- outer(lams, 1:length(theta)) | ||
if (length(theta)>0) { | ||
C <- cbind(1, cos(a))%*% c(1, -theta) | ||
S <- sin(a) %*% theta | ||
} else { | ||
C <- 1 | ||
S <- 0 | ||
} | ||
num <- as.vector(C*C + S*S)/(2*pi) | ||
if (length(phi)>0) { | ||
C <- cbind(1, cos(a))%*% c(1, -phi) | ||
S <- sin(a) %*% theta | ||
} else { | ||
C <- 1 | ||
S <- 0 | ||
} | ||
den <- as.vector(C*C+S*S) | ||
num/den | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sdfhd <- function(n, alpha=1, phi=numeric(0), theta=numeric(0), lmodel=c("FD", "FGN", "PLA", "NONE")) { | ||
lmodel <- match.arg(lmodel) | ||
if(!(InvertibleQ(phi)&&InvertibleQ(theta)&&alpha>0&&alpha<2)) | ||
stop("error: non-invertible or non-stationary") | ||
if(length(phi)==0&&length(theta)==0) s1 <- 1 else s1 <- 2*pi*sdfarma(n, phi, theta) | ||
s2 <- switch(lmodel, | ||
FD = sdfFD((1-alpha)/2, n), | ||
FGN = sdfFGN(1-alpha/2, n), | ||
PLA = sdfPLA(alpha, n), | ||
PLS = sdfPLS(alpha, n), | ||
NONE = sdfFGN(0.5, n)) | ||
s1*s2 | ||
} |
Oops, something went wrong.