Create Correlogram plot with given data

Hello everyone,
I'm trying to plot an ACF and PACF according to my given data, but I dont seem to find a way to do so. If anyone knows a way to do so and wants to share I would highly appreciate it!
Bellow is my set of data:

 Accepted Answer

If you don't have any input file (such as a txt or a csv) from where you can import data directly into matlab, I guess you need to do it manually. I will do it for you for ACF and PACF vectors, you need just to copy the code into your matlab, then i reccomend you to have a look at the basics of the language here: https://it.mathworks.com/help/matlab/getting-started-with-matlab.html?s_tid=CRUX_topnav
lags=[1:9]; %creating the x-axis vector
ACF=[0.833,0.796,0.723,0.659,0.59,0.536,0.493,0.454,0.413]; %creating a row column of ACF values
PACF=[0.833,0.343,0.013,-0.027,-0.048,0.002,0.036,0.026,-0.017]; %creating a row column of PACF values
figure
bar(lags,ACF,'b');
title('ACF');
xlabel('Lags');
figure
bar(lags,PACF,'r');
title("PACF");
xlabel('Lags');
You can use the same approach for the last two row vectors.

4 Comments

Hello Enrico,
Thank you very much for the answer! Although your answer works in terms of visual representation, as it presents the bar charts, I realized that in order to be able to prove the number of lags the corresponding model would have, we need to include the upper and lower bounds (significance levels) in our graph. I am afraid I have no idea how to do that.
But it would like this: (With the blue lines representing the upper and lower bounds)
Hi!
The significance bands have different formulation, the most common (which I think is also the one represented in both images) is the following:
upper_band=+1.96/sqrt(N);
lower_band=-1.96/sqrt(N); %Note: N is the number of time series points
Then you can plot the bands (i will slightly change the code present above):
lags=[1:9]; %creating the x-axis vector
ACF=[0.833,0.796,0.723,0.659,0.59,0.536,0.493,0.454,0.413]; %creating a row column of ACF values
PACF=[0.833,0.343,0.013,-0.027,-0.048,0.002,0.036,0.026,-0.017]; %creating a row column of PACF values
figure
hold on
bar(lags,ACF,'b');
title('ACF');
xlabel('Lags');
plot(lags,repelem(upper_band,length(lags)),'k--',lags,repelem(lower_band,length(lags)),'k--');
figure; hold on
bar(lags,PACF,'r');
title("PACF");
xlabel('Lags');
plot(lags,repelem(upper_band,length(lags)),'k--',lags,repelem(lower_band,length(lags)),'k--');
The graphics of the plot can be further improved. Hence I strongly reccomend to have a look to basic Matlab language. It is not going to be a waste of time!
It works! I really apreciate it Enrico. I will take a look at the basics of Matlab. Now, I only wonder if I could make an assumption about N. We don't really know the size of the sample. Any idea would be welcome.
If the size of the sample is actually unknown, make an assumption on N would be no-sense

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!