Presentation is loading. Please wait.

Presentation is loading. Please wait.

假 設 檢 定.

Similar presentations


Presentation on theme: "假 設 檢 定."— Presentation transcript:

1 假 設 檢 定

2 Two sample tests (兩組樣本的檢定)
2 兩組獨立樣本:兩群樣本之間獨立 使用兩種不同麻醉劑的病人血壓、男女之間的藥物反應 配對資料(paired):兩個樣本之間存在相關性、或是為配對樣本。 由雙胞胎的資料來測試兩種藥的效果,一群學生在受訓前與受訓後的英文成績,或是眼科病患左眼vs.右眼的手術恢復指數。

3 Two sample t-test Two groups, X and Y, are independent and
3 Two groups, X and Y, are independent 比較X與Y是否相同→compare and and 3

4 Two sample t-test:equal variance
4 Assume 合併 與 估計 檢定統計量

5 Two sample t-test:unequal variance
5 Assume 用 估計 ,用 估計 檢定統計量

6 Two sample t-test 6 t.test(x, y, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, var.equal = FALSE, conf.level = 0.95, ...) x: 第一組樣本的觀察值 y:第二組樣本的觀察值 paired: 是否為配對資料 var.equal: T表示兩組變異數相同,F表示兩組變異數不同 conf.level: 顯著水準

7 Example 7 檢定data1中,男女體重是否相同?

8 Example 8 P-value= <0.05, reject H0: weights of male and female are not equal

9 Example 若顯著水準為0.1? 呼叫檢定的結果 9

10 Practice 檢定data1中,男女身高是否相同? 先畫出box plot,看看男女身高的中位數數與變異是否相同
10 檢定data1中,男女身高是否相同? 先畫出box plot,看看男女身高的中位數數與變異是否相同 再根據上圖的結論,作檢定

11 檢定兩群體變異數是否相同 11 兩組獨立樣本 , 要檢定 已知 且 則在H0之下, R指令:var.test(…)

12 var.test() 12 var.test(x, y, ratio = 1, alternative=c("two.sided", "less", "greater"), conf.level = 0.95, ...) x:第一組的觀測值 y:第二組的觀測值 ratio:

13 Example 檢定data1中,男女體重的變異數是否相同?
13 檢定data1中,男女體重的變異數是否相同? P-value= <0.05,所以拒絕H0,也就是說男女體重的變異數不同 所以在檢定男女體重是否相同時,應該要用var.equal=F

14 Practice 14 檢定data1中,男女身高是否相同? 先檢定男女身高的變異數是否相同 再根據上面的結論,作檢定

15 Paired t-test 15 X and Y are dependent Data: Test statistic Reject if

16 Example 16 P-value=0.8852>0.05, not reject H0

17 Practice 17 想知道某種降血壓藥物是否有效,隨機抽取出10個高血壓病人,測量吃藥前與吃藥後的血壓。請問,此藥物是否能有效降低血壓?

18 Analysis of variance (ANOVA)
18 Test if k groups (k2) with k different treatments have the same population mean If only one factor (drug A, B, C) is considered in the data, it is one-way ANOVA; when there is another factor in the model (smoke or not), it is two-way ANOVA.

19 Analysis of variance (ANOVA)
19 ANOVA model (one-way): Assumptions: are independent and normally distributed. 19

20 Analysis of variance (ANOVA)
20 Let denote the mean of the ith group, and be the overall mean between-group sum of squares (SSB) within-group sum of squares (SSW) total sum of squares (SST)

21 ANOVA table 21 Source of variation Degree of freedom Sum of squares Mean square F statistic Between group k-1 SSB MSB= SSB/(k-1) F=MSB/MSW Within group N-k SSW MSW= SSW/(N-K) Total N-1 SST If the null hypothesis is true, MSB and MSW would be close, and F≈1 Reject the null hypothesis if 21

22 Example R指令:aov(formula, data = NULL, ...) formula: Y~factor
22 R指令:aov(formula, data = NULL, ...) formula: Y~factor Y, response Factor 1 Factor 2

23 Example 23 One-way ANOVA: type

24 Example One-way ANOVA: food
24 One-way ANOVA: food For “type”, p-value=2.302×10-5<0.05, so reject H0. i.e. the mean weights of different types are different. For “food”, p-value=0.2961>0.05, do not reject H0, so the mean weights of pigs fed with different foods are the same.

25 Eample Two-way ANOVE 考慮了food(與其交互作用)之下,不同種類的豬之平均體重不同 25

26 Practice 26 12 pigs fed with 3 brands of cereal 請問食用不同廠牌飼料的豬平均體重是否不同?

27 Note 27 ANOVA is used to test if the different treatment groups have the same mean. If the test result leads to rejection of H0, we can apply the T-test next to see which treatment contributes the difference. But, the significant level needs to be adjusted for the total number of T-test performed. It is called multiple-comparisons.

28 Homework 在Mass package中的資料 “michelson” 請問在Expt=1與Expt=2的平均光速相同嗎?
28 在Mass package中的資料 “michelson” Expt: The experiment number, from 1 to 5. Run: The run number within each experiment. Speed: Speed-of-light measurement. 請問在Expt=1與Expt=2的平均光速相同嗎? 請問在Expt=1與Expt=3的平均光速相同嗎? 請問這5種實驗的平均光速相同嗎?

29 Wilcoxon rank sum test 29 Compare two independent samples with small sample size of continuous outcomes EX: two diet pills, 1 and 2, randomly assigned to 8 patients, outcomes are their weight loss Test statistic, , S: rank sum of treatment 1, n1 is its sample size In this example,

30 Wilcoxon rank sum test 30 If these two pills have the same effects, W would be small The critical values of different sums and sample sizes can be found in tables R指令:wilcox.test(x, y, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, exact = NULL, conf.int = FALSE, conf.level = 0.95, ...) x: 第一組的資料 y:第二組的資料 exact: 是否計算exact p-value 30

31 Wilcoxon rank sum test 31 P-value=0.6875>0.05, so not reject H0, i.e. the mean weight loss of pill 1 and pill 2 are equal.

32 Practice 32 8隻豬隨機分派食用兩種飼料,一週後體重增加如下 請問食用不同飼料的豬之平均體重是否相同?

33 Wilcoxon signed-rank test
33 Compare two dependent samples with small sample size of continuous outcomes EX: 9 patients, measure the blood pressure before and after Test statistic, T, is the sum of the positive ranks The median of all possible values of T is If the medicine is not effective, T would be close to the median 33

34 Wilcoxon signed-rank test
34 R指令一樣是“wilcox.test”,其中“paired=T”. P-value= <0.05, reject H0. 所以吃藥前後血壓不同

35 Practice 35 想知道某種降血壓藥物是否有效,隨機抽取出10個高血壓病人,測量吃藥前與吃藥後的血壓。請問,此藥物是否能有效降低血壓?

36 Expect rank sum of group i under the null hypothesis
Kruskal-Wallis test 36 Compare k independent samples each with small sample size Test statistic Look up the tables to find critical values R指令:kruskal.test(…) Expect rank sum of group i under the null hypothesis 36

37 Example 37

38 Practice 38 12 pigs fed with 3 brands of cereal 請問食用不同廠牌飼料的豬平均體重是否不同?


Download ppt "假 設 檢 定."

Similar presentations


Ads by Google