1

In ccf, When I give the option of plot=TRUE, I will get a plot that gives me 95% confidence interval cut-offs for my cross-correlations at each lag. My question is, if I want to use a 90% confidence level, how can I do this? Thanks.

Yang Yang
  • 858
  • 3
  • 26
  • 49
  • 1
    If helps if you include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data and the code you are running. Make it clear which packages and functions you are using. – MrFlick Apr 27 '16 at 18:55

1 Answers1

0

I believe that by setting Plot=T, ccf function passes its results to acf and then to plot.acf function. plot.acf is where confidence interval is calculated. You can see it with the ":::" device

stats:::plot.acf

You should see something simmilar:

function (x, ci = 0.95, type = "h", xlab = "Lag", ylab = NULL .....etc.

I suggest you set plot=F in ccf function, then use plot function seperately, changing confidence interval (ci). You can do so by using this code:

plot(x, ci = 0.90, type = "h", xlab = "Lag", ylab = NULL,
 ylim = NULL, main = NULL,
 ci.col = "blue", ci.type = c("white", "ma"),
 max.mfrow = 6, ask = Npgs > 1 && dev.interactive(),
 mar = if(nser > 2) c(3,2,2,0.8) else par("mar"),
 oma = if(nser > 2) c(1,1.2,1,1) else par("oma"),
 mgp = if(nser > 2) c(1.5,0.6,0) else par("mgp"),
 xpd = par("xpd"),
 cex.main = if(nser > 2) 1 else par("cex.main"),
 verbose = getOption("verbose"),
 ...)

LINK: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/plot.acf.html

Since you havent provided any actual example data, i will show you an example with two common time series: recruit.dat and soi.dat. Just run this script line by line and try to understand what each line does.

#import data from web:
soi = ts(scan("http://anson.ucdavis.edu/~shumway/soi.dat"), start=1950,   frequency=12)
rec = ts(scan("http://anson.ucdavis.edu/~shumway/recruit.dat"), start=1950, frequency=12)

#run simple ccf function with plot=F
ccfvalues =ccf (soi, rec, plot=F)

#now run a plot function, with the desired confidence interval. Simple as that!
plot (ccfvalues, ci=0.90, type = "h", xlab = "Lag", ylab = NULL,ylim = NULL, main = NULL,ci.col = "blue", ci.type = c("white", "ma"),max.mfrow = 6, ask = Npgs > 1 && dev.interactive(),mar = if(nser > 2) c(3,2,2,0.8) else par("mar"),oma = if(nser > 2) c(1,1.2,1,1) else par("oma"),mgp = if(nser > 2) c(1.5,0.6,0) else par("mgp"),xpd = par("xpd"),cex.main = if(nser > 2) 1 else par("cex.main"),verbose = getOption("verbose"))

Replace the soi and recruit data with your own and you are all set! Hope it works!

Dfinzgar
  • 88
  • 5
  • Thank you for your reply. But I get this error when using the plot() function you give me as an example. ccf=ccf(mei[,2],n.mt1021960[,names(n.mt1021960)=='Annual']) Then I replace the x in your plot() function with ccf, and I get this: Error: '...' used in an incorrect context. Could you help me with this? Thanks. – Yang Yang Apr 27 '16 at 20:46
  • x should be replaced with your results! – Dfinzgar Apr 28 '16 at 00:01
  • Thanks. My code is, ccf=ccf(mei[1:62,2],n.mt1024638[2:63,names(n.mt1024638)=='Winter']) plot(ccf, ci = 0.90, type = "h", xlab = "Lag", ylab = NULL,ylim = NULL, main = NULL,ci.col = "blue", ci.type = c("white", "ma"),max.mfrow = 6, ask = Npgs > 1 && dev.interactive(),mar = if(nser > 2) c(3,2,2,0.8) else par("mar"),oma = if(nser > 2) c(1,1.2,1,1) else par("oma"),mgp = if(nser > 2) c(1.5,0.6,0) else par("mgp"),xpd = par("xpd"),cex.main = if(nser > 2) 1 else par("cex.main"),verbose = getOption("verbose"),...) Error: '...' used in an incorrect context – Yang Yang Apr 28 '16 at 15:40
  • Hey Yang! Since you haven't provided any actual data, and i dont know what mei and Winter are, i can give you a simple example: it is now included on the bottom of my answer. You can run the code provided and see for yourself. – Dfinzgar Apr 28 '16 at 18:24
  • Thanks a lot. I notice that you delete "..." in your original code just behind verbose = getOption("verbose"). Thank you so much. – Yang Yang Apr 28 '16 at 18:56