From murdoch at stats.uwo.ca  Fri Mar 24 18:59:05 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri, 24 Mar 2006 12:59:05 -0500
Subject: [Rd] bug in plot.acf (PR#8705)
In-Reply-To: <971536df0603240625j4f8ff3d9uc05082063747d4af@mail.gmail.com>
References: <20060324125503.E098B183A3@slim.kubism.ku.dk>
	<971536df0603240625j4f8ff3d9uc05082063747d4af@mail.gmail.com>
Message-ID: <44243369.8090302@stats.uwo.ca>

On 3/24/2006 9:25 AM, Gabor Grothendieck wrote:
> On 3/24/06, murdoch at stats.uwo.ca <murdoch at stats.uwo.ca> wrote:
>> (Moved from r-devel to r-bugs)
>>
>> On 3/24/2006 5:03 AM, Antonio, Fabio Di Narzo wrote:
>> > Hi all.
>> > There's a bug in plot.acf, when plotting acf for multivariate time series.
>> > Here a reproducible example:
>> >
>> > X <- rnorm(1000)
>> > Y <- -X + rnorm(1000, sd=0.6)
>> > Z <- cbind(X,Y)
>> >
>> > In
>> > acf(Z)
>> > cross-correlation plot y-axis is limited to 0-1. But:
>> > acf(Z, ylim=c(-1,1))
>> > shows that there was a negative correlation, that was cut away in the
>> > previous plot.
>> >
>> > I've seen the error is trivial. There's something like:
>> >
>> > for(each pair of univariate time series) {
>> > if(is.null(ylim)) {
>> > ...#set ylim properly
>> > }
>> > ...
>> > }
>> >
>> > in plot.acf code, so that in the first iteration the ylim par is properly
>> > set to about c(0,1), but in
>> > subsequent interations, ylim is no more NULL, and the old, unproper ylim
>> > specification
>> > remains.
>>
>> Thanks for noticing this.  It's easy to fix, but before I do, I'd like
>> an opinion on the proper fix.  Should all the plots use the same ylim,
>> or in the case where it is unspecified, should they each choose their
>> own?  I can see arguments for both possibilities.
>>
> 
> 
> Not sure if its worth considering this but plot.zoo allows ylim to be
> a pair or it can be a list of pairs to specify different ylims for each
> plot or it can be a labelled list to specify just those indicated with
> the unspecified ones being defaulted.  Also if can be a set of data
> points in which case its range it used.

I'd say this is probably not a great idea here, since there are n^2 
limits to specify when plotting n series:  it's not obvious what the 
input would be. (Ylim as an I x I x 2 array?  Or 2 x I x I?)  Users who 
want that level of control should write a custom version of plot.acf.

Duncan



[Rd] bug in plot.acf (PR#8705)
Duncan Murdoch