On 12-02-14 3:13 PM, Diviya Smith wrote:
Hi there,
I am trying to compute the autocorrelation in a dataset using R's acf
function. ACF automatically plots the results. This works well except in
some cases xlim doesnt work
data<- rnorm(2000,0,1)
acf(data,xlim=c(1,10)) # works - the plot starts at 1
acf(data,lag=100,xlim=c(1,100)) # this does not work and the plot still
starts at 0
Is there another way to specify the xlim or the starting value for x? Any
help would be most appreciated.
I think you misunderstand what "xlim" controls. It sets the limit of
the plot region that's guaranteed to be included, but the region is
normally expanded. It doesn't control what is plotted unless it falls
outside the expanded region.
There are probably two ways to do what you want. You can force the
region not to expand, using xaxs="i" in the call. This won't adjust the
y axis to a smaller range; you'll need to do that yourself.
The other way is to manipulate the acf object to drop the lag 0 values;
it is a pretty smart object, so you can do that using
x <- acf(data, lag=100, plot=FALSE)[1:100] #only lags 1:100
plot(x)
Duncan Murdoch
______________________________________________
R-help@r-project.org 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.