[R] Problem with sapa package and spectral density function (SDF)
Jorge Garcia Molinos
garciamj at tcd.ie
Sun Jan 22 01:37:30 CET 2012
Hi everybody,
I'm a beginner R user and I'm trying to use the package "sapa" to
estimate the spectral density function of several time series using
the SDF function. For each time series, I want to calculate the
density function at two temporal resolutions (daily and monthly). The
monthly values calculated as a mean of the daily values. I first
create a ts object for both series and then run the SDF function. The
thing I can't figure out is why for the daily series the spectral
density function is calculated without problems and with the monthly
series an error always occurs. The R script I'm using (and the error)
is:
> dat <- read.table("Lakes.txt",header=T)
> sub.dat <- subset(dat,dat$Name=="White")
>
> sub.dat$mf <- as.factor(subdat$Month)
> sub.dat$yf <- as.factor(subdat$Year)
> sub.dat$ymf <- subdat$yf : subdat$mf
> sub.datm <- aggregate(subdat$DA,list(subdat$ymf),mean)
>
> serie.day <- ts(subdat$DA,start(sub.dat$Year[1],sub.dat$Day[1],frequency=365))
> n.d <- length(serie.day)
> espec.day <- SDF(serie.day,method="lag window",window=taper(type="parzen",n.sample=n.d,cutoff=(2*sqrt(n.d))),npad=2*n.d)
>
> serie.month <- ts(sub.datm,start(sub.dat$Year[1],sub.dat$Month[1]),frequency=12)
> n.m<-length(serie.month)
> n.m
[1] 322
> espec.month<-SDF(serie.month,method="lag window",window=taper(type="parzen",n.sample=n.m,cutoff=(2*sqrt(n.m))),npad=2*n.m)
Error in createTaper(window, "hanning", n.sample) :
Taper vector must contain 161 elements
It's curious that the length indicated by the error warning is half of
the length of the series. Also, why it mentions the Hanning window if
I've specified the Parzen in the code. I have tried with other series
and the same thing keeps happening. It's probably something very basic
but why is this happening? I'll appreciate sincerely any help/advice
to solve this problem.
Best regards,
Jorge
More information about the R-help
mailing list