简体   繁体   中英

Theil's U 1 / Theil's U 2 Forecast Coefficient formula in Python

I have a problem implementing the Theil U forecast coefficient formula in my Python code. One of the problems is that I found several different versions of the formula. The 3 formulas I want to try are the following:

Theil's U 1 and 2 from a paper that ironically discusses the confusion of the Theil's U forecast coefficient: https://journals.sagepub.com/na101/home/literatum/publisher/sage/journals/content/mrja/1973/mrja_10_4/002224377301000413/20181220/002224377301000413.fp.png_v03

A different version of the Theil's U forecast coefficient from what appears to be an Oracle help page: https://docs.oracle.com/cd/E40248_01/epm.1112/cb_statistical/frameset.htm?ch07s02s03s04.html

The three formulas should achieve a value of 1 if the forecast is just a naive lagged forecast. So, let's consider the following simple list: list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and assume that the forecast for every value is the previous value.

This is my code for the 3 formulas:

list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

num = (sum([(list[row] - list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5
denum = ((sum([list[row] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5) + \
    ((sum([list[row - 1] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) / 9) ** 0.5)

UI = num / denum
print(UI)

num = sum([(list[row - 1] - list[row]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
denum = (sum([list[row] ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]])) ** 0.5

UII = num / denum
print(UII)

num = sum([((list[row - 1] - list[row]) / list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5
denum = sum([((list[row] - list[row - 1]) / list[row - 1]) ** 2 for row in [1, 2, 3, 4, 5, 6, 7, 8, 9]]) ** 0.5

U_Oracle = num / denum
print(U_Oracle)

These are the 3 results:

0.08224166442822099

0.15309310892394865

1.0

I can't figure out why not all 3 values are equal to 1. Is something wrong with my code?

The paper from Briemel, called a clarification is actually quite confusing, as it says that Ai and Pi are actual and predicted values. That is not true, you should use those values as 'rate of change' (quoting from the paper itself If one means by Ai and Pj the observed changes and the predicted changes ... ), which would require you to write another code for it.

To make a long story short, the Oracle implementation is the right one you are looking for!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM