Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

python - How to inverse second differencing using pmdarima or otherwise?

I'm running a VARMA model in statsmodels and some of my inputs need to be differenced twice in order to be stationary. The VARMA model doesn't have a differencing parameter, so I need to difference before running the model and inverse the differencing after myself.

I've tried using pmdarima diff_inv, but I have spent a while with it and haven't been able to get it to return the original array for inversing second differencing. I think the issue is with the xi parameter, so if someone could show me how to use pmdarima to inverse second differencing that would work as well.

For now, I'm trying to figure out how to inverse second differencing without the help of pmdarima.

Using this code, I was able to successfully difference an array twice, then inverse the differencing to get the original array.

y = pd.Series([5, 3, 6, 2, 10]) #original data
diff1 = y.diff() #get first difference

[NaN, -2, 3, -4, 8] #(returns this but in pd series form)

diff2 = y.diff().diff() #get second difference

[NaN, NaN, 5, -7, 12]

#now inverse the differencing
inv1 = diff2.cumsum()-2 #undo one level of differencing. subtract xi,2=-2 since that's the first value of the original data differenced once
inv1[1]=-2 #add -2 as the second value in the series

[NaN, -2, 3, -4, 8] #we get the same series as after 1 level of differencing applied to the original

 inv2 = inv1.cumsum()+5 #undo another level of differencing.  add xi,1=5 since that's the first value of the original series
 inv2[0]=5 #add 5 as the first value of the series

[5, 3, 6, 2, 10] #we get the original data

Now, I just need to figure out how to determine the xi,1 and xi,2 values (5 and -2 in this example) for my application. Since I will be second differencing the input data, applying the model, then inversing the differencing, I think I can get xi,1 from the first value of the input data, but how do I determine xi,2?

question from:https://stackoverflow.com/questions/65933344/how-to-inverse-second-differencing-using-pmdarima-or-otherwise

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...