Time series Analysis:How to plot these AR(1) graphs in python?









up vote
1
down vote

favorite












The equation for AR(1) is :



enter image description here



Cases:



enter image description here



This is what it looks like:
enter image description here



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:
enter image description here



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.










share|improve this question



























    up vote
    1
    down vote

    favorite












    The equation for AR(1) is :



    enter image description here



    Cases:



    enter image description here



    This is what it looks like:
    enter image description here



    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:
    enter image description here



    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.










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      The equation for AR(1) is :



      enter image description here



      Cases:



      enter image description here



      This is what it looks like:
      enter image description here



      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:
      enter image description here



      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.










      share|improve this question















      The equation for AR(1) is :



      enter image description here



      Cases:



      enter image description here



      This is what it looks like:
      enter image description here



      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:
      enter image description here



      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      Pygirl

      348211




      348211



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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














































































          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          Evgeni Malkin