[R] cpgram: access data, confidence bands

David Scott d.scott at auckland.ac.nz
Mon Nov 22 23:14:05 CET 2010


  On 22/11/10 22:54, Henri Mone wrote:
> Dear R experts, beginners and everyone else,
>
> I'm calculating "cumulative periodogram" using the command "cpgram"
> [1] from the MASS library. Here is a short example with the "lh"
> (hormone level) dataset:
>
>    library(MASS)
>    plot(lh,type="l",ylab="value",xlab="time", main="Hormone Levels (lh)")
>    spectrum(lh, main="Hormone Levels (lh)") # periodigram
>    cpgram(lh, main="Hormone Levels (lh)") # cumul. periodigram
>
> I got following two questions:
>
> 1. The command "cpgram" plots the cumulative periodogram without any
> problem. But I could not figure out any way to access the data of the
> plot (save it in a variable).
> the following command fails (contains no data):
>     >myObject<-cpgram(lh, main="Hormone Levels (lh)")
>     >summary(myObject)
>         Length  Class   Mode
>              0   NULL   NULL
>
> Is there an easy way to access the data of the  cumulative
> periodogram, or do I need to rewrite the "cpgram" function?
>
You need to rewrite cpgram. Have a look at the last line of the 
function, it is
invisible()
meaning it doesn't return anything. It is easy to change it, replace the 
last line by for example

return(list(pgram = y, cum = cumsum(y)/sum(y)))

or whatever you actually want to return.


> 2. The "cpgram" function plots with the default options the 95%
> confidence bands in the plot. The confidence band  are defined such
> that in 95% of the cases the true value will lie inside the bands. For
> most cases which I tested the cumulative periodogram is outside the
> confidence band. Does "cpgram" plot the confidence band of the the
> cumulative periodogram or for the periodogram (I think it is the
> cumulative periodigram, is this correct?). How should the confidence
> band in "cpgram" be interpreted? Some more description on this would
> be great.
>
>
It is the cumulative periodogram (as the name suggests). What did you 
test? Only a white noise process should stay inside the confidence 
bands. There is some information about the use of the cumulative 
periodogram in Venables and Ripley's book for which cpgram was written 
(but admittedly not a lot).

David Scott


_________________________________________________________________
David Scott	Department of Statistics
		The University of Auckland, PB 92019
		Auckland 1142,    NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:	d.scott at auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics



More information about the R-help mailing list