cshamruk
    • 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
    --- title: ICEF Elements of Statistic 2 --- # Seminar 17-18 Goodness of Fit (Pearson's) test Inputs : - observed category sizes : $O_1, \dots, O_k$ - expected (according to $H_0$) category sizes: $E_1, \dots , E_k$ **Note:** if $E_i$ is too small (e.g. $\leq 3$) we have to lump it into another category, reducing the number of categories. Test statistic : $$\text{Pearson test statistic} = \sum_{i=1}^{k} \frac{(O_i-E_i)^2}{E_i} \sim \chi^2(k - s - 1),$$ where - $k$ is the number of categories, - $s$ is the number of parameters in the expected distribution, *that we had to estimate from the data*. ## Problem 4 (grouping) Categories : $\{0, 1, 2, 3, 7 , 8\}$ $O_0 = 32, O_1 = 12, O_2 = 3, O_3 =1, O_7 = 1, O_8 =1$ Total number of observations $N = O_1 + \dots + O_8 = 32 + 12 + 3 + 1 + 0 + 0+ 0 + 1 + 1=50$ Theoretical categories are dictated by the sample space of the Poisson distribution. if $X\sim Poisson(\lambda)$, $X \in \{0, 1, 2, 3, \dots \}$ $P(X = x) = \frac{\lambda^x}{x!} \exp(-\lambda),$ (PMassF, discrete variable analogue of PDF) where $\lambda$ is the mean of random variable $X$. Set of categories registered after our research is not the same as the sample space (range of possible values) of hypothesized distribution: $$\{0,1,2,3,7,8\} \quad \text{vs} \quad \{0, 1,2,3,4,5,6,7,8,9, 10\dots\}$$ To make them the same we *change category labels*: - we add categories $\{4,5,6\}$ in the observed set with $O_4=O_5=O_6 = 0$, we get $$\{0,1,2,3,4,5,6,7,8\} \quad \text{vs} \quad \{0, 1,2,3,4,5,6,7,8,9, 10\dots\}$$ - to handle the tail of the theoretical distribution $\{8, 9, 10, \dots\}$, we replace the last category $8$ with category "$\geq 8$". $$\{0,1,2,3,4,5,6,7,\geq 8\} \quad \text{vs} \quad \{0, 1,2,3,4,5,6,7,\geq 8\}$$ Accordingly $O_8$ must be relabeled $O_{\geq 8}$. $$E_i = N \times P(X = i), \text{ for $i =0, 1,\dots 7$}\\E_{\geq 8} = N\times P(X \geq 8)$$ From the statement of the problem $\lambda = 0.7$, and $P(X = x) = \frac{\lambda^x}{x!} \exp(-\lambda)$. Then - $E_0 = 50 \cdot \frac{0.7^0}{0!}\cdot\exp(-0.7)=50 \cdot \exp(-0.7) =24.8$ - $E_1 = 50 \cdot \frac{0.7^1}{1!}\cdot\exp(-0.7)=50 \cdot 0.7\cdot \exp(-0.7) =17.4$ - $E_2 = 50 \cdot \frac{0.7^2}{2!}\cdot\exp(-0.7)=6.1$ - $E_3 = 50 \cdot \frac{0.7^3}{3!}\cdot\exp(-0.7)=50 \cdot 0.7\cdot \exp(-0.7) =1.4$ - $E_4 = 50 \cdot \frac{0.7^4}{4!}\cdot\exp(-0.7)=50 \cdot 0.7\cdot \exp(-0.7) =0.2$ - ... We observe that the theoretical sizes of categories $3,4,5,\dots,\geq 8$ are too small, smaller than $2$. For the test to be valid we should lump them together. ![](https://i.imgur.com/ml32hNb.png) We make another grouping: - replace categories $\{3,4,5,6,7,\geq 8\}$ with a single category $\geq 3$: $$E_{\geq 3} = N \cdot P(X \geq 3) = N \cdot (1 - P(X <3))\\ =N\cdot (1 - P(X=0) - P(X=1) - P(X=2))\\ =N - N\cdot P(X=0) - N\cdot P(X=1) - N\cdot P(X=2)\\ =N - E_0-E_1-E_2 \\ =50 - 24.8 - 17.4 - 6.1 = 1.7 $$ The last category $\geq 3$ still turns out to be far too small, so we group it together with $2$ to get category $\geq 2$. $$E_{\geq 2} = E_2 + E_{\geq 3} = 6.1 + 1.7 = 7.8$$ Finally we get 3 categories $\{0,1,\geq 2\}$ with frequencies (category sizes): - theoretical : $E_0 = 24.8, E_1 = 17.4, E_{\geq 2} = 7.8$ - observed : $O_0 =32,O_1=12, O_{\geq 2} =6$. The value of Pearson test statistic is $\frac{(32 - 24.8)^2}{24.8} + \frac{(12 - 17.4)^2}{17.4} + \frac{(6 - 7.8)^2}{7.8} =4.18$ We reject the null hypothesis of the data being distributed as Poisson(0.7) if 4.18 is larger than the 95% quantile of the $\chi^2(3-1)$. The quantile (critical value) is 5.99, above the observed value of the test statistic therefore we do not reject $H_0$. ![](https://i.imgur.com/SKSCKm5.png) ## Problem 5 GoF (conditioning and grouping) $$H_0 : \text{Basketball shots are independent Bernoulli trials with probability of success $p = .6$}$$ We start with determining the thoretical categories (sample space) and their sizes $E_i$. $O_3 = 80, O_4 = 50, \dots O_{15} = 1$. The number of observations is $N=200$. $X$ - length of a series of hits (successful shots). Under the $H_0$ it must be distributed as a geometric random variable. $$P(X = x) = p^x (1-p)$$ $P(X = 2) = P(hit \cap hit \cap miss) = 0.6 \cdot 0.6 \cdot (1 - 0.6)$ As the researcher dropped the observations with $X\leq 2$, we have to use the conditional distribution: > $$P(A \mid B) =\frac{P(A \cap B)}{P(B)}$$ $$E_i = N \times P(\underbrace{X = i}_{A} \mid \underbrace{X > 2}_{B}) = \begin{cases} 0, &\quad \text{if $x \leq 2$}\\ N \times \frac{P(X = x)}{P(X < 2)}, &\quad \text{if $x \geq 3$} \end{cases}$$ > $$E_1 = N \times P(\underbrace{X = 1}_{A} \mid \underbrace{X > 2}_{B}) = N \times \frac{P(X=1 \cap X > 2)}{P(X > 2)} = N \cdot \frac{0}{P(X > 2)} = 0$$ $$P(X > 2) = 1 - P(X =0) - P(X = 1) - P(X = 2) \\ = 1 - 0.4 - 0.6\cdot 0.4 - 0.6^2 \cdot 0.4 = 1 - (1 + 0.6 + 0.36)\cdot .4 = 0.216$$ \begin{align} E_3 &= N \times P(\underbrace{X = 3}_{A} \mid \underbrace{X > 2}_{B}) = N \times \frac{P(X = 3 \cap X > 2)}{P(X > 2)} \\ &= N \cdot \frac{P(X=3)}{P(X > 2)} \\ &= 200\cdot \frac{.6^3 \cdot .4}{0.216} = 80\\ E_4 &= N \times P(\underbrace{X = 4}_{A} \mid \underbrace{X > 2}_{B}) = N \times \frac{P(X = 4 \text{ AND } X > 2)}{P(X > 2)} \\ &= N \cdot \frac{P(X = 4)}{P(X > 2)} \\ &= 200 \cdot \frac{.6^4\cdot .4}{.216} = 48\\ E_5 &= 200\cdot \frac{.6^5 \cdot .4}{.216} = 28.8\\ E_6 &= 200\cdot \frac{.6^6 \cdot .4}{.216} = 17.28\\ E_7 &= 200\cdot \frac{.6^7 \cdot .4}{.216} = 10.4\\ E_8 &= 200\cdot \frac{.6^8 \cdot .4}{.216} = 6.22\\ E_{\geq 9} &= N \times P(X \geq 9 \mid X > 2) = N\frac{P(X \geq 9)}{P(X > 2)} \\ &= N - \sum_{i \in \{3,4,5,6,7,8\}} E_i = 9.3 \end{align} We need to group the existing categories to obtain classes $\{3,4,5,6,7,8,\geq 9\}$. The observed frequencies for grouped classes are $O_3 = 80, O_4 = 50, \dots , O_{\geq 9} = 8$ The test statistic is $$\sum_{i \in \{3,4,5,6,7,8,\geq 9\}}\frac{(O_i - E_i)^2}{E_i} =\\ = (48 - 50)^2 / 48 + (28.8 - 32)^2 / 28.8 + (16 - 17.28)^2 / 17.28 \\+ (8 - 10.4)^2 / 10.4 + (6.22 - 6)^2 / 6.22 + (8 - 9.3)^2 / 9.3 \\ = 1.27$$ The test statistic is distributed as $\chi^2(7 - 1)$, the 5% critical value is 12.59, much larger than the observed test statistic value, 1.27, therefore we do not reject $H_0$. ## Problem 6 $$E_{\leq 30} = N \cdot \Phi(\frac{30 - \mu}{\sigma})$$ ## Problem 7 $$E_i = N \cdot P(X = i) = (1 - \hat p)^{i-1} \hat p$$ # Seminar 18 ## Problem 6 The suggested null is that the shots are independent, which is equivalent to the following hypothesis on $X$: [Geometric distribution wiki](https://en.wikipedia.org/wiki/Geometric_distribution) $$H_0 : \text{shot are independent, with prob $p$} \iff H_0 : X \sim \text{Geometric}(1-p)$$ $H_0$ implies the following probability mass function for $X$: $$P(X = x) = p^x (1-p), \quad x= 0, 1,2,3,\dots$$ We only have records on series of postitive length $1,2,3, \dots$. Series of length $0$ are not recorded, therefore to compute the estimated frequency of series of length $x = 1, 2, 3 , \dots$ we must use conditional probability mass function: $$P(X= x \mid X > 0) = \frac{P(X = x)}{1 - P(X = 0)}$$ $$P(X = 0) = 1 - p = 0.503, \Rightarrow P(X = x\mid X> 0 ) = p^x$$ > The null could also have been formulated as >$$H_0 : P(X = x) = p^x (1-p), \quad x= 1,2,3,\dots$$ We start by computing the estimated class sizes: \begin{align} E_1 &= N \cdot P(X = 1\mid X > 0) = 400 \cdot .497 = 198.8\\ E_2 &= N \cdot P(X = 2\mid X > 0) = 400 \cdot .497^2 = 98.8\\ E_3 &= N \cdot P(X = 3\mid X > 0) = 400 \cdot .497^3 = 49.1\\ E_4 &= N \cdot P(X = 4\mid X > 0) = 400 \cdot .497^4 = 24.4\\ E_5 &= N \cdot P(X = 5\mid X > 0) = 400 \cdot .497^5 = 12.12\\ E_{\geq 6} &= 400 \cdot (1 - P(X <6))\\ &= 400 - E_1 - E_2 - E_3 - E_4 - E_5 = 10.7 \end{align} The Pearson test statistic takes value $$(173 - 198.8)^2/198.8 + (110 - 98.8)^2/49.7 \\+ (61 - 49.1)^2/49.1 + (28 -24.4)^2/24.4 \\+ (15 - 12.12)^2/12.12 + (13 - 10.7)^2/10.7 = 10.46$$ It is distributed according to $\chi^2(5)$ ($df = 6 - 1$, as the probability of a successful shot is given in the problem statement). The critical value corresponding to the 10% significance level is $9.24$. The obtained test-statistic is above the critical value therefore the null is rejected, i.e. the shots of Michael Jordan were not independent. ## Problem 7 $$H_0 : X \sim \text{Geometric(p)}$$ $p$ is unknown, let's find it via Likelihood method. We have 120 observations of $X$, denote them $x_1, \dots , x_{120}$. Each one is distributed geometrically: \begin{align} P(X_i = x) &=\underbrace{(1-p)^{x-1}}_\text{$x-1$ misses} \cdot \underbrace{p}_\text{hit} \quad x= 1, 2, 3\\ P(X \geq 4) &= 1 - P(X < 4)\\ &=1 - \left(p + (1-p)p + (1 - p)^2 p\right) \\ &= 1 - \frac{1 - (1-p)^3}{1 - (1-p)}p\\ &= (1-p)^3 \end{align} $$L( x_1, \dots, x_{120}) = \Pi_{i = 1}^{120} P(X_i = x_i)\\ = \Pi_{x_i = 1} P(X_i = 1) \cdot \Pi_{x_i = 2} P(X_i = 2)\cdot \Pi_{x_i = 3} P(X_i = 3) \cdot \Pi_{x_i \geq 4} P(X_i = x_i)\\ =\underbrace{\Pi_{x_i=1} p}_{p^{50}} \cdot \underbrace{\Pi_{x_i = 2} (1-p)p}_{(1-p)^{40} p^{40}}\cdot \underbrace{\Pi_{x_i = 3} (1-p)^2 p}_{(1-p)^{40} p^{20}} \cdot \underbrace{\left(P(X \geq 4)\right)^{10}}_{(1 - p)^{30}}$$ Maximize the logarithm of the likelihood with respect to $p$: $$\frac{\partial }{\partial p} \left( 110 \ln p + 110 \ln (1-p) \right)\mid_{p = \hat p_{ML}} = 0$$ $$\frac{110}{\hat p_{ML}} - \frac{110}{1-\hat p_{ML}} = 0\\ \Rightarrow \hat p_{ML} = 1-\hat p_{ML} = 1/2$$ 1. Formulate the null $$H_0 : \text{shots are independent}$$ 2. Write down the $E_i$ Using the estimate $\hat p$ of $p$ we can write down the expected frequencies: \begin{align} E_1 &= N \cdot \hat P(X = 1)= N \cdot \hat p = 120 \cdot 1/2 = 60\\ E_2 &= N \cdot \hat P(X = 2) = 120 \cdot 1/2\cdot 1/2 = 30\\ E_3 &= N \cdot \hat P(X = 3) = 120 \cdot 1/2^2\cdot 1/2 = 15\\ E_{\geq 4} &= N - E_1 - E_2 - E_3 = 120 - 60 - 30 - 15 = 15. \end{align} 3. Compute the Pearson test statistic (chi-squared): $$(50 - 60)^2/60 + (40 - 30)^2/30 + (15 - 20)^2/20 + (10- 15)^2/15 \approx 7.92$$ The test-statistic is distributed as $\chi^2(2)$ ($df = 4 - 1 - 1$, because we used an estimate of the parameter based on the same data), the 5% significance level critical value is $5.99$, below the observed value of the test statistic, therefore the null is rejected at 5% significance level. At 1% signinficance level the null passes, although barely, the 1% significance level critical value being $9.21$. ## Problem 8 $X$ is the number of wins in a match + $X=0$ - the opponent won two games in a row $P(X=0) = P(loss \cap loss) = (1-p)^2$ + $X = 1$ - - we won the first game but lost the next two OR - we lost the first game, won the second, but lost the third $P(X = 1) = P(win \cap loss \cap loss) + P(loss \cap win \cap loss) =2 p(1-p)^2$ + $X=2$ $P(X = 2) = P(win \cap win) +P(loss \cap win \cap win) +P(win\cap loss \cap win) = p^2 + 2p^2 (1-p)$ Our null $$H_0 : \text{wins in diffferent games are independent and happen with probability $p=.6$}$$ is equivalent to $$H_0 : P(X = x) = \begin{cases} (1 - p)^2 \quad \text{if $x = 0$}\\ 2p (1 - p)^2 \quad \text{if $x = 1$}\\ p^2 (3 - 2p) \quad \text{if $x = 2$} \end{cases}$$ Under the null the estimated frequencies are: \begin{align} E_0 &= 200 \cdot P(X = 0) = 200 \cdot .4^2 = 32\\ E_1 &=200 \cdot P(X = 1) =200 \cdot 2\cdot.6\cdot .16 = 38.4\\ E_2 &=200 \cdot P(X = 2) = 200 \cdot .36 \cdot 1.8 = 129.6 \end{align} The test statistic takes value $$(27 - 32)^2/32 + (47 - 38.4)^2/38.4 + (127 - 129.6)^2/129.6 = 2.76$$ The test statistic is distributed according to $\chi^2(3 - 1)$, the 5% critical value is $5.99$ above the observed value, therefore we do not reject the null.

    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