Re: [R] acf.plot() question

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Mon 17 Oct 2005 - 06:59:08 EST

          Have you received a reply to this? I haven't seen one. If not, you might have received a quicker reply if you had noted that the example came from ch. 14 of Venables and Ripley (2002) Modern applied Statistics with S, 4th ed. (Springer, pp. 390-391, to be precise).

          You ask about the "plot in the lower right-hand corner", which as I read it is labeled "fdeaths". I assume you are asking why the upper-right is labeled "mdeaths and fdeaths" and the lower-left "fdeaths and mdeaths", especially since the lags in the lower left are negative.   I agree that it might make more sense, since the lower left lags are negative, to have the label in the lower left the same as in the upper right. However, it doesn't disturb me greatly as it is.

          spencer graves

DeBarr, Dave wrote:
> When I run the "acf()" function using the "acf(ts.union(mdeaths,
> fdeaths))" example, the "acf()" function calls the "acf.plot()"
> function to generate this plot...
> http://members.cox.net/ddebarr/images/acf_example.png
>
> The plot in the lower right-hand corner is labeled "fdeaths & mdeaths",
> but the negative lags appear to belong to "mdeaths & fdeaths" [which
> correspond to the positive lags of "fdeaths & mdeaths"].
>
> Am I missing something, or should the plot in the lower right-hand
> corner be labeled "mdeaths & fdeaths" (instead of "fdeaths & mdeaths")?
>
> Note: The unit of measure for the lags is years.
>
>

>>autocorrelation <- function(x, y, lags) {

>
> + n <- length(x)
> + x.bar <- mean(x)
> + y.bar <- mean(y)
> + c <- array(0, length(lags))
> + i <- 1
> + for (t in lags) {
> + s <- seq(max(1, 1 - t), min(n - t, n))
> + c[i] <- sum((x[s + t] - x.bar) * (y[s] - y.bar)) / n
> + i <- i + 1
> + }
> + x.sd <- sqrt(sum((x - x.bar) ^ 2) / n)
> + y.sd <- sqrt(sum((y - y.bar) ^ 2) / n)
> + return(c / (x.sd * y.sd))
> + }
>
>>autocorrelation(mdeaths, fdeaths, -15:15)

>
> [1] 0.015054983 0.365626026 0.615427121 0.708206289 0.621895801
> [6] 0.340005447 -0.024534195 -0.381671430 -0.611793479 -0.677803477
> [11] -0.604031174 -0.349468396 0.019759425 0.405200639 0.744309322
> [16] 0.976241251 0.735668532 0.364241839 -0.010675725 -0.382920620
> [21] -0.622386979 -0.688538519 -0.610583980 -0.383338305 -0.018112073
> [26] 0.391983088 0.656592111 0.721397236 0.639104375 0.361352626
> [31] -0.003385423
>
>>autocorrelation(fdeaths, mdeaths, -15:15)

>
> [1] -0.003385423 0.361352626 0.639104375 0.721397236 0.656592111
> [6] 0.391983088 -0.018112073 -0.383338305 -0.610583980 -0.688538519
> [11] -0.622386979 -0.382920620 -0.010675725 0.364241839 0.735668532
> [16] 0.976241251 0.744309322 0.405200639 0.019759425 -0.349468396
> [21] -0.604031174 -0.677803477 -0.611793479 -0.381671430 -0.024534195
> [26] 0.340005447 0.621895801 0.708206289 0.615427121 0.365626026
> [31] 0.015054983
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves@pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Oct 17 07:16:49 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:58:35 EST