# CA trend, monotone, Fisher exact ###### tags: `Categorical data analysis` ## Ix2 table 對於特殊的Ix2表格,即$y = \{0, 1\}$,可以檢測linear probability,即是$x$的值跟$y = 1$的機率有無線性關係。 定義: <font size = 5.5> $\pi_{i} = P[Y = 1 | X = x_{i}] = p_{i}$ </font> 想要檢驗有無線性關係,便可假設為 <font size = 5.5> $\pi_{i} = \alpha + \beta x_i$ </font> 由least square method算出的結果便可得到 ![](https://i.imgur.com/CYzuZlL.jpg) 其中 <font size = 5.5> $\bar{x} = \frac{\sum_{i} x_{i}}{n}$ </font> ### 假設檢定 要檢定是否有trend, that is, to test whether $\beta = 0$, we use <b>Cochran-Armitage trend test</b> <font size = 5.5> $H_0: \beta = 0$ $H_a: \beta \neq 0$ </font> ![](https://i.imgur.com/flSOvDz.jpg) ![](https://i.imgur.com/bb2ICQv.jpg) ![](https://i.imgur.com/5zVy2jb.jpg) ### SAS code ```sas= proc freq data = <data>; weight <var>; table <explanetory> * <response> / trend; run; ``` ### SAS implementation ![](https://i.imgur.com/QREX33g.jpg) 第一個值是test statistic的z值,第二個值是單尾檢定,第三個值雙尾檢定 ## Monotone relation 對於類別ordinal資料,有時候linear relation其實很難找,這時就退而求其次找monotone就好。要檢測monotone需要先定義一些名詞。 $i, j$為X跟Y的rank <b>Concordant pair:</b> For $x_{ij}$, if $(i^{'} > i) \land (j^{'} > j)$, then $x_{i'j'}$ is called the concordant pair of $x_{ij}$ <b>Discordant pair:</b> if $(i^{'} > i) \land (j^{'} < j)$, then $x_{i'j'}$ is called the discordant pair of $x_{ij}$ 此時numbers of concordant pair(NC): $\sum_{i}\sum_{j} x_{ij} * (\sum_{k} x_{k})$ where $x_k$ is the concordant pair of $x_{ij}$ number of discordant pair(ND): $\sum_{i}\sum_{j} x_{ij} * (\sum_{k} x_{k})$ where $x_k$ is the discordant pair of $x_{ij}$ ### Test statistic Here, we will use <b>Gamma measurement</b> to measure if the data has monotone relation Define ![](https://i.imgur.com/XwauF71.jpg =65%x) Then the test statistic is ![](https://i.imgur.com/BWmNk6J.jpg) For the sample: <font size = 5.5> $\hat{\gamma} = \frac{NC - ND}{NC + ND}$ </font> Note: 1. Gamma is symmertric, that is col跟row互換不會影響值 2. $|\gamma| \leq 1$ ### SAS code ```sas= proc freq data = <data>; weight <var>; table <explanetory> * <response> / measures; run; ``` ### SAS implementation ![](https://i.imgur.com/5spSr6t.jpg) ## Fisher exact test 在cell的數量小時,卡方會不準確,在表格為Ix2的情況下,可以用fisher exact test 其假設檢定為 $H_0: X, Y$ independent $H_a: X, Y$ dependent 而其p-value有很多種算法 ![](https://i.imgur.com/UHyR9OD.jpg) ![](https://i.imgur.com/RyYh5tH.jpg) SAS在計算two-sided pvalue是用第一種算法 ### SAS code ```sas= proc freq data = <data>; weight <var>; table <explanetory> * <response> / exact; run; ``` ### SAS implementation ![](https://i.imgur.com/UmjVLq4.jpg)