Exercise 4.2 [OLD] | |
 [TA] Di Su   Created at: 0000-00-00 00:00   2022A4Ex2 | 1 |
Exercise 2 (${\color{red}\star}{\color{red}\star}{\color{red}\star}$ Horse racing (40%)). Hong Kong Jockey
Club (HKJC) organizes approximately 700 horse races every year. This
exercise analyses the effect of draw on winning probability. According
to HKJC:The draw refers to a horse's position in the starting gate. Generally speaking, the smaller the draw number, the closer the runner is to the insider rail, hence a shorter distance to be covered at the turns and has a slight advantage over horses with bigger draw numbers.The dataset horseRacing.txt ,
which is a modified version of the dataset in the GitHub project HK-Horse-Racing,
can be downloaded from the course website. It contains all races from 15
Sep 2008 to 14 July 2010. There are six columns:
In this example, we consider all races that (i) took placed in the
turf runway of the Shatin racecourse, (ii) were of distance 1000m,
1200m, 1400m, 1600m, 1800m and 2000m; and (iii) used draws 1-14. Let
Remark 2 (Hints for Exercise 2.).
| |
4.2 | |
Easy Difficult Number of votes: 27 | |
Does the prior follow a Beta distribution? | |
Anonymous Ifrit   Created at: 2022-03-24 14:53 | 10 |
The prior 𝜋(𝜃) ∝ 𝜃2(1−𝜃2)𝟙(0<𝜃<1), but not 𝜃2(1−𝜃)2𝟙(0<𝜃<1), the kernel of Beta(3,3). Is it true that the prior does not follow a Beta (or even a named) distribution? | |
Show 3 reply | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-03-24 15:08 | 2 |
Good catch! You are right. It is no longer a Beta random variable. The purpose of assignment 4 is to train your ability to handle non-conjugate problems. | |
Anonymous Orangutan   Last Modified: 2022-03-24 16:35 | 5 |
In this case, I am not sure, but we may use the transformation. ie) $\phi$ = $\theta^2$ so that $\phi$ ~ beta(2,2) | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-03-24 23:24 | 13 |
It is a very interesting observation! I would like to give hints to motivate follow-up discussion.
| |
Dirichlet-Multinomial Model | |
Anonymous Moose   Last Modified: 2022-03-28 14:02 | 3 |
It is clever to define x's in terms of the average position of the first and last 7 draw because the analysis could be simplified. One natural question is that how to use all draw for the analysis instead of the average. In this case, we may consider the Dirichlet-Multinomial model which is an extension of the Beta-Binomial model. Suppose the draws of each horse are always known and denote it as D. Given a particular distance, let $x^{(d)}_{i}$ be the position of the horse started at d draw in the ith race. Then $$[x^{(d)}_{i}\mid D=d,\theta^{(d)}_1,\dots,\theta^{(d)}_{14}]\sim multi(\theta^{(d)}_1,\dots,\theta^{(d)}_{14})$$ for $d=1,\dots,14;i=1,\dots,n$ $$[\theta^{(d)}_1,\dots,\theta^{(d)}_{14}]\sim Dirichlet(\alpha^{(d)}_1,\dots,\alpha^{(d)}_{14})$$ By the conjugacy, $$[\theta^{(d)}_1,\dots,\theta^{(d)}_{14}\mid x^{(d)}_{1:n}]\sim Dirichlet(\alpha^{(d)}_{n1},\dots,\alpha^{(d)}_{n14})$$ where $\alpha^{(d)}_{ni}=\sum_{k=1}^n x^{(d)}_{k}+\alpha^{(d)}_i$ for $i=1,\dots,14$ What do you think? | |
Show 4 reply | |
 [TA] Di Su   Created at: 2022-03-29 11:25 | 6 |
Using Dirichlet-Multinomial model is a good direction to go! However, there are some details you need to rigorously work on. For example, the definition of $D$ is not clear. Does it depend on the index of the horse? Moreover, the multinomial distribution is multivariate, should the data be $(x_i^{(1)},\cdots,x_i^{(14)})$ instead of $x_i^{(d)}$? | |
Anonymous Moose   Last Modified: 2022-03-29 16:01 | 4 |
You are right. It should be $x_{i1},\dots,x_{i14}$ in the multinomial distribution. It may be better to look at the data set first before the discussion. All the conditions stated in the assignment remain unchanged. For simplicity, let focus on the distance 1200 as the following. where each row represents the $i$th race, each column represents the draw and each entry represents the position. The above data set could be calculated by the code below. It is not necessary to define the variable D which is confusing. Then, it is clear that how does the Dirichlet-Multinomial model work by looking at the data set.For example, If we believe that an inner draw will lead to a better position, then we may set the following prior: $$[\theta_1,\dots,\theta_{14}]\sim Dir(1,\dots,14)$$ The posterior is $$[\theta_1,\dots,\theta_{14}\mid x_{1:n}]\sim Dir(723,783,790,809,707,752,702,864,809,899,806,842,953,898)$$ Under the $L^2$ loss, the Bayes estimator is the posterior mean $$0.064,0.069,0.070,0.071,0.062,0.066,0.062,0.076,0.071,0.079,0.071,0.074,0.084,0.079$$ It could be calculated by the following R code: We could see that the point estimates of the inner draws are slightly less than that of the outer draws. However, we still need to do the hypothesis testing to draw the final conclusion. | |
Anonymous Jackal   Created at: 2022-03-31 14:32 | 2 |
I am so raw to R and always get pissed by R. So for the selecting criteria, do you mean merging the ST and TF condition into one would run faster? I did this.
| |
 [TA] Di Su   Created at: 2022-03-31 20:07 | 4 |
Merging the check of “ST” and “TF” will not speed up the codes significantly. and are both fine.Your codes are correct if you want to further restrict the races to have a distance of 1200. | |
Question Regarding the R codes in the hints | |
Anonymous Grizzly   Created at: 2022-03-30 13:11 | 2 |
In the hints of Exercise 4.2 Q2, there is a code of cond1 = (D[1,"racecourse"]=="ST")&(D[1,"runway"]=="TF") Why we have to include 1 in D[1,"racecourse"] and D[1,"runway"]? Thank you. | |
Show 2 reply | |
Anonymous Moose   Created at: 2022-03-30 14:34 | 13 |
It is because the race course and the runway must be the same for the same race. So we only need to check one and thus will know the rest. Although it is not necessary to do so, it will be computationally efficient as we could only check one condition. | |
Anonymous Buffalo   Created at: 2022-04-01 02:51 | 4 |
This is because the calculated values for racecourse and runway are the same for all rows among the Dataframe D, and you can pick any row in D. | |
4.2.2 | |
Anonymous Liger   Created at: 2022-03-31 16:33 | 0 |
For question 2, do we need to calculate B10 to make the conclusion or it is ok to have p0 greater than 0.05 to conclude that we do not reject H0? | |
Show 1 reply | |
Anonymous Loris   Last Modified: 2022-03-31 17:13 | 8 |
Both are OK. But it should be noted that the criteria $\hat{p}_0<0.05$ is derived from the decision theoretic approach. That is: To test: $H0: \theta_{1000}\leq 0.5$ against $H1:\theta_{1000}>0.5$. Consider $\hat{\psi}\in \{0,1\}$ and the loss $L(\theta,\hat{\phi})=a_0{1}(\psi<\hat{\psi})+a_1{1}(\psi>\hat{\psi})$ where $\psi={1}(\theta_{1000}> 0.5)$, $a_0=95\%$ and $a_1=5\%$. By theorem 4.1, the Bayes estimator is $\hat{\psi}_{\pi}={1}(\hat{p}_0<\frac{a_1}{a_0+a_1}=0.05)$ where $\hat{p_0}=P(\theta\in \Theta_0|x)$ | |
Q4.4.2 | |
Anonymous Gopher   Created at: 2022-03-31 19:01 | 8 |
Hi, I found that the posterior density is the sum of two beta distribution kernel with different alpha. Is it correct? Can I use that and compute the posterior probability? | |
Show 4 reply | |
 [TA] Di Su   Last Modified: 2022-03-31 20:53 | 1 |
Yes, it is. It would be fun to try it! | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-03-31 20:20 | 9 |
It is very interesting!
| |
Anonymous Orangutan   Created at: 2022-03-31 22:01 | 3 |
My posterior is not mixture of beta distribution, so may incorrect. How we can separate the posterior into 2 parts ? (the sum of two beta?) | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-03-31 22:15 | 7 |
You need to carefully expand the posterior density. My hint is that you need to use the identity $$1-\theta^2=(1-\theta)(1+\theta)=(1-\theta) + \theta(1-\theta).$$ | |
Everyone seems so hardworking | |
Anonymous Jackal   Created at: 2022-04-01 01:27 | 8 |
Hope we all do well sigh. I find this useful too: https://bit.ly/3DtIz3h | |
Show 1 reply | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-04-01 09:55 | 0 |
Haha! It is definitely useful too! 😆 | |
Q2 typo? | |
Anonymous Jackal   Created at: 2022-04-01 12:10 | 1 |
For Q2 both hypotheses are called H0. 🤔 | |
Show 1 reply | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-04-01 16:34 | 2 |
Ahhh, good catch! Yes, the later one is $H_1$. Thanks for letting me know. | |
Condition (iii) of Data Selection | |
 ZHENG, Bo (Anonymous Crow)   Last Modified: 2022-04-01 16:50 | 8 |
We consider all races that (i) took placed in the turf runway of the Shatin racecourse; (ii) were of distance 1000m, 1200m, 1400m, 1600m, 1800m and 2000m; (iii) used draws 1–14 Does the condition (iii) mean that we only select the race used ALL OF draws 1-14? (e.g. $draws = \{1,2,3,…,14\}$) If so, why not easily denote $x_i$ as $$x_i=1(\frac{1}{7}\sum_{j\in[1,7]}{position_{ij}}<\frac{1}{7}\sum_{j\in[8,14]}{position_{ij}})$$ but $$x_i=1(\frac{1}{|draw_i\cap[1,7]|}\sum_{j\in{draw_i\cap[1,7]}}{position_{ij}}<\frac{1}{|draw_i\cap[8,14]|}\sum_{j\in{draw_i\cap[8,14]}}{position_{ij}})$$ Therefore, inspired by the given definition of $x_i$, does the condition (iii) mean that we should select the race that not only used SOME draws of 1-7 but also used SOME draws of 8-14? (e.g. $draws = \{2,9\}$) | |
Show 3 reply | |
Anonymous Chameleon   Created at: 2022-04-01 16:33 | 1 |
For example, in race 40 there is no horse with the 7th draw, but the final position consisted of 1 to 13. So I guess the 7th participant didn't attend the match due to some reason. Then you may not divide by 7. | |
Anonymous Hedgehog   Created at: 2022-04-01 16:34 | 1 |
I think no, as the question already said $i=1,2,…,n$ are the races satisfy all the conditions. Let me explain a bit what I guess from the definition. $ [1,7] $ is an interval, contains all real numbers $x$ such that $ 1 \le x \le 7 $ . $ draw_i $ refers to the set $ \{1,2,3,…,14 \} $ . So, $ draw_i ⋂ [1,7] $ refers to the set $ \{1,2,3,4,5,6,7 \} $ which has cardinality $ |\{1,2,3,4,5,6,7 \}| =7 $ . In set theory, sometimes mathematicians use $[[1,7]]$ to denote all integers in the interval $[1,7]$ , use $[[1,\infty)$ to denote all integers in the interval $[1,\infty)$ . | |
 [Instructor] Kin Wai (Keith) Chan   Created at: 2022-04-01 16:48 | 8 |
Good question! Yes, you are right. Please note the following two points:
\[ |\texttt{draw}_i \cap [1,7]| = |{1,2,3,6,7}| = 5. \] | |
Solution of Ex4.2 (3) | |
Anonymous Orangutan   Created at: 2022-04-13 15:05 | 0 |
I am wondering why we select “post.d(d)” in this case. I don't know this is the cause, but the credible interval of solution (especially 2000m) is different of mine. Thanks | |
Show 1 reply | |
 [TA] Di Su   Created at: 2022-04-17 15:18 | 0 |
Thanks for pointing out the typo. Please check Blackboard for the updated solution. | |