Time series Analysis:How to plot these AR(1) graphs in python?
up vote
1
down vote
favorite
The equation for AR(1) is :
Cases:
This is what it looks like:
So I came up with this code:
from random import gauss
from random import seed
from matplotlib import pyplot
seed(1)
N = 100
b1 = [1, 0.8]
b2 = [1, -0.8]
b3 = [0.1, 1]
b4 = [0, 1.1]
sigma1to2 = 0.1
sigma3to4 = 0.5
e1to2 = [gauss(0, sigma1to2) for i in range(N)]
e3to4 = [gauss(0, sigma3to4) for i in range(N)]
x1 = np.zeros(N)
x2 = np.zeros(N)
x3 = np.zeros(N)
x4 = np.zeros(N)
for i in range(1,N):
x1[i] = b1[0] + (b1[1]* x1[i-1]) + e1to2[i]
x2[i] = b2[0] + (b2[1]* x2[i-1]) + e1to2[i]
x3[i] = b3[0] + (b3[1]* x3[i-1]) + e3to4[i]
x4[i] = b4[0] + (b4[1]* x4[i-1]) + e3to4[i]
fig = plt.figure(figsize=(15,5))
plt.subplot(221)
plt.plot(x1,label='series1')
plt.title('series1')
plt.subplot(222)
plt.plot(x2,label='series2')
plt.title('series2')
plt.subplot(223)
plt.plot(x3,label='series3')
plt.title('series3')
plt.subplot(224)
plt.plot(x4,label='series4')
plt.title('series4')
plt.show()
This is what I get:
What I am doing wrong? The 1st and last graph is not matching with that one. Actually, I am finding out the ACF after plotting the graph and there are cases where ACF will be different depending upon those three parameters value. ACF for those 1st and last case will be different in my case. Hence I ain't able to generalize the cases properly.
python statistics time-series arima
add a comment |
up vote
1
down vote
favorite
The equation for AR(1) is :
Cases:
This is what it looks like:
So I came up with this code:
from random import gauss
from random import seed
from matplotlib import pyplot
seed(1)
N = 100
b1 = [1, 0.8]
b2 = [1, -0.8]
b3 = [0.1, 1]
b4 = [0, 1.1]
sigma1to2 = 0.1
sigma3to4 = 0.5
e1to2 = [gauss(0, sigma1to2) for i in range(N)]
e3to4 = [gauss(0, sigma3to4) for i in range(N)]
x1 = np.zeros(N)
x2 = np.zeros(N)
x3 = np.zeros(N)
x4 = np.zeros(N)
for i in range(1,N):
x1[i] = b1[0] + (b1[1]* x1[i-1]) + e1to2[i]
x2[i] = b2[0] + (b2[1]* x2[i-1]) + e1to2[i]
x3[i] = b3[0] + (b3[1]* x3[i-1]) + e3to4[i]
x4[i] = b4[0] + (b4[1]* x4[i-1]) + e3to4[i]
fig = plt.figure(figsize=(15,5))
plt.subplot(221)
plt.plot(x1,label='series1')
plt.title('series1')
plt.subplot(222)
plt.plot(x2,label='series2')
plt.title('series2')
plt.subplot(223)
plt.plot(x3,label='series3')
plt.title('series3')
plt.subplot(224)
plt.plot(x4,label='series4')
plt.title('series4')
plt.show()
This is what I get:
What I am doing wrong? The 1st and last graph is not matching with that one. Actually, I am finding out the ACF after plotting the graph and there are cases where ACF will be different depending upon those three parameters value. ACF for those 1st and last case will be different in my case. Hence I ain't able to generalize the cases properly.
python statistics time-series arima
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The equation for AR(1) is :
Cases:
This is what it looks like:
So I came up with this code:
from random import gauss
from random import seed
from matplotlib import pyplot
seed(1)
N = 100
b1 = [1, 0.8]
b2 = [1, -0.8]
b3 = [0.1, 1]
b4 = [0, 1.1]
sigma1to2 = 0.1
sigma3to4 = 0.5
e1to2 = [gauss(0, sigma1to2) for i in range(N)]
e3to4 = [gauss(0, sigma3to4) for i in range(N)]
x1 = np.zeros(N)
x2 = np.zeros(N)
x3 = np.zeros(N)
x4 = np.zeros(N)
for i in range(1,N):
x1[i] = b1[0] + (b1[1]* x1[i-1]) + e1to2[i]
x2[i] = b2[0] + (b2[1]* x2[i-1]) + e1to2[i]
x3[i] = b3[0] + (b3[1]* x3[i-1]) + e3to4[i]
x4[i] = b4[0] + (b4[1]* x4[i-1]) + e3to4[i]
fig = plt.figure(figsize=(15,5))
plt.subplot(221)
plt.plot(x1,label='series1')
plt.title('series1')
plt.subplot(222)
plt.plot(x2,label='series2')
plt.title('series2')
plt.subplot(223)
plt.plot(x3,label='series3')
plt.title('series3')
plt.subplot(224)
plt.plot(x4,label='series4')
plt.title('series4')
plt.show()
This is what I get:
What I am doing wrong? The 1st and last graph is not matching with that one. Actually, I am finding out the ACF after plotting the graph and there are cases where ACF will be different depending upon those three parameters value. ACF for those 1st and last case will be different in my case. Hence I ain't able to generalize the cases properly.
python statistics time-series arima
The equation for AR(1) is :
Cases:
This is what it looks like:
So I came up with this code:
from random import gauss
from random import seed
from matplotlib import pyplot
seed(1)
N = 100
b1 = [1, 0.8]
b2 = [1, -0.8]
b3 = [0.1, 1]
b4 = [0, 1.1]
sigma1to2 = 0.1
sigma3to4 = 0.5
e1to2 = [gauss(0, sigma1to2) for i in range(N)]
e3to4 = [gauss(0, sigma3to4) for i in range(N)]
x1 = np.zeros(N)
x2 = np.zeros(N)
x3 = np.zeros(N)
x4 = np.zeros(N)
for i in range(1,N):
x1[i] = b1[0] + (b1[1]* x1[i-1]) + e1to2[i]
x2[i] = b2[0] + (b2[1]* x2[i-1]) + e1to2[i]
x3[i] = b3[0] + (b3[1]* x3[i-1]) + e3to4[i]
x4[i] = b4[0] + (b4[1]* x4[i-1]) + e3to4[i]
fig = plt.figure(figsize=(15,5))
plt.subplot(221)
plt.plot(x1,label='series1')
plt.title('series1')
plt.subplot(222)
plt.plot(x2,label='series2')
plt.title('series2')
plt.subplot(223)
plt.plot(x3,label='series3')
plt.title('series3')
plt.subplot(224)
plt.plot(x4,label='series4')
plt.title('series4')
plt.show()
This is what I get:
What I am doing wrong? The 1st and last graph is not matching with that one. Actually, I am finding out the ACF after plotting the graph and there are cases where ACF will be different depending upon those three parameters value. ACF for those 1st and last case will be different in my case. Hence I ain't able to generalize the cases properly.
python statistics time-series arima
python statistics time-series arima
edited Nov 10 at 8:58
asked Nov 10 at 8:43
Pygirl
358211
358211
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I just had to change the xlimit and the starting function value to be other than zero.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I just had to change the xlimit and the starting function value to be other than zero.
add a comment |
up vote
0
down vote
accepted
I just had to change the xlimit and the starting function value to be other than zero.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I just had to change the xlimit and the starting function value to be other than zero.
I just had to change the xlimit and the starting function value to be other than zero.
answered Nov 14 at 13:06
Pygirl
358211
358211
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237362%2ftime-series-analysishow-to-plot-these-ar1-graphs-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown