#Example 1
#Compute Hurst's K estimate of H
data(NileMin)
HurstK(NileMin)
GetFitFGN(NileMin)
#Example 2
#Script for comparing FGN/ARMA forecast performance
#
## Not run:
# data(NileMin)
# outNileMin<-FitFGN(NileMin)
# set.seed(12177)
# z<-Boot(outNileMin)
# n<-length(z)
# K<-100 #number of out-of-sample data values
# z1<-z[1:(length(z)-K)] #training data
# z2<-z[-(1:(length(z)-K))] #testing data
# #
# #FGN fit to z1 and forecast using z2
# maxLead<-3
# n1<-length(z1)
# outz1<-FitFGN(z1)
# H<-outz1$H
# mu<-outz1$muHat
# rFGN<-var(z1)*acvfFGN(H, n + maxLead -1)
# F<-TrenchForecast(c(z1,z2), rFGN, mu, n1, maxLead=maxLead)$Forecasts
# nF<-nrow(F)
# err1<-z2-F[,1][-nF]
# err2<-z2[-1]-F[,2][-c(nF,(nF-1))]
# err3<-z2[-c(1,2)]-F[,3][-c(nF,(nF-1),(nF-2))]
# rmse1<-sqrt(mean(err1^2))
# rmse2<-sqrt(mean(err2^2))
# rmse3<-sqrt(mean(err3^2))
# FGNrmse<-c(rmse1,rmse2,rmse3)
# #
# #ARMA(p,q) fit to z1 and forecast using z2
# p<-2
# q<-1
# ansz1<-arima(z1, c(p,0,q))
# phi<-theta<-numeric(0)
# if (p>0) phi<-coef(ansz1)[1:p]
# if (q>0) theta<-coef(ansz1)[(p+1):(p+q)]
# zm<-coef(ansz1)[p+q+1]
# sigma2<-ansz1$sigma2
# vz<-tacvfARMA(phi=phi, theta=theta, sigma2=sigma2, maxLag=0)
# r<-vz*ARMAacf(ar=phi, ma=theta, lag.max=n + maxLead -1)
# F<-TrenchForecast(c(z1,z2), r, zm, n1, maxLead=3)$Forecasts
# err1<-z2-F[,1][-nF]
# err2<-z2[-1]-F[,2][-c(nF,(nF-1))]
# err3<-z2[-c(1,2)]-F[,3][-c(nF,(nF-1),(nF-2))]
# rmse1<-sqrt(mean(err1^2))
# rmse2<-sqrt(mean(err2^2))
# rmse3<-sqrt(mean(err3^2))
# ARMArmse<-c(rmse1,rmse2,rmse3)
# #
# #tabulate result
# tb<-matrix(c(FGNrmse,ARMArmse),ncol=2)
# dimnames(tb)<-list(c("lead1","lead2","lead3"),c("FGN","ARMA"))
# ## End(Not run)
Run the code above in your browser using DataLab