I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success. 1. I would like to get rid of the lag zero 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ... Could anybody help me in this? Any help will be appreciated Thank you for your attention Stefano [[alternative HTML version deleted]]
Hi Stefano, the manual tells us that we can access components of an acf object directly by acf.obj[.], but assignment ]<- does not work this way. One way of doing what you want is to assign NA to x$acf[x$lag==0] like so: x <- acf(runif(100)) x$acf[1] <- NA plot(x) But I suppose what you actually want is to have a reasonable ylim to be in effect when plotting your acf. I have struggled with this myself and found the following solution: In plot.acf the formula for the white noise confidence interval is something along the lines of acf.clim <- function(x=stop("your acf"), n=x$n.used, CL=.95) { cl = qnorm((1+CL)/2)/sqrt(n) attr(cl,"CL") <- CL return( cl) } Using this function you can plot x <- acf(runif(100),plot=F) plot(x, ylim=2*acf.clim(x)*c(-1,1)) # adjust magnification as needed As for your second question we first prevent plotting of x-axis and then add our custom axis: x <- acf(runif(1000),100,plot=F) plot(x, ylim=2*acf.clim(x)*c(-1,1),xaxt='n') # note option 'xaxt'! axis(1,at=12*(0:8)) Hope that helps, Matthias NB: It would be a good idea to include the acf.clim(.) inside of the acf object... Now it is somewhat hidden inside of plot.acf x$clim <- acf.clim(x) str(x) Stefano Sofia wrote:> I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success. > > 1. I would like to get rid of the lag zero > 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ... > > Could anybody help me in this? > > Any help will be appreciated > Thank you for your attention > Stefano > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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 > and provide commented, minimal, self-contained, reproducible code. > >-- Journalist: "Mr. Gandhi, what do you think of Western civilization?" Gandhi: "I think it would be a good idea." ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Matthias Braeunig, Dipl.Phys. ~ University Medical Center Freiburg ~ Institute of Environmental Medicine and Hospital Epidemiology ~ Department of Evaluation Research in Complementary Medicine ~ Hugstetter Str. 55, D - 79106 Freiburg, Germany ~ Phone: +49 (0)761 270-8306, Fax: -8343 ~ Web: http://kompmed.uniklinik-freiburg.de ~ Email: matthias.braeunig at uniklinik-freiburg.de ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Try this. It uses Matthias' trick for getting rid of lag 1. The it defines a new local plot.acf and then defines a new local plot.acf which # test data set.seed(1) x <- rnorm(1000) # run acf x.acf <- acf(x) # remove lag 0 -- see Matthias' post x.acf$acf[1] <- NA # plot with custom x axis plot(x.acf, xaxt = "n") axis(1, seq(12, length(x.acf$acf), 12)) On 8/18/06, Stefano Sofia <stefano.sofia at regione.marche.it> wrote:> I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success. > > 1. I would like to get rid of the lag zero > 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ... > > Could anybody help me in this? > > Any help will be appreciated > Thank you for your attention > Stefano > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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 > and provide commented, minimal, self-contained, reproducible code. >
Try constructing the acf plot using the traditional plot tools. Then you can do what you like with it. Eg if your model is called model.lme, then something like this should work: acf.resid <- ACF(model.lme, resType = "n") my.lags <- acf.resid$lag > 0.5 plot(acf.resid$lag[my.lags], acf.resid$ACF[my.lags], type="b", main="Residual Autocorrelation", xlab="Lag", ylab="Correlation", axes=F) stdv <- qnorm(1 - 0.01/2)/sqrt(attr(acf.resid, "n.used")) lines(acf.resid$lag[my.lags], stdv[my.lags], col="darkgray") lines(acf.resid$lag[my.lags], -stdv[my.lags], col="darkgray") abline(0,0,col="gray") box() axis(1) axis(2) Modify the first axis to put ticks and numbers where you want them. Double-check the image against the plot of the ACF object to be sure that it lines up right. Cheers Andrew On Fri, Aug 18, 2006 at 04:50:01PM +0200, Stefano Sofia wrote:> I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success. > > 1. I would like to get rid of the lag zero > 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ... > > Could anybody help me in this? > > Any help will be appreciated > Thank you for your attention > Stefano > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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 > and provide commented, minimal, self-contained, reproducible code.-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: a.robinson at ms.unimelb.edu.au http://www.ms.unimelb.edu.au