Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38ef9b3

Browse files
committed
Add in Fay-Philippe test; Remove Ljung-Box test which is probably not valid.
1 parente06f6e9 commit38ef9b3

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

‎NAMESPACE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ importFrom(pracma,deconv)
5858
importFrom(pracma,grad)
5959
importFrom(pracma,hessian)
6060
importFrom(pracma,pinv)
61+
importFrom(pracma,psi)
6162
importFrom(pso,psoptim)
6263
importFrom(signal,Arma)
6364
importFrom(signal,filter)

‎R/garma-package.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' @importFrom pso psoptim
1313
#' @importFrom dfoptim hjkb nmkb
1414
#' @importFrom GA de
15-
#' @importFrom pracma pinv hessian conv deconv grad
15+
#' @importFrom pracma pinv hessian conv deconv grad psi
1616
#' @importFrom signal Arma filter
1717
#' @importFrom zoo zoo index
1818
#' @importFrom tswge factor.wge

‎R/garma_main.R‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,11 @@ garma<-function(x,
402402
'var.coef'=vcov1,
403403
'sigma2'=sigma2,
404404
'obj_value'=fit$value,
405+
'obj_par'=fit$par,
405406
'loglik'=loglik,
406407
'aic'=-2*loglik+2*(n_coef+1),
407408
'model'=model,
409+
'spectrum'=ss,
408410
'convergence'=fit$convergence,
409411
'conv_message'=c(fit$message,message),
410412
'method'=method,

‎R/tsdiag.R‎

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,47 @@ tsdiag.garma_model<-function(object, gof.lag = 10, ...) {
1919
titles<- .generate_default_plot_title(object,h=0)
2020

2121
## plot standardized residuals, acf of residuals, Ljung-Box p-values
22-
oldpar<- par(mfrow= c(3,1))
22+
oldpar<- par(mfrow= c(2,1))
2323
on.exit(par(oldpar))
2424
rs<-object$residuals
2525
stdres<-rs/sqrt(object$sigma2)
26-
plot(stdres,type="h",main="Standardized Residuals",ylab="")
26+
plot(stdres,type="h",main=paste(object$series,"-Standardized Residuals"),ylab="")
2727
abline(h=0)
28-
acf(as.numeric(object$residuals),plot=TRUE,main="ACF of Residuals",na.action=na.pass)
29-
#pacf(as.numeric(object$residuals), plot = TRUE, main = "PACF of Residuals", na.action = na.pass)
30-
nlag<-gof.lag
31-
pval<- rep(NA,nlag)
32-
n_param<-object$order[1]+object$order[3]+object$k
33-
for(iin1L:nlag)pval[i]<- Box.test(rs,i,type="Ljung-Box",fitdf=ifelse(i>n_param,n_param,0))$p.value
34-
plot(1L:nlag,pval,xlab="Lag",ylab="p value",ylim= c(0,1),xaxp=c(1,nlag,nlag-1),
35-
main="p values for Ljung-Box statistic",sub=titles$sub)
36-
abline(h=0.05,lty=2,col="blue")
28+
acf(as.numeric(object$residuals),plot=TRUE,
29+
main= paste(object$series," - ACF of Residuals"),
30+
sub=titles$sub,
31+
na.action=na.pass)
32+
# nlag <- gof.lag
33+
# pval <- rep(NA,nlag)
34+
# n_param <- object$order[1]+object$order[3]+object$k
35+
# for(i in 1L:nlag) pval[i] <- Box.test(rs, i, type="Ljung-Box", fitdf=ifelse(i>n_param,n_param,0))$p.value
36+
# plot(1L:nlag, pval, xlab = "Lag", ylab = "p value", ylim = c(0,1), xaxp=c(1,nlag,nlag-1),
37+
# main = "p values for Ljung-Box statistic", sub=titles$sub)
38+
# abline(h = 0.05, lty = 2, col = "blue")
39+
#
40+
# cat('NOTE: The degrees of freedom for the Ljung-Box statistic are determined differently\n')
41+
# cat(' to the standard R "tsdiag". An adjustment is made for the number of model\n')
42+
# cat(' parameters as per Ljung & Box (1978).\n')
43+
# cat(' Note also that the Ljung-Box test has not been formally established as valid\n')
44+
# cat(' for GARMA processes.\n')
3745

38-
cat('NOTE: The degrees of freedom for the Ljung-Box statistic are determined differently\n')
39-
cat(' to the standard R "tsdiag". An adjustment is made for the number of model\n')
40-
cat(' parameters as per Ljung & Box (1978).\n')
41-
cat(' Note also that the Ljung-Box test has not been formally established as valid\n')
42-
cat(' for GARMA processes.\n')
46+
# Fay & Philippe (2002) spectral test for gof.
47+
ss<-object$spectrum
48+
n_freq<- length(ss$spec)
49+
mean_methods<- c('QML','CSS')
50+
params<-list(y=object$y,orig_y=object$diff_y,ss=ss,p=object$order[1],q=object$order[3],d=object$order[2],k=object$k,
51+
include.mean=object$include.mean,include.drift=object$include.drift,drift=object$model$drift,
52+
method=object$method,
53+
est_mean=ifelse(object$method%in%mean_methods,TRUE,FALSE),
54+
scale=sd(object$y),m_trunc=object$m_trunc)
55+
56+
spec_den_inv<- .calc_spec_den_inv(object$obj_par,params)
57+
58+
I_f<-ss$spec*spec_den_inv/ (2*pi*n_freq)
59+
s<- log(mean(I_f,na.rm=TRUE))- mean(log(I_f),na.rm=TRUE)- digamma(1)# (-digamma(1)) == Euler-Mascheroni constant
60+
s_sigma2<-pracma::psi(1,1)
61+
s2<-s/s_sigma2
62+
p<-1-pnorm(s2)
63+
64+
cat(sprintf('Fay-Philippe Goodness of Fit test.\n\nz-Statistic: %0.4f\np-value: %0.4f\n',s2,p))
4365
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp