Try   HackMD

統計實驗筆記

變數

p^ 樣本比例
μ
= 母體平均數 = 中央趨勢量數
σ
= 母體變異術 = 分散趨勢量數
p
= 母體比例


  1. nominal scale: 名目尺度/類別尺度
    • 姓名、身高
  2. ordinal scale: 順序尺度/等級尺度
    • 名次: 1、2、3
  3. interval scale: 等距尺度/比例尺度
    • 溫度: 10 -> 20 -> 30

https://www.myclass-lin.org/wordpress/archives/615


  1. Qualitative Data: 非數值資料(定性資料)
  2. Quantitative Data: 數值資料
    • 離散隨機變數
    • 連續隨機變數

Random Variable

隨機變數
給定樣本空間

(S,F),如果其上的實值函數
X:SR
F
(實值)可測函數,則稱
X
為(實值)隨機變數。

A random variable is a measurable function

X:ΩE from a set of possible outcomes
Ω
to a measurable space
E
.

變異數

  • 代數性質

    (σ)2=1NΣ1N(Xiμ)2

    移項,拆開後得到

    ΣXi2=Nσ2+Nμ

    亦可表達為「

    σ2= 平方的期望值-期望值的平方」
    (σ)2=ΣXi2f(x)μ2

    樣本變異數,亦若是

    Σxi2=(n1)s2+nx¯

  • 平移不變性

    • 變異數的平移不變性,平移變異數不變
    • 自己推,很簡單
  • 平方擴充性

    • 變異數的平方擴充性
    • 原來:
      X1,X2,X3...XN
    • Yi=aXi
    • μY=aμX
    • Y
      標準差公式,以
      aXi
      代換,提出a
    • 得知
      σY=aσX
      ,所以
      σY2=a2σX2

共變異數

σx,y2=Cov(X,Y)
=ΣyΣx(xμx)(yμy)f(x,y)

=E((XμX)(YμY))
  定義式
=E(XYμXYμyX+μXμY)

=E(XY)μXE(Y)μYE(X)+E(μXμY)

=E(XY)μXμY

=E(XY)E(X)E(Y)
  計算式

待自己證

Var(aX+bY)=a2Var(X)+b2Var(Y)+2abCov(X,Y)

  • 性質:
    • Cov(X,a)=0
      aConstant
    • Cov(X,Y)=Cov(Y,X)
    • Cov(X,X)=Var(X)=σX2
    • Cov(X+d,Y+c)=Cov(X,Y)
    • Cov(aX,bY)=abCov(X,Y)
      • Eg:
        Cov(2X5,3Y7)=23Cov(X,Y)=6Cov(X,Y)

相關係數

https://zh.wikipedia.org/wiki/皮尔逊积矩相关系数
Correlation Coefficient

ρX,Y=cov(X,Y)σXσY=E[(XμX)(YμY)]σXσY

完全正相關

ρX,Y=1
正相關:共變異數>0

負相關參考資料:菲利浦曲線

母體相關係數

ρX,Y=Corr(X,Y)
母體標準差
σX,Y=Cov(X,Y)

樣本共變異數

Sx,y^=1n1Σ1n(xix¯)(yiy¯)
樣本相關係數
rx,y^

我們希望能夠從 樣本推母體

Sxy=Σ1nxiyinx¯y¯
Sxx=Σ1nxi2n(x¯)2
Σ(xix¯)2

Syy=Σ1nyi2n(y¯)2
Σ(yiy¯)2

rx,y^=Sxy^S^xxS^yy

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


樣本標準差

sx=Sxxn1

Chebyshev's Theorem

https://zh.wikipedia.org/wiki/切比雪夫不等式

P(xμ<zσ)>11z2

Proof

By Markov Theorem
We have

P(Xa)E(X)a, Take
X=|xμ|

P(|xμ|a)E(|xμ|)a

P(|xμ|a)2E((xμ)2)a2

P(|xμ|a)2Var(x)a2

P(|xμ|a)σa

P(|xμ|aσ)1a2

That is Chebyshev's Theorem!

機率複習

eg:

台大 中山 政大 (人數)
30 66 234 330
18 42 210 270
48 108 444 600

列聯表

台大 中山 政大 機率
0.05 0.11 0.39 0.55
0.03 0.07 0.35 0.45
機率 0.08 0.18 0.74 1

邊際機率:在有兩個以上的事件的樣本空間中,若僅考慮某一事件個別發生的機率,稱為邊際機率。
也就是最右邊的 column 及 最下面的 row

獨立事件:自己看

P(A|M):念作 probility of
A
condition
M

算機率在離散型要注意等號

axiom:

  • xP(x)=1
  • 0P(x)1
    ,
    AΩ
  • P(Ω)1
  • A1,A2..ΩAiAj0,ijP(i=1)=i=1P(Ai)

貝氏定理:

A1,A2...AnΩBΩP(Ai|B)=P(B|Ai)P(Ai)i=1nP(B|Ai)P(Ai)

期望值

Except

E(X)=μ
Var(X)=σ2=E[(xμ)2]

分佈

r.v.

X, XB(n,p) ~ : belongs to(服從)
f(x)={0,(otherwise)CxnPx(1P)nx, xN{0}

P:成功的機率

二項式分配:當 n = 1 時是 bernoulli

機率函數

設x為離散型r.v.,則

fx(x)={0,xRxP(X=x),xRx R:range

  • Rx={x|xX(ω),ωΩ}
  • X:ΩR

fxy(x,y)={0,(x,y)RxyP(X=x,Y=y),(x,y)Rxy

老師喜歡這樣表達:當你寫P(),你要在 () 中描述完整事件,所以要寫得像:P(Z<z)或f(x)
* class P(Event);
* class f(var);

f(z)P(Z<z)
f(z)
是單點機率密度
P(Z<z)
是事件機率

Distribution

只有 Possion, normal 分布有封閉性

Discreate

Bernoulli distribution

P(x)=pxq1x
$$

  1. 進行一次成敗實驗,定義 x 表成功的次數
  2. Rx={0,1}
  3. 母數:
    0P1
  4. XBer(p)

Binomial distribution

iid: 獨立且同樣集合,Independent and identically distributed

Definition
在n個獨立的是/非試驗中成功的次數的離散機率分布,其中每次試驗的成功機率為p。其分佈即為二項分佈。

P(x)=(nm)pxqnx
$$

  1. Testing Bernoulli for n times
  2. Rx={xN,x<n}
  3. Bernomial Sigma additivity (可加性)
    • x,yiidB(P)
  4. 二項式分布式離散型的常態分佈
  5. E(x)=np
  6. Var(x)=npq

Poisson distribution

有封閉性

P(x)=eλλxx!

Definition
A discrete random variable X is said to have a Poisson distribution with parameter λ > 0, if, for x = 0, 1, 2, , the probability density function of X is given by:

P(x)=eλλxx!
$$

  1. 在單位時間內,線段平面空間上連續操作,Poisson 過程
    • Poisson must homogeneous and indepedent
  2. R={N+0}
  3. λ
    為發生偶發事件的期望次數
  4. λ=E(X)=Var(X)

Hyper Geometric

Definition

  1. The result of each draw (the elements of the population being sampled) can be classified into one of two mutually exclusive categories.
  2. The probability of a success changes on each draw, as each draw decreases the population.

(kx)(Nknx)(Nn)
$$

  1. E(x)=nkN
  2. 取後不放回抽 n 個,成功 k 次
  3. Var(x)=n(kN)(1kN)(NnN1)
  4. 修正因子:
    (1NnN1)
    因為因為他是 finite 所以前一次會影響下一次,(會縮小),這稱作有限母體的修正因子。
  5. Rx={012...n}

Continuous

Normal

有封閉性

f(x)=12πσe12(xμσ)2
$$

Definition
將一連續變項之觀察值發生機率以圖呈現其分布情形,且具有以下特性:
以平均數為中線,構成左右對稱之單峰、鐘型曲線分布。
觀察值之範圍為負無限大至正無限大之間。

  1. XN(μ,σ2)

  2. 積起來很不好積,所以查表

    • 因為每個常態分佈的
      σ,μ
      不同,查表怎麼查?
      • 規定一個標準常態分布:
        ZN(0,1)
      • Standard Normal Probability Distribution
      • f(x)=12πe12x2
  3. Computing Probabilities for Any Normal
    Probability Distribution

    • 標準化
    • XX(μ,σ2), Let xμσN(0,1)
  4. 常態分配做線性變換,依舊是常態分配

    • 注意平方->平移,變異數->|a|倍
    • E(x¯)=μ
    • Var(x¯)=σ2n
  5. 反標準化

    • ZN(0,1)
    • Let
      X=σZ+μ

Normal Approximation of Binomial Probabilities

  • 葉氏連續性校正(Yates continuity correction)
    用邊界 ± 0.5 去包住離散值

Exponential probability distribution

f(x)=1μexμ
$$
https://zh.wikipedia.org/zh-tw/指数分布

令 τ 為 隨機變數 且其 機率密度(probability density) 滿足

fτ(t):=λeλt,if t0;
fτ(t):=0,if t<0

其中 λ>0 為常數。則我們說 τ 為 exponential distribution 或者說 τ 為 Exponential 隨機變數

E(x)=0x1μexμdx=σ
Var(x)=μ2

By part

公式:

P(x>x0)=ex0μ
proof:

若某計次過程服從 poisson process

間格時間必服從指數分布
指數分布的
μ
跟 poisson 的
μ
互為倒數
注意單位,使用標準單位不容易錯

eg:
Poisson:

eλλxx!

Expnential:
λeyλ

Sampling and Sampling Distributions

definition

樣本統計量的分配,稱為抽樣分配

smapling

  • 有限母體
    • hypergeomttric, sampling w/o replacement, dependent
    • 取後不放回
  • 無限母體
    • Binomonal, sampling w/ replacement, independent

Statistical Inference 統計推測

  • Estimatoin 估測
  • Testing 檢定

我們主要想要估測三件事
平均數、標準差、百分比
我們說這是統計參數

eg:

X1,X2...Xn
x¯=1nΣX

Var(x¯)=Var(1nΣX)=σ2n

點估計

重點:

x¯ 好用

x1,x2...Xniidfxi(xi,θ)

θ^ 去推論母體參數
θ

估計值跟估計量是不同的,估計量有無限多個
有 hat 是估計量

不偏性

Bias(θ¯)=E(θ¯)θ=0

  • 高估估計量
    Bias(θ)>0E(θ)>0
  • 不偏估計量
    Bias(θ)=0E(θ)=0
  • 低估估計量
    Bias(θ)<0E(θ)<0

證明

s2σ2=0

E(s2)=E(1(n1)Σ(xi2)nx¯2)
=1(n1)(Σ(E(xi2))nE(x¯2))

=1(n1)(Σ(Var(x)+E2(x))nE(x¯2))

=1(n1)(Σ(σ2+μ2)nE(x¯2))

=1(n1)(Σ(σ2+μ2)n(σ2n+μ2))

=1(n1)(nσ2+nμ2σ2nμ2)

=1(n1)(nσ2σ2)

=σ2

倒著寫即可。

有效性 (efficiency)

有效性是以估計式的平均平方誤差來衡量, 越小代表估計式的有效性越高。

sum of least squares

Wiki

一致性 (consistency)

當樣本數增大時, 估計值會漸近於母體參數真值。

A consistent estimator is one for which, when the estimate is considered as a random variable indexed by the number n of items in the data set, as n increases the estimates converge in probability to the value that the estimator is designed to estimate.

區間估計

信賴區間(英語:Confidence interval,C.I)

[L,U] 估計
θ
,在
(1α)100%
信心水準
信心水準
(1α)100%
越大表示:越大的信心區間 [L, U] 會包含真實的母體
θ

(1α)是中間面積

1α=P(L<θ<U)

樞紐量

Pivotal Quantity
樞紐量有

  1. 隨機變數
  2. 未知代估母數

https://en.wikipedia.org/wiki/Pivotal_quantity

wikiA pivotal quantity or pivot is a function of observations and unobservable parameters such that the function's probability distribution does not depend on the unknown parameters.

通常是點估計量的 t 或 z 分配

x1,x2...xn
θ
之函數組合
記為
Q(θ^i;θ)
,且其機率分配不依賴於任何未知母數
(即,可完全被掌握)
g(θ^,θ)=nθ^θs

θ
(1α)100
信賴區間

  1. 找出適當估計量
  2. 找出適當的樞紐量及其機率分配
    • 點估計量的分配
  3. 1α=P(L<θ<U)
    • 1α=P(θ^kns<g(θ^,θ)<θ^+kns)
    • k 要查表
  • Margin error:
    E=σnzα2

為什麼 t 分配的自由度是 n-1?

因為t分配中的未知待估母數只有一個(

μ)
因此未必自由度是 n-1

σ 已知樞紐量是 z

查 t 表,如果自由度很大的時候,可以近似去查 z 表

變異數的區間估計

http://mail.tku.edu.tw/yinghaur/lee/stat-new/第十章補充%E7%B5%B1%E8%A8%88%E4%BC%B0%E8%A8%88(%E6%AF%8D%E9%AB%94%E8%AE%8A%E7%95%B0%E6%95%B8%E4%B9%8B%E5%8D%80%E9%96%93%E4%BC%B0%E8%A8%88).pdf

信賴區間的意義

試驗 k 次,平均有

1α 次,未知待估母數會落在該區間。

  • 寫法:
    • 0.95=P(x¯σnzα2μx¯+σnzα2)

樣本比例的信賴區間

單一母體樣本比例的區間估計

X1,X2,...XniidBer(p)

  1. 點估計:
    p^p
  2. p^CLTaN(p,σp^)
    • z=p^pp^(1p^)n
    • a 是漸近
    • 根據中央極限定理漸近常態
  3. 1α=P(|p^p|<zα2SE(p^))
    • SE = standard error

margin error =

zα2p^(1p^)n

假說檢定

  • 讓樣本據說話

  • 檢定力(power),檢定力的大小,就是檢定的有效程度大小:

    • eg:
      • 左圖 power 大,右圖 power 小
      • img
有罪推論 無罪推論
H0 有罪 無罪
Ha 無罪(需負舉證責任) 有罪
H0 !H0
reject
α
type one error
1-
β
Do not reject 1-
α
β
type two error

如果題目沒說

α 沒說,一般來說設 0.05

p-value

樣本觀察值的尾機率

A p-value is a probability that provides a measure of the evidence againest the null hypothesis provided by the sample.
Smaller p-value indicate more evidence againest

H0.

魏丞偉把檢定統計量的絕對值拿掉,假設是檢定統計量是x,|x| > a => x > a or x < -a,之後再查表找大於a,小於-a的尾巴機率,加起來就會是p-value。

假說檢定之三面等價法

  1. 臨界值法
    • Test statistic
  2. p-value 法
    • 樣本觀察值得尾機率
      • 如果雙尾檢定。算兩邊機率
  3. 區間估計法
    • x¯
      出發,算信賴區間

結論必一致

母體變異數未知

自己算樣本變異數,所以使用 t 分配

  • 假設母體常態
    1. 假設 H0
    2. α
    3. test statistic
      • T=x¯μ0snt(n1)

Definition of Student-T distribution

Tν=Zχ2νT
Z
is a standard normal distribution
ν
is the degree of freedom
χ2
is a Chi-square distribution

所需樣本數

單尾檢定

μ0σnzα=μa+σnzβ

左尾右尾可交換,所就用左尾檢定表示,算法相同。

因此,

n=σ2(zα+zβ)2(μ0μa)2
注意這邊
α
值有可能因為雙尾檢定而除以 2

想像:用

α 算閾值的砍點跟用
β
算肯定會一樣,而根據這砍點,定義我的
α
要多少

兩獨立母體之檢定

Case I: 母體常態,
σ12,σ22
皆已知

Recall:

x¯1x¯2μ1μ2
ax¯1bx¯2N(aμ1bμ2,(aσ1)2n1+(bσ2)2n2)

同樣的
Var(aX+bY)=a2Var(X)+b2Var(Y)+2abCov(X,Y)

然後依樣畫葫蘆,放變數進去

σ=(aσ1)2n1+(bσ2)2n2 我個人稱作 coSigma

技巧

在假說檢定上,需要有一個 const 放在右邊(待改進說法),所以會盡量把變數放在左邊,做假說檢定。

H0:μ0>μ1
μ0μ1>0

檢定力:

power=1β

Case II: 母體常態,變異數皆未知

使用T分配

變異數相等(同質)

同質(Homogeneous)變異數假設:

σ1=σ2

Sp2=σ2=(n11)S12+(n21)S22n1+n22
如此帶入

檢定統計數

TS=(x¯1x¯2)(μ1μ2)Sp2(1n1+1n2)

自由度:

n1+n22

變異數相異

檢定統計數

TS=(x¯1x¯2)(μ1μ2)s12n1+s22n2

自由度為(取高斯整數):

df=(s12n1+s22n2)21n11s12n1+1n21s22n2

兩相關常態母體之檢定

(成對樣本)相依母體
Sample matched, pair!

eg: 實驗組、對照組

Sample size:n

dk=x1kx2k

Σdkn=D¯

SD2=Σ(diD¯)2

H0:μD=C

服從 T 分配

T=D¯μDSDnT(n1)

兩獨立母體比例之檢定

p¯1p¯2N(p1p2,p1q1n1+p2q2n2)

因為沒有

p1 p2 所以變異數使用
p¯1
&
p¯2
代替

if    H0:(p1=p2=p)

p=n1p¯1+n2p¯2n1+n2

σ=pq(1n1+1n1)

母體變異數之檢定

Chi-Square symbol:

χ2

推導:

s2=1n1Σ(xix¯)2

(n1)s2=Σ(xix¯)2

(n1)s2σ2=Σ(xix¯)2σ2=(Z12+Z22+Z32+...+Zn2)χ(n1)2

Chi-square doesn't closed!!

cχ2χ2,cR


E(χ2)=df
卡方變數之期望值=自由度
Var(χ2)=2df

卡方變數之變異數=兩倍自由度

檢定統計數:

TS=(n1)s2σ02χ(n1)2

because

χ1α22TSχα22

(n1)s2χα22σ2(n1)s2χ1α22

移項而已
Then we can say

σ has {
1α
}% confidence in this intervel!

兩獨立母體變異數檢定

F-distribation

必要條件:

  1. independent
  2. two Normal populations
  3. equal variances

F distribution

XF(df1,df2)
df1=n11

df2=n21

一個F-分布的隨機變數是兩個卡方分布變數除以自由度的比率:

U1/d1U2/d2=U1/U2d1/d2
其中,
U1χ12,U2χ22
彼此獨立,自由度為
d1,d2

檢定統計數:

TS=s12s22

標準差較大的放上面

可以保證出來的檢定統計數,是在右尾

比較多母體比率

多母體比率相等之檢定

卡方分配(chi-square distridution)

檢定統計數:

χ2=ΣiΣj(fijeij)2eijχ(r1)(c1)2

fij = reality value
eij
= expected value,
H0
,
eij5

r
= number of rows
c
= number of columns

Reject rule

  1. p-value approach: Reject
    H0
    if p-value
    α
  2. Critical value: Reject
    H0
    if
    χ2χα2

Critical values for the marascuilo pairwise comparison procedure for k population proportions

CVij=χα2p¯iq¯ini+p¯jq¯jnj

where

χα2 with a level of significance
α
and
k 1
degrees of freedom
p¯i
and
p¯j
are the proportions for the populations
i
,
j

ni
and
nj
are the sample size of populations
i
,
j

Reject or significant if:

|p¯ip¯j|>CVij

Test of independence

use preverious formula to judge whether the

χ2 is siginificance.

H0: Assumes that there is no association between the two variables.
Ha
: Assumes that there is an association between the two variables.

Goodness of Fit test

適合度

檢定統計數:

χ(k1)2=Σi=1k(fiei)2ei

fi is the reality value
ei
is the expected value,
ei5

k
is the number of categories

Test for is Normal distribution?

Use Goodness of fit test to test whether it is normal distribution.

n divided by 5 in to
n5
slice.

each slice is the

ei
Imgur

And test it's

χ(n53)2

Why -3?

beacuse the degree of freedom is

kp1
p
is the number of parameters of the distribution estimated by the sample.

And the Normal distribution has 2 parameters.

Hence

kp1=k3