Ning
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Z test, T test, chi test tags: 量化資料分析, 統計, Stata date: Tue, Nov 1, 2022 robots: noindex, nofollow --- > [color=#000000]目錄 >:::spoiler >[TOC] >::: # 描述性統計:如何以統計數字呈現基本資料? | 數值變項 | |:------------------------------------| | mean, median, standard deviation | | 類別變項 (Nominal, ordinal variables) | |:-------------------------------------| | frequency table (次數分配表) , frequency, mode (眾數) | | (Relative frequencies) percentage (百分比)及 proportion(比例) | | Proportion: p = frequency/total N | | Percentage: % = (f/N)*100 = p*100 | # 假設檢定 ## 假設 研究假設+虛無假設=**所有的結果** 這兩個假設中,只有一個是正確的。 * 虛無假設H~0~:通常假設為沒關聯、沒差異 * 研究假設H~1~:通常假設為有關聯、有差異 不同樣本之間的平均數不一樣,兩樣本平均數之間的差異,會形成近似於常態分配的分佈圖。 ![](https://i.imgur.com/GKnrjp2.png) ## 顯著性(significance test) 判定哪一個哪一個最可能為真。 P-value : 在虛無假設下,得到某數值或更極端值的機率。當p值很小,該統計值來自該分配的機率很小。 α : 決定是否拒絕虛無假設的關卡,同時也決定了顯著度(significance level) P-value>=α : 不拒絕虛無假設 P-value<α : 拒絕虛無假設 ## 如何下結論? * 有足夠證據去支持研究假設 * 拒絕虛無假設並支持研究假設 * 沒有足夠證據去支持研究假設 * 不拒絕虛無假設(個人慣用:無法拒絕虛無假設) :::danger :warning: 不能說「接受虛無假設」 ::: ## 檢定的錯誤 型I錯誤(type I error) : 錯誤拒絕虛無假設 large smaples 型II錯誤(type II error) : 錯誤沒有拒絕虛無假設 small smaples ![](https://i.imgur.com/1zZIqx3.png) The smaller we make P(Type I error), the larger P(Type II error) becomes, that is, failing to reject H0 even though it is false. If we tolerate only an extremely small P(Type I error), such as α = 0.000001, the test may be unlikely to reject H0 even if it is false—for instance, unlikely to convict someone even if they are guilty. This reasoning reflects the fundamental relation:The smaller P(Type I error) is, the larger P(Type II error) is. # Z test 比較樣本與母體之間的差異是不是抽樣誤差所造成 ## 前提(assumptions) :::spoiler * 自變項:二類別變項 * 依變項:連續變項(本斥但有時候也用次序) * 用於母體 * 常態分配 * 樣本數>=10 * <font color="red">知道母體標準差</font> ::: ## one sample Z test(one-tailed) ### 假設檢定 #### 假設 >Example: >![](https://i.imgur.com/QhL2UDH.png) #### 顯著水準 ##### 單尾 >常用顯著水準 >:::spoiler >![](https://i.imgur.com/PZIqZd5.png) >![](https://i.imgur.com/hudobM5.png) >::: ##### 雙尾 >常用顯著水準 >:::spoiler >![](https://i.imgur.com/Q3gpZVl.png) >::: >Z分配查表: >:::spoiler >![](https://i.imgur.com/8iKguME.jpg) >::: #### 結果 >Example: >Z分數2.5(p<.05)是比臨界值1.65 更極端的數值, 落在拒絕區內。研究者結論:Z分數2.5不可能歸因於抽樣誤差。經常小考提升了考試成績。拒絕虛無假設。 # Z test vs T test >計算母體標準差(σ)、母體變異數(σ^2^)、離均差平方和(SS) >:::spoiler >![](https://i.imgur.com/GWItuc3.png) >::: >計算樣本標準差(SD)、樣本變異數(SD^2^)、離均差平方和(SS) >:::spoiler >![](https://i.imgur.com/HysBfqJ.png) >::: >Z test vs one sample T test >:::spoiler >![](https://i.imgur.com/JkWmNz0.png) >::: # T test ## 前提(assumptions) :::spoiler * 自變項:二類別變項 * 依變項:連續變項(本斥但有時候也用次序) * 隨機抽樣 * 資料分配接近常態分配 * 相對大的樣本 * 若有不同樣本,樣本的變異量接近、相等 * <font color="red">我們不知道母體變異數</font> ::: ## 單一樣本T test for single sample 目的: * 只有一個群體,想使用該群體資料來檢測一個假設平均數 * 檢驗樣本平均數和母體平均數是否有顯著差異,<font color="red">但是不知道母體平均數</font>,使用樣本標準差(SD)計算抽樣誤差量的估計值 ### 假設 >Example: >:::spoiler >![](https://i.imgur.com/DoheKzn.png) >::: ### 顯著性 t 分配表是依自由度(degrees of freedom,簡稱df)而非樣本人數(n)安排的。因此,為了決定拒絕區的位置,我們需要計算所用的統計檢定之df。 單樣本 t 檢定的df公式是**df = n-1**。 >t分配查表: >:::spoiler >![](https://i.imgur.com/YmBQYwG.gif) >::: ### 結果 參與新體育教學體能方案學生的平均體能分數(M=102.87,SD=5.00)顯著高於母體平均數(μ=100),t (14)=2.22, p < .05。 ### 語法 ```stata= ttest var==mean_population ``` ## 獨立樣本 T test for independent samples 有兩項平均數、兩群體資料,彼此沒有關連性,例如兩個隨機分配的群體。 觀測到的平均數差異與預期由抽樣誤差獲所造成的差異之比值。 >t公式的意義: >:::spoiler >![](https://i.imgur.com/AxWXKK8.png) >![](https://i.imgur.com/dyAZ9uX.png) >::: ### 假設 >Example: >:::spoiler >![](https://i.imgur.com/cP4G8WF.png) >::: ### 顯著性 獨立樣本 T 檢定有兩組樣本,df 公式是**df = (n~1~-1)+(n~2~-1)**。 | 名稱 | 公式 | 意義 | | -------- | -------- | -------- | | 離差分數 | M~1~-M~2~ | | | 離差平方和 | 理論:SS~1~=Σ(M~1~-M~2~)^2^ 計算:SS~1~=Σ(M~1~-M~2~)^2^-Σ(M~1~-M~2~)^2^/n | | 樣本變異數 | 各組:SD~1~=√SS~1~/(n-1) 合併:SD~p~=((n~1~-1)SD~1~^2^+(n~2~-1)SD~2~^2^)/((n~1~-1)+(n~2~-1))| | 平均數差異標準誤(抽樣誤差) | SEM~i~=√(SD~p~/n~1~+SD~p~/n~2~) | | T檢定 | t=(M~1~-M~2~)/SEM~i~ | 這兩個平均數的差異(即,M~1~-M~2~), 與預期因抽樣誤差而造成的差異(即,SEM~i~)相比較, 前者是後者的 t 倍大。 | ### 結果 >Example: > >這兩個平均數的差異(即,200.83-186.17=14.67)與預期因抽樣誤差而造成的差異(即,6.64)相比較,前者是後者的 2.21倍大。 > >t 的拒絕區是 t > 2.228 及 t < -2.228,所以得到的 t 值沒有落在拒絕區內。得到的 t 值不夠大,不足以拒絕虛無假設。 ### Effect size: Cohen’s d and Hedge’s g ![](https://i.imgur.com/BXfo8lI.jpg) #### Cohen’s d 計算公式: ![](https://i.imgur.com/ZtZlZT2.png) 判讀解釋參考表: ![](https://i.imgur.com/hlHwdCl.png) ### 語法 獨立樣本 T 檢定 ```stata= ttest var, by(var_2group) welch unequal ``` Effect size: Cohen’s d and Hedge’s g ```stata= esize twosmaple var, by(var_2group) ``` ## 成對樣本T test for dependent samples 有兩項平均數,可能是相同的人,但是不同的兩組,或者,有關係的兩群體,例如,先生與太太、母親與小孩 不獨立、成對、相關或重複的樣本,相同群體或有關聯的群體 ### 語法 ```stata= ttest var1=var2 ``` # 卡方檢定(Chi square test) ## 前提(assumptions) :::spoiler * 類別變項與類別變項(Categorical vs. categorical) * 不計算平均數 * 頻次計算(frequency counts)資料 ![](https://i.imgur.com/5Q6gkaL.png) ::: ## 單變項卡方檢定 ### 語法 ```stata= tab var1, chi csgof var1, expperc(51 49) ``` expperc(百分比 百分比) ## 雙變項卡方檢定 ### 語法 ```stata= tab var1 var2, chi expected tab var1 var2, chi expected ``` --- # 散布圖 ```stata= scatter y x ``` --- # 課後練習&作業 ## 課後練習 [Week 02 課後練習 @ 2022. 秋 量化資料分析](https://hackmd.io/@tree10zi23/Quan-w02-work) [Week 04 課後練習 @ 2022. 秋 量化資料分析](/izEQrwekSZOjfrFN4JQLKg) [Week 05 課後練習 @ 2022. 秋 量化資料分析](/zvMeNo_1RuWOAjL_OmAgHw) [W07 In-Class @ 2022. 秋 量化資料分析](/GJQpmx4oSbKcfuhkyy8PKA) [Week08 課後練習 @ 2022. 秋 量化資料分析](/xzVUedxYQSqE1hDf8hGasw) ## 作業 [2022. fall-Quan. Homework 01 @ Week 06](/d8v5o0R7RWuv58eABPQ_Vg) >參考答案 >[2022. 秋 量化資料分析 作業1-答案](/sOFB5qKWRdGDsxrp_15BYw) [2022. fall-Quan. Homework 02 @ Week 08](/MMDl4oL9RY6bBAkd-j1pyw) >參考答案 > --- :::info :star2:參考資源 :::spoiler * [參考書(老師提供)](https://www.dropbox.com/scl/fo/kpqy7qzm3xxoc3l5mlylz/h?dl=0&rlkey=qh6yztfgkbew890eootebfc9g) * [多變量分析課程講義](https://1drv.ms/u/s!An-sUGi5a5V22nqTM_PwpTbiS8ZX?e=K1MV8a) * [自學資源](https://1drv.ms/u/s!ApuI0KJcIZgW9ye3iypnqHBlca7h?e=T6G2n8) ::: :::info :star2:軟體安裝 :::spoiler * [stata14&15下載安裝](https://1drv.ms/u/s!ApuI0KJcIZgWpEaUVy6PXeg3VSlq?e=u66r08) :::

    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