wave
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Linear tendency ###### tags: `Categorical data analysis` ## Amended odds ratio When any $n_{ij} \approx 0$, the original definition of odds ratio will be problematic. Thus, we will use the amended odds ratio, which is defined as <font size = 5.5> $\theta = \frac{(n_{11} + 0.5)(n_{22} + 0.5)}{(n_{21} + 0.5)(n_{12} + 0.5)}$ </font> ## Case contral study ![](https://i.imgur.com/Lj9fWoV.jpg) When we control the number of columns, only if we have $P(L)$, i.e. the prevalence of lung cancer can we determine the value of relative risk. ## Pearson $\chi^2$ test This test is to test whether X and Y are independent, so ![](https://i.imgur.com/Vk9XpC7.png) And we have stated the situation of X and Y are independent, which is <font size = 5.5> $\pi_{ij} = \pi_{i+}\pi_{+j}$ </font> so here we get to know that ![](https://i.imgur.com/8e71mNe.png) And the test statistic is thus to be defined as ![](https://i.imgur.com/5YsExKG.png) Where $\chi^2$ is a chi-square distribution with $df = (i-1)(j-1)$ So where dose the df comes from? 定義$ij-1$:有效樣本數,因為在類別資料分析中,會把所有的樣本區分成$ij$個類,所以真正能夠提供資訊的是類,而不是原始的樣本數,所以稱有效樣本數。 而在row跟column的部分各要估計$(i-1)$跟$(j-1)$個參數$(\mu_{ij})$,所以再扣掉$(i-1) + (j-1)$,則得到 $(ij - 1) - [(i-1) + (j-1)] = (i-1)(j-1)$ ## SAS inplementation ![](https://i.imgur.com/mmGMxX3.jpg) 1. 一般的卡方結果 2. Likelihood ratio test($G^2$) 3. 先amend過,就是前面的+0.5之後再做的卡方 Note: 1. When the sample size is large $\chi^2 \approx G^2$ 2. Let $c = ij - 1$, then when $\frac{n}{c} < 5$, the approximation for $G^2$ to chi-square distribution will be poor 3. If $\frac{n}{c} \approx 1$, then the approximation for $\chi^2$ will be very good. ## Pearson residual 上面的卡方檢定的結果只有拒絕和不拒絕,沒辦法對cell多做解釋,用pearson residual則可進一步解釋 <font size = 5.5> $r_{ij} = \frac{n_{ij} - \hat{\mu_{ij}}}{\sqrt{\hat{\mu_{ij}}}}$ </font> if $r_{ij} > 0$,則代表預測值低估,反之則高估 ## Partition chi-square 對於一個完整的contingency table,如果其中幾個變項的行為相同或不同,可以透過partition的方式來切割表格,這樣就可以看出哪幾個變項其實是可以整合的。這也可以用在如果有幾個cell的值太小,在卡方的時候會出問題,但在切割的時候需要遵守以下原則。而要切割前可以先看row percent來大概決定那些變項是可以整併的。 1. subtable的df和要等於原來table的df 2. 每一個在原本的cell出現的數字都必須且只能在subtable出現一次 3. 每一個marginal出現的數字都必須且只能在subtable出現一次 Note: 將切割出來的subtable的卡方值加起來便會是原本table的卡方值 ## Proportional reduction To measure how well $X$ can predict $Y$ in categorical data, we define propotional reduction in error as <font size = 5.5> $PRE = \frac{V(Y) - V(Y|X)}{V(Y)}$ </font> where $V(Y) = V({\pi_{+j}})$: the variation of marginal distribution of $Y$ $V(Y|X) = V({\pi_{1|i}, \pi_{2|i}, ...., \pi_{j|i}})$: the variation of conditional distribution give that $X = i$ 因此這個參數代表的涵義就是,當給定$X$之後,原本$Y$的變異有多少可以被$X$所解釋,值越大代表說$X$這個變數的解釋能力越好,整體概念跟R-square很像。 In categoriacal data, we can't not define variance, so we re-define the variation as **entropy**: <font size = 5.5> $V(Y) = \sum_{j} \pi_{+j}log\pi_{+j}$ </font> Then the proportional reduction can be expressed as **uncertainty coefficients**: <font size = 5.5> $U = -\frac{\sum_{i}\sum_{j} \pi_{ij} log\frac{\pi_{ij}}{\pi_{i+}\pi_{+j}}}{\sum_{j} \pi_{+j} log \pi_{+j}}$ </font> ### code ``` sas= proc freq data = <data>; weight count; table <explanetory> * <response> / measures; run; ``` ### SAS implementation ![](https://i.imgur.com/1a92jyT.jpg) 1是將column當作response variable,row當作explanetory variable 2則反之 3則是將兩個平均 ## Linear tendency of ordinal data 因為前面的likelihood ratio test跟test of independency皆只有考慮類別,但如果資料是帶有順序的,此時這兩個test就會失真。所以可以將資料assign score當成連續變數之後再做檢定。 而其test statistic為 ![](https://i.imgur.com/pZHKBej.jpg) $r$為相關係數,其假設檢定為$H_0: r = 0, H_a : r \neq0$ 如果assign score的方法是用Midrank,則其相關係數稱為Spearman's rho ![](https://i.imgur.com/1SEuEWg.jpg) ### code ``` sas= proc freq data = <data>; weight count; table <explanetory> * <response> / measures scores = [rank][rigit]; run; ``` / measures scores = rank 會將correlation用midrank來計算,此時Pearson correlation跟Spearman correlation的值會相同 ![](https://i.imgur.com/SaAPAAD.jpg) / measures scores = ridit 則是將midrank再除以n ![](https://i.imgur.com/IhHLt0f.jpg)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully