Skip to content

Commit

Permalink
version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Wioletta Wojtowicz authored and cran-robot committed Feb 26, 2013
1 parent 58d0276 commit bdf681f
Show file tree
Hide file tree
Showing 31 changed files with 769 additions and 669 deletions.
9 changes: 5 additions & 4 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: perARMA
Type: Package
Title: Package for Periodic Time Series Analysis
Version: 1.3
Date: 2013-01-26
Version: 1.4
Date: 2013-02-22
Author: Anna Dudek, Harry Hurd and Wioletta Wojtowicz
Maintainer: Wioletta Wojtowicz <wwojtowi@agh.edu.pl>
Description: The package includes procedures for identification, model
Expand All @@ -13,6 +13,7 @@ License: GPL (>= 2.0)
Depends: R (>= 2.12.2)
Imports: corpcor, gnm, matlab, Matrix, signal
LazyLoad: yes
Packaged: 2013-01-26 17:55:59 UTC; Administrator
Packaged: 2013-02-26 16:36:33 UTC; Administrator
NeedsCompilation: no
Repository: CRAN
Date/Publication: 2013-01-26 19:04:05
Date/Publication: 2013-02-26 18:04:51
59 changes: 30 additions & 29 deletions MD5
@@ -1,35 +1,36 @@
22f72e22d481c346eaeefcf4a58b1ba8 *DESCRIPTION
cf1e7d59905a99714f8c8584bc18ccf5 *NAMESPACE
cc6480fe3932b6d519910ec8b6ee004b *DESCRIPTION
e7042692e7b99fec882e9ea7f6b3945f *NAMESPACE
d0e7f7a82b2d432a419b6a2ecfe4da54 *R/B2R.R
52770d3262c996755e5d229aa35338d6 *R/Bcoeff.R
77e41f9e4e8d4998702edb2721b4171d *R/Bcoeffa.R
2ca886418d9479a5db27bbfcfb41b9a0 *R/Bcoeff.R
edf6097efc1a23487268b361c09306ca *R/Bcoeffa.R
c62687f233039a4f5a9d64f4759e31fc *R/R_w.R
2aeedb17ae421e79750d4205f19e56e1 *R/R_w_ma.R
5110daa0544e84d2f7c4ebb1f2f6b99a *R/RparmaT.R
02b780e2c3d9a709a3b60d9db5c98b1c *R/ab2phth.R
dc341778f524a5fb1e13d9407f67a447 *R/acfpacf.R
f3e77f968d757ca5fd79ce43502267ae *R/acfpacf.R
c884ec9b595268a0b8c48a7a1da71872 *R/acfpacf.acf.R
e155ba91dd0ebbaeefad9f987ee563ec *R/acfpacf.pacf.R
b0233505aa3a96c06260ba73ae49e407 *R/loglikec.R
803a328880042b1e321d45a4c1c7d0d3 *R/loglikec.R
8cfa719e40fa198eb8e3e45534e21ce0 *R/loglikef.R
7f300783036798e96f0c7cb3effd38d6 *R/makepar.R
33a4273b176326c8b03e34f70935d6d1 *R/makeparma.R
4a2b6479a0ba2a4ba66fe054d28a68b2 *R/nancorr.R
e903d92b472ffa272108b83c8ad177e2 *R/parma_ident.R
4e59f04f8a4b83a47d305a95eff50dbc *R/parmaf.R
a36c0822d451a3432430b8b6a84f4ce7 *R/parmafil.R
f755f4a40d046e727013bb8ddb9c3571 *R/parmaf.R
b65201152c2a8ba6481a964fdd674f0b *R/parmafil.R
2660b59646fa28827dce4e3aa9b77685 *R/parmaresid.R
65a9bff0b559a16f6921126aa0b9eacd *R/perARMA-internal.R
20f38cea94ef49310236fbad6d5454ec *R/perYW.R
c637e96733074c3c17bfd1b09483c8e5 *R/peracf.R
82438b186ab3c3cb04d85b70f1597fa1 *R/permest.R
11dab4fc214de70822bea8038d9efe39 *R/peracf.R
ec6b39a77f56efa508db6b77a8ae9411 *R/permest.R
d47782117aa8efd9cc76827172bcbf62 *R/perpacf.R
3bee0050e84990cc41f716b3b5d2a1ac *R/persigest.R
29d0e0899837a64ef20ca79e0939291b *R/persigest.R
792ce1782b1e600d8b04b2e41a579e67 *R/pgram.R
7caa14deb19c0a2fd78c5fcb718dd4cb *R/phth2ab.R
a82072d29a0190e1eafd5ab3e3c46b1d *R/ppfcoeffab.R
78b45e574912e040c05368d059424a12 *R/ppfplot.R
80b8977d522e9482c4f0c999b5ec5662 *R/predictperYW.R
a7557290c398a4063dcdf3999863a3ec *R/predseries.R
b191acfe474fa86df3e209a63dbc12e7 *R/ppfcoeffab.R
096217a784e95930de06d3cb93573fc6 *R/ppfplot.R
4296b58b0d101cd3c33b82e7dcc2f9a1 *R/predictperYW.R
1963a09b148459b6b80234b1fef7c157 *R/predseries.R
0a8cfaae72a7fd85b7a79e12ff491736 *R/rho.constant.test.R
3c43e22d60138e2d0369f79931c833a8 *R/rho.zero.test.R
d0b5aeed248c1c79612704eb8ed8f97c *R/rhoci.R
Expand All @@ -39,26 +40,26 @@ d0b5aeed248c1c79612704eb8ed8f97c *R/rhoci.R
3e70e7e9f011671136f5f6b59537507b *data/volumes.sep.rda
7b21c6d0fed65af0d7cdf6e426be8928 *demo/00Index
3f49c4fe703763b0aa1d462eae6366b9 *demo/perARMA.R
3d4ab7a38418eb59b565938c6f4400fa *man/Bcoeff.Rd
d569ddfaaffa0562ec11423493e6e65c *man/Bcoeff.Rd
e4cb2ee84d56affeca10260b3f765fcf *man/R_w_ma.Rd
245bed7d69aa109d7683f019481a5619 *man/ab2phth.Rd
ac03315ec94fc5b41350a5108ed0be8a *man/acfpacf.Rd
e7306d5a3f7592de2e263f1add437745 *man/ab2phth.Rd
b00054c650a6d25c754ae74ae46ec82a *man/acfpacf.Rd
795d1c14429a5f0d8162c4e55dadf24a *man/arosa.Rd
d8c4197c42d3991c2bc5ad49f15e6e39 *man/loglikec.Rd
b09ad462f97f1554668482c9f6c49dae *man/loglikef.Rd
e6c3cfefcbf714b49139529093a4193a *man/makeparma.Rd
bb7b146e6029724d6430d2114d995cf7 *man/loglikec.Rd
789367280f4b892d6e3c5af8785a91c6 *man/loglikef.Rd
1d46f32b39df1c25a4e46c1197ea42a8 *man/makeparma.Rd
62a4893295eed0a5d024e102a99db024 *man/parma_ident.Rd
5d0ef20e4d98f4d4b56d6d43c4baf1bd *man/parmaf.Rd
22c53686c679a58e4b02f0ec9679fc60 *man/parmafil.Rd
aa1a077a5de9adc9cd38ad321c67c201 *man/parmaf.Rd
9d6781c9788d815f17e9aa15361ca492 *man/parmafil.Rd
bde241521eafc03924659da69ab9597e *man/parmaresid.Rd
46fdfe8036fe531b4ca24fbeca7c69d4 *man/perARMA-package.Rd
2b0e92737a09ea65ee8a4e889a43a805 *man/perARMA-package.Rd
24b847838147e06a5955ef339bee27e0 *man/perYW.Rd
8479a188f86815cc7095015bdfe73ad9 *man/peracf.Rd
41eab8bec1e72e494c3fb44f9c125fe4 *man/permest.Rd
d6777a128ecabd376497c2099621595d *man/perpacf.Rd
f6b55e18e377f31a5544afe162aea010 *man/persigest.Rd
75b466ccbf5cae7b7b0ab8557192ea2b *man/peracf.Rd
e475eebae951f14740d8d48636899b31 *man/permest.Rd
ddc2d19d7e208eec08816071eb920c8b *man/perpacf.Rd
c31f68cd96d4138e0723e791c5bec9f5 *man/persigest.Rd
a1715f1935d607122269c8dff92e4134 *man/pgram.Rd
4a8d4bc6cfa2db446d46d659538652f9 *man/predictperYW.Rd
614f54b44d69ffe0ea77666958431422 *man/predictperYW.Rd
f27f7a2b649e833c4a454f510e23935f *man/scoh.Rd
66b72e60499fbeac3c5438b9f6f65fc9 *man/volumes.Rd
2decf951b391e6984feabe44d39eb493 *man/volumes.sep.Rd
2 changes: 1 addition & 1 deletion NAMESPACE
@@ -1,4 +1,4 @@
export(
pgram, scoh, permest, persigest, peracf, Bcoeff, Bcoeffa, perpacf, ppfplot, ppfcoeffab, acfpacf.acf, acfpacf.pacf, acfpacf,

perYW, predictperYW, predseries, loglikec, parmafil, makeparma, R_w_ma, ab2phth, phth2ab, parma_ident, loglikef, parmaresid, parmaf)
perYW, predictperYW, predseries, loglikec, parmafil, makeparma, makepar, R_w_ma, ab2phth, phth2ab, parma_ident, loglikef, parmaresid, parmaf)
248 changes: 126 additions & 122 deletions R/Bcoeff.R
@@ -1,133 +1,137 @@
Bcoeff<-function(x,T,tau,missval,datastr,...)
Bcoeff<-function (x, T, tau, missval, datastr, ...)
{
Bcoeff_full<-function(x,T,tau,missval,datastr,printflg,meth)
{
Bcoeff_full <- function(x, T, tau, missval, datastr, printflg,
meth) {
nout = floor((T + 2)/2)
nx = length(x)
pmean1 <- matrix(0, nx, 1)
pmean <- matrix(0, T, 1)
numtau = length(tau)
Bkhat <- matrix(0, nout, numtau)
Rhokhat <- matrix(0, nout, numtau)
n1 <- matrix(1, nout, numtau)
n2 <- matrix(1, nout, numtau)
fratio <- matrix(1, nout, numtau)
pvec <- matrix(1, nout, numtau)
nsamp <- matrix(0, 1, numtau)
if (is.nan(missval)) {
missisnan = 1
imissx = x[(is.nan(x))]
}
else {
missisnan = 0
imissx = x[x == missval]
}
nmissx = length(imissx)
for (i in 1:T) {
index = seq(i, nx, T)
z = x[index]
if (missisnan) {
igood = which(!is.nan(z))
imiss = which(is.nan(z))
}
else {
igood = which((z != missval))
imiss = which((z == missval))
}
z = z[igood]
pmean[i] = mean(z)
x[index[imiss]] = pmean[i]
pmean1[index] = pmean[i]
}
xd = x - pmean1
for (k in 1:numtau) {
lag = tau[k]
alag = abs(lag)
indt = seq(1, (nx - alag))
indtt = seq((1 + alag), nx)
corlen = length(indt)
ncorper = floor(corlen/T)
ncor = ncorper * T
nsamp[k] = ncor
indt = indt[1:ncor]
indtt = indtt[1:ncor]
xx = xd[indt] * xd[indtt]
xxt = fft(xx)/ncor
xxt2 = abs(xxt)^2
kindex = seq(1, floor((ncor + 2 * ncorper)/2), ncorper)
nk = length(kindex)
Bkhat[, k] = xxt[kindex]
if (lag < 0) {
phase_correction = exp(i * 2 * pi * (kindex -
1) * lag/ncor)
Bkhat[, k] = Bkhat[, k] * phase_correction
}
if (meth == 0) {
kgood = setdiff(seq(1, floor(ncor/2)), kindex)
for (kk in 1:length(kindex)) {
if (kk == 1) {
n1[kk, k] = 1
}
else {
n1[kk, k] = 2
}
n2[kk, k] = 2 * length(kgood)
backav = sum(xxt2[kgood])/n2[kk, k]
num = (abs(Bkhat[kk, k])^2)/n1[kk, k]
fratio[kk, k] = num/backav
pvec[kk, k] = 1 - pf(fratio[kk, k], n1[kk,
k], n2[kk, k])
}
}
else {
if (meth >= ncorper) {
meth = 2 * floor((ncorper - 1)/2)
}
half = floor(meth/2)
for (kk in 1:length(kindex)) {
if (kk == 1) {
kgood = seq(2, (half + 1))
n1[kk, k] = 1
}
else {
if (T%%2 == 0 & kk == length(kindex)) {
center = kk * ncorper
kgood = seq((center - half), (center -
1))
n1[kk, k] = 1
}
else {
center = kk * ncorper
kgood = c(seq((center - half), (center -
1)), seq((center + 1), (center + half)))
n1[kk, k] = 2
}
}
n2[kk, k] = 2 * length(kgood)
backav = sum(xxt2[kgood])/n2[kk, k]
num = (abs(Bkhat[kk, k])^2)/n1[kk, k]
fratio[kk, k] = num/backav
pvec[kk, k] = 1 - pf(fratio[kk, k], n1[kk,
k], n2[kk, k])
}
}
}
if (printflg) {
for (k in 1:numtau) {
cat(paste("\n"))
cat(paste("Bcoeffs for", datastr, "lag=", tau[k],"\n"))

nout= floor((T+2)/2)
nx=length(x)
pmean1<-matrix(0,nx,1)
pmean<-matrix(0,T,1)
numtau=length(tau)
Bkhat<-matrix(0,nout,numtau)
Rhokhat<-matrix(0,nout,numtau)

n1<-matrix(1,nout,numtau)
n2<-matrix(1,nout,numtau)
fratio<-matrix(1,nout,numtau)
pvec<-matrix(1,nout,numtau)
nsamp<-matrix(0,1,numtau)


if (is.nan( missval))
{missisnan=1
imissx=x[(is.nan(x))]
} else {
missisnan=0
imissx=x[x==missval] }

nmissx=length(imissx)

for (i in 1:T)
{ index=seq(i,nx,T)
z=x[index]
if (missisnan)
{ igood=which(!is.nan(z))
imiss=which(is.nan(z))
} else {
igood=which((z!=missval))
imiss=which((z==missval))
}

z=z[igood]

pmean[i]=mean(z)
x[index[imiss]]=pmean[i]
pmean1[index]=pmean[i]
}
xd=x-pmean1

for (k in 1:numtau)
{ lag=tau[k]
alag=abs(lag)
indt=seq(1,(nx-alag))
indtt=seq((1+alag),nx)
corlen=length(indt)
ncorper=floor(corlen/T)
ncor=ncorper*T
nsamp[k]=ncor
indt=indt[1:ncor]
indtt=indtt[1:ncor]
xx=xd[indt]*xd[indtt]

xxt=fft(xx)/ncor
xxt2=abs(xxt)^2
kindex=seq(1,floor((ncor+2*ncorper)/2),ncorper)

nk=length(kindex)
Bkhat[,k]=xxt[kindex]
if (lag < 0)
{ phase_correction=exp(i*2*pi*(kindex-1)*lag/ncor)
Bkhat[,k]=Bkhat[,k]*phase_correction}

if (meth==0)
{ kgood=setdiff(seq(1,floor(ncor/2)),kindex)
for (kk in 1:length(kindex))
{ if (kk==1)
{n1[kk,k]=1
} else {
n1[kk,k]=2}

n2[kk,k]=2*length(kgood)
backav=sum(xxt2[kgood])/n2[kk,k]
num=(abs(Bkhat[kk,k])^2)/n1[kk,k]
fratio[kk,k]=num/backav
pvec[kk,k]=1-pf(fratio[kk,k],n1[kk,k],n2[kk,k])
}
} else {
if (meth >= ncorper)
{meth=2*floor((ncorper-1)/2)}
half=floor(meth/2)
for (kk in 1:length(kindex))
{if (kk==1)
{kgood=seq(2,(half+1))
n1[kk,k]=1
} else {
if (T %% 2 ==0 & kk==length(kindex))
{ center=kk*ncorper
kgood=seq((center-half),(center-1))
n1[kk,k]=1
}else {
center=kk*ncorper
kgood=c(seq((center-half),(center-1)),seq((center+1),(center+half)))
n1[kk,k]=2
}
}
n2[kk,k]=2*length(kgood)
backav=sum(xxt2[kgood])/n2[kk,k]
num=(abs(Bkhat[kk,k])^2)/n1[kk,k]
fratio[kk,k]=num/backav
pvec[kk,k]=1-pf(fratio[kk,k],n1[kk,k],n2[kk,k])
}
}
}

if ( printflg)
{ for (k in 1:numtau)
{ cat(paste('Bcoeffs for',datastr, 'lag=',tau[k],'\n'))
cat('k reB_k imB_k n1 n2 Fratio pv','\n')
for (kk in 1:dim(pvec)[1])
{ cat(paste(kk-1,Re(Bkhat[kk,k]),Im(Bkhat[kk,k]),n1[kk,k],n2[kk,k],fratio[kk,k], pvec[kk,k],'\n'))}
}
}

result = list(Bkhat = Bkhat, nsamp = nsamp, n1 = n1,
detail <- matrix(c(Re(Bkhat[,k]), Im(Bkhat[,k]), n1[,k], n2[,k], fratio[,k],pvec[,k]),ncol=6)
colnames(detail) <- c( "reB_k"," imB_k ", "n1", "n2", "Fratio", "pv")
row.names(detail)<-paste("k=",seq(0,(length(kindex)-1)), sep="")
print(detail)
}
}
result = list(Bkhat = Bkhat, nsamp = nsamp, n1 = n1,
n2 = n2, fratio = fratio, pvec = pvec)
class(result) = "Bcoeff"
result
}
}
L <- modifyList(list(printflg = 1, meth = 0), list(x = x,
T = T, tau = tau, missval = missval, datastr = datastr,
...))
do.call(Bcoeff_full, L)
}


0 comments on commit bdf681f

Please sign in to comment.