Kursus 02402/02323 Introducerende Statistik. Forelæsning 6: Sammenligning af to grupper

Relaterede dokumenter
Oversigt. 1 Motiverende eksempel - energiforbrug. 2 Hypotesetest (Repetition) 3 Two-sample t-test og p-værdi. 4 Konfidensinterval for forskellen

Oversigt. 1 Motiverende eksempel - energiforbrug. 2 Hypotesetest (Repetition) 3 Two-sample t-test og p-værdi. 4 Konfidensinterval for forskellen

Kursus 02323: Introducerende Statistik. Forelæsning 12: Forsøgsplanlægning. Peder Bacher

Introduktion til Statistik. Forelæsning 5: Hypotesetest, power og modelkontrol - one sample. Peder Bacher

Basic statistics for experimental medical researchers

Oversigt. Kursus 02402/02323 Introducerende Statistik. Forelæsning 5: Hypotesetest, power og modelkontrol - one sample

enote 3: Hypotesetests for én gruppe/stikprøve Introduktion til Statistik Forelæsning 5: Hypotesetest, power og modelkontrol - one sample Peder Bacher

Forelæsning 11: Envejs variansanalyse, ANOVA

k UAFHÆNGIGE grupper Oversigt 1 Intro eksempel 2 Model og hypotese 3 Beregning - variationsopspaltning og ANOVA tabellen 4 Hypotesetest (F-test)

Ensidet eller tosidet alternativ. Hypoteser. tosidet alternativ. nul hypotese testes mod en alternativ hypotese

Kursus Introduktion til Statistik. Forelæsning 7: Kapitel 7 og 8: Statistik for to gennemsnit, ( , ) Per Bruun Brockhoff

Statistik for MPH: 7

Kursus 02402/02323 Introduktion til statistik. Forelæsning 13: Et overblik over kursets indhold. Klaus K. Andersen og Per Bruun Brockhoff

Forelæsning 4: Konfidensinterval for middelværdi (og spredning)

Introduktion til Statistik. Forelæsning 12: Inferens for andele. Peder Bacher

Statistik for MPH: oktober Attributable risk, bestemmelse af stikprøvestørrelse (Silva: , )

Forelæsning 11: Tovejs variansanalyse, ANOVA

Introduktion til Statistik. Forelæsning 10: Inferens for andele. Peder Bacher

Vina Nguyen HSSP July 13, 2008

1 enote 1: Simple plots og deskriptive statistik. 2 enote2: Diskrete fordelinger. 3 enote 2: Kontinuerte fordelinger

Reexam questions in Statistics and Evidence-based medicine, august sem. Medis/Medicin, Modul 2.4.

Kvant Eksamen December timer med hjælpemidler. 1 Hvad er en continuous variable? Giv 2 illustrationer.

STAT-UB.0103 Spring 2012 Homework Set 8 Solutions

Konfidensintervaller og Hypotesetest

Afsnit E1 Konfidensinterval for middelværdi i normalfordeling med kendt standardafvigelse

k UAFHÆNGIGE grupper F-test Oversigt 1 Intro eksempel 2 Model og hypotese 3 Beregning - variationsopspaltning og ANOVA tabellen

Generalized Probit Model in Design of Dose Finding Experiments. Yuehui Wu Valerii V. Fedorov RSU, GlaxoSmithKline, US

Forelæsning 5: Kapitel 7: Inferens for gennemsnit (One-sample setup)

Kursus 02323: Introducerende Statistik. Forelæsning 8: Simpel lineær regression. Peder Bacher

Eksamen Bacheloruddannelsen i Medicin med industriel specialisering

1 enote 1: Simple plots og deskriptive statistik. 2 enote 2: Diskrete fordelinger. 3 enote 2: Kontinuerte fordelinger

Oversigt. 1 Intro: Regneeksempel og TV-data fra B&O. 2 Model og hypotese. 3 Beregning - variationsopspaltning og ANOVA tabellen

Project Step 7. Behavioral modeling of a dual ported register set. 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU 1

Program. t-test Hypoteser, teststørrelser og p-værdier. Hormonkonc.: statistisk model og konfidensinterval. Hormonkoncentration: data

Løsning eksamen d. 15. december 2008

Forelæsning 6: Kapitel 7: Hypotesetest for gennemsnit (one-sample setup)

Anvendt Statistik Lektion 5. Sammenligning af to grupper * Sammenligning af middelværdier * Sammenligning af andele

Forsøgsplanlægning Stikprøvestørrelse

Linear Programming ١ C H A P T E R 2

Program. Konfidensinterval og hypotesetest, del 2 en enkelt normalfordelt stikprøve I SAS. Øvelse: effekt af diæter

Opgaver til ZAR II. Afdeling for Anvendt Matematik og Statistik Michael Sørensen Oktober Opgave 1

Kursus 02402/02323 Introducerende Statistik

Ikke-parametriske tests

Statistik Lektion 20 Ikke-parametriske metoder. Repetition Kruskal-Wallis Test Friedman Test Chi-i-anden Test

Oversigt. 1 Motiverende eksempel: Højde-vægt. 2 Lineær regressionsmodel. 3 Mindste kvadraters metode (least squares)

Statistik og Sandsynlighedsregning 2. Repetition og eksamen. Overheads til forelæsninger, mandag 7. uge

Question I.1 (1) We use Method 3.8 from Chapter 3 to achieve

Klasseøvelser dag 2 Opgave 1

Anvendt Statistik Lektion 5. Sammenligning af to grupper * Sammenligning af middelværdier * Sammenligning af andele

Privat-, statslig- eller regional institution m.v. Andet Added Bekaempelsesudfoerende: string No Label: Bekæmpelsesudførende

Besvarelse af vitcap -opgaven

Introduktion til Statistik. Forelæsning 3: Kontinuerte fordelinger. Peder Bacher

Basal statistik Esben Budtz-Jørgensen 4. november Forsøgsplanlægning Stikprøvestørrelse

Løsning til eksaminen d. 29. maj 2009

Indhold. 2 Tosidet variansanalyse Additive virkninger Vekselvirkning... 9

q-værdien som skal sammenlignes med den kritiske Chi-i-Anden værdi p-værdien som skal sammenlignes med signifikansniveauet.

Oversigt. 1 Gennemgående eksempel: Højde og vægt. 2 Korrelation. 3 Regressionsanalyse (kap 11) 4 Mindste kvadraters metode

1 Sammenligning af 2 grupper Responsvariabel og forklarende variabel Afhængige/uafhængige stikprøver... 2

Ikke-parametriske metoder. Repetition Wilcoxon Signed-Rank Test Kruskal-Wallis Test Friedman Test Chi-i-anden Test

En Introduktion til SAS. Kapitel 5.

men nu er Z N((µ 1 µ 0 ) n/σ, 1)!! Forkaster hvis X 191 eller X 209 eller

Hvad skal vi lave? Responsvariabel og forklarende variabel Afhængige/uafhængige stikprøver

Skriftlig eksamen Science statistik- ST501

Analyseinstitut for Forskning

Vores mange brugere på musskema.dk er rigtig gode til at komme med kvalificerede ønsker og behov.

Løsning til eksaminen d. 14. december 2009

Oversigt. 1 Eksempel. 2 Fordelingen for gennemsnittet t-fordelingen. 3 Konfidensintervallet for µ Eksempel

I dag. Statistisk analyse af en enkelt stikprøve: LR test og t-test, modelkontrol, R Sandsynlighedsregning og Statistik (SaSt)

Hypoteser om mere end to stikprøver ANOVA. k stikprøver: (ikke ordinale eller højere) gælder også for k 2! : i j

User Manual for LTC IGNOU

Forelæsning 11: Kapitel 11: Regressionsanalyse

(studienummer) (underskrift) (bord nr)

Forsøgsplanlægning Stikprøvestørrelse

Measuring Evolution of Populations

Muligheder: NB: test for µ 1 = µ 2 i model med blocking ækvivalent med parret t-test! Ide: anskue β j som stikprøve fra normalfordeling.

Oversigt. Kursus Introduktion til Statistik. Forelæsning 9: Inferens for andele (kapitel 10) Per Bruun Brockhoff

enote 5: Simpel lineær regressions analyse Kursus 02402/02323 Introducerende Statistik Oversigt

Normalfordelingen. Statistik og Sandsynlighedsregning 2

Exam questions in Statistics and evidence-based medicine, spring sem. Medis/Medicin, Modul 2.4.

enote 2: Kontinuerte fordelinger Introduktion til Statistik Forelæsning 3: Kontinuerte fordelinger Peder Bacher enote 2: Continuous Distributions

Skriftlig Eksamen Kombinatorik, Sandsynlighed og Randomiserede Algoritmer (DM528)

(studienummer) (underskrift) (bord nr)

Program: 1. Repetition: fordeling af observatorer X, S 2 og t. 2. Konfidens-intervaller, hypotese test, type I og type II fejl, styrke.

Generelle lineære modeller

X M Y. What is mediation? Mediation analysis an introduction. Definition

KA 4.2 Kvantitative Forskningsmetoder Forår 2010

Kursus Introduktion til Statistik. Forelæsning 12: Variansanalyse. Per Bruun Brockhoff

Anvendt Statistik Lektion 9. Variansanalyse (ANOVA)

Forelæsning 9: Inferens for andele (kapitel 10)

Multivariate Extremes and Dependence in Elliptical Distributions

Trin 1: Formuler hypotese Spørgsmål der ønskes testet vha. data H 0 : Nul hypotese Formuleres som en ligheds hændelse

Hvad skal vi lave? Nulhypotese - alternativ. Teststatistik. Signifikansniveau

Forelæsning 10: Statistik ved hjælp af simulering

Statistik. Statistik. Hvad er Statistik? Hvad er Statistik? Hvad er Statistik? 1. Hvad er statistik? 2. Mennesker som måleinstrumenter

Sport for the elderly

Kommentarer til opg. 1 og 3 ved øvelser i basalkursus, 3. uge

1 Statistisk inferens: Hypotese og test Nulhypotese - alternativ Teststatistik P-værdi Signifikansniveau...

PARALLELIZATION OF ATTILA SIMULATOR WITH OPENMP MIGUEL ÁNGEL MARTÍNEZ DEL AMOR MINIPROJECT OF TDT24 NTNU

t-fordeling Boxplot af stikprøve (n=20) fra t(2)-fordeling Program ( ): 1. repetition: fordeling af observatorer X, S 2 og t.

Anvendt Statistik Lektion 9. Variansanalyse (ANOVA)

Transkript:

Kursus 02402/02323 Introducerende Statistik Forelæsning 6: Sammenligning af to grupper Peder Bacher DTU Compute, Dynamiske Systemer Bygning 303B, Rum 009 Danmarks Tekniske Universitet 2800 Lyngby Danmark e-mail: pbac@dtu.dk Efterår 2016 DTU Compute Introduktion til Statistik Efterår 2016 1 / 53

enote 3: Statistik for to grupper/stikprøver Specifikke metoder, to grupper: Konfidensinterval for forskel i middelværdi Test for forskel i middelværdi (t-test) Forsøgsplanlægning: Beregn sample størrelsen for den ønskede styrke Specifikke metoder, to PARREDE grupper: Tag differencen for hver måling statistik for én gruppe DTU Compute Introduktion til Statistik Efterår 2016 2 / 53

enote 3: Two Samples Specific methods, two samples: Confidence interval for the mean difference Test for the mean difference (t-test) Planning: calculating the sample size for wanted power Specific methods, two PAIRED samples: Take difference One sample DTU Compute Introduktion til Statistik Efterår 2016 3 / 53

Oversigt 1 Motiverende eksempel - energiforbrug 2 Hypotesetest (Repetition) 3 Two-sample t-test og p-værdi 4 Konfidensinterval for forskellen 5 Overlappende konfidensintervaller? 6 Det parrede setup 7 Checking the normality assumptions 8 The pooled t-test - a possible alternative DTU Compute Introduktion til Statistik Efterår 2016 4 / 53

Motiverende eksempel - energiforbrug Motiverende eksempel - energiforbrug Forskel på energiforbrug? I et ernæringsstudie ønsker man at undersøge om der er en forskel i energiforbrug for forskellige typer (moderat fysisk krævende) arbejde. In the study, the energy usage of 9 nurses from hospital A and 9 (other) nurses from hospital B have been measured. The measurements are given in the following table in mega Joule (MJ). Stikprøve fra hver hospital n 1 = n 2 = 9: Hospital A Hospital B 7.53 9.21 7.48 11.51 8.08 12.79 8.09 11.85 10.15 9.97 8.40 8.79 10.88 9.69 6.13 9.68 7.90 9.19 DTU Compute Introduktion til Statistik Efterår 2016 6 / 53

Motiverende eksempel - energiforbrug Eksempel - energiforbrug Hypotesen om ingen forskel ønskes undersøgt: H 0 : µ 1 = µ 2 Sample means og standard deviations: ˆµ 1 = x 1 = 8.293, (s 1 = 1.428) ˆµ 2 = x 2 = 10.298, (s 2 = 1.398) Er data i overenstemmelse med nulhyposen H 0? Data: x 2 x 1 = 2.005 Nulhypotese: H 0 : µ 2 µ 1 = 0 NYT: p-værdi for forskel: p-værdi = 0.0083 (Beregnet under det scenarie, at H 0 er sand) NYT:Konfidensinterval for forskel: 2.005 ± 1.412 = [0.59; 3.42] DTU Compute Introduktion til Statistik Efterår 2016 7 / 53

Hypotesetest (Repetition) Definition af hypotesetest og signifikans (Repetition) Definition 3.23. Hypotesetest: We say that we carry out a hypothesis test when we decide against a null hypothesis or not using the data. A null hypothesis is rejected if the p-value, calculated after the data has been observed, is less than some α, that is if the p-value < α, where α is some pre-specifed (so-called) significance level. And if not, then the null hypothesis is said to be accepted. Definition 3.28. Statistisk signifikans: An effect is said to be (statistically) significant if the p-value is less than the significance level α. (OFTE bruges α = 0.05) DTU Compute Introduktion til Statistik Efterår 2016 9 / 53

Hypotesetest (Repetition) Metode 3.36. Steps ved hypotesetests - et overblik (Repetition) Helt generelt består et hypotesetest af følgende trin: 1 Formulate the hypotheses and choose the level of significance α (choose the risk-level ) 2 Calculate, using the data, the value of the test statistic 3 Calculate the p-value using the test statistic and the relevant sampling distribution, and compare the p-value and the significance level α and make a conclusion 4 (Alternatively, make a conclusion based on the relevant critical value(s)) DTU Compute Introduktion til Statistik Efterår 2016 10 / 53

Hypotesetest (Repetition) Definition og fortolkning af p-værdien (Repetition) p-værdien udtrykker evidence imod nulhypotesen Tabel 3.1: p < 0.001 Very strong evidence against H 0 0.001 p < 0.01 Strong evidence against H 0 0.01 p < 0.05 Some evidence against H 0 0.05 p < 0.1 Weak evidence against H 0 p 0.1 Little or no evidence against H 0 Definition 3.21 af p-værdien: The p-value is the probability of obtaining a test statistic that is at least as extreme as the test statistic that was actually observed. This probability is calculated under the assumption that the null hypothesis is true. DTU Compute Introduktion til Statistik Efterår 2016 11 / 53

Two-sample t-test og p-værdi Metode 3.58: Two-sample t-test Beregning af teststørrelsen When considering the null hypothesis about the difference between the means of two independent samples: δ = µ 2 µ 1 the (Welch) two-sample t-test statistic is H 0 : δ = δ 0 t obs = ( x 1 x 2 ) δ 0 s 2 1 /n 1 + s 2 2 /n 2 DTU Compute Introduktion til Statistik Efterår 2016 13 / 53

Two-sample t-test og p-værdi Theorem 3.59: Fordelingen af (Welch) t-teststørrelsen Welch t-teststørrelsen er t-fordelt The (Welch) two-sample statistic seen as a random variable: T = ( X 1 X 2 ) δ 0 S1 2/n 1 + S2 2/n 2 approximately, under the null hypothesis, follows a t-distribution with ν degrees of freedom, where ( s 2 ) 2 1 n 1 + s2 2 n 2 ν =. (s 2 1 /n 1) 2 n 1 1 + (s2 2 /n 2) 2 n 2 1 if the two population distributions are normal or if the two sample sizes are large enough. DTU Compute Introduktion til Statistik Efterår 2016 14 / 53

Two-sample t-test og p-værdi Metode 3.60: Two-sample t-test Et level α test er 1 Compute t obs and ν as given above. 2 Compute the evidence against the null hypothesis a H 0 : µ 1 µ 2 = δ 0 vs. the alternative hypothesis H 1 : µ 1 µ 2 δ 0 by the p value = 2 P(T > t obs ) where the t-distribution with ν degrees of freedom is used. 3 If p value < α: We reject H 0, otherwise we accept H 0. 4 The rejection/acceptance conclusion could alternatively, but equivalently, be made based on the critical value(s) ±t 1 α/2 : If t obs > t 1 α/2 we reject H 0, otherwise we accept H 0. a We are often interested in the test where δ 0 = 0 DTU Compute Introduktion til Statistik Efterår 2016 15 / 53

Two-sample t-test og p-værdi Metode 3.61: Det ensidede two-sample t-test Et level α ensidet less test er 1 Compute t obs and ν as given above. 2 Compute the evidence against the null hypothesis H 0 : µ 1 µ 2 δ 0 vs. the alternative hypothesis H 1 : µ 1 µ 2 < δ 0 by the p value = P(T < t obs ) where the t-distribution with ν degrees of freedom is used. 3 If p value < α: We reject H 0, otherwise we accept H 0. 4 The rejection/acceptance conclusion could alternatively, but equivalently, be made based on the critical value t α : If t obs < t α we reject H 0, otherwise we accept H 0. DTU Compute Introduktion til Statistik Efterår 2016 16 / 53

Two-sample t-test og p-værdi Metode 3.62: Det ensidede two-sample t-test Et level α ensidet greater test er 1 Compute t obs and ν as given above. 2 Compute the evidence against the null hypothesis H 0 : µ 1 µ 2 δ 0 vs. the alternative hypothesis H 1 : µ 1 µ 2 > δ 0 by the p value = P(T > t obs ) where the t-distribution with ν degrees of freedom is used. 3 If p value < α: We reject H 0, otherwise we accept H 0. 4 The rejection/acceptance conclusion could alternatively, but equivalently, be made based on the critical value t 1 α : If t obs > t 1 α we reject H 0, otherwise we accept H 0. DTU Compute Introduktion til Statistik Efterår 2016 17 / 53

Two-sample t-test og p-værdi Spørgsmål til fordelingen af forskellen i stikprøvegennemsnit (socrative.com - ROOM:PBAC) Hvilken af pdf erne repræsenterer fordelingen af forskellen i stikprøvegennemsnit? X 2 X 1 pdf pdf 0.00 0.05 0.10 0.15 0.00 0.05 0.10 0.15 A -5 0 5 10 15 x B -5 0 5 10 15 x under: H 0 : δ = 10 pdf 0.00 0.05 0.10 0.15 C -5 0 5 10 15 x (sample sizes n 1 = 7 and n 2 = 8) (sample std. dev. s 1 = 18 and s 2 = 24) pdf 0.0 0.1 0.2 0.3 0.4 D -5 0 5 10 15 x A B C eller D? Svar: A DTU Compute Introduktion til Statistik Efterår 2016 18 / 53

Two-sample t-test og p-værdi Spørgsmål til fordelingen af forskellen i stikprøvegennemsnit (socrative.com - ROOM:PBAC) Hvilken af pdf erne repræsenterer fordelingen af X 2 X 1 δ 0 pdf pdf 0.00 0.05 0.10 0.15 0.00 0.05 0.10 0.15 A -5 0 5 10 15 x B -5 0 5 10 15 under: H 0 : δ = 10 pdf 0.00 0.05 0.10 0.15 x C -5 0 5 10 15 (sample sizes n 1 = 7 and n 2 = 8) (sample std. dev. s 1 = 18 and s 2 = 24) pdf 0.0 0.1 0.2 0.3 0.4 x D -5 0 5 10 15 x A B C eller D? Svar: C DTU Compute Introduktion til Statistik Efterår 2016 19 / 53

Two-sample t-test og p-værdi Spørgsmål til fordelingen af forskellen i stikprøvegennemsnit (socrative.com - ROOM:PBAC) Hvilken af pdf erne repræsenterer fordelingen af T = X 2 X 1 δ 0 s 2 1 /n 1 + s 2 2 /n 2 pdf pdf 0.00 0.05 0.10 0.15 0.00 0.05 0.10 0.15 A -5 0 5 10 15 x B -5 0 5 10 15 x under: H 0 : δ = 10 pdf 0.00 0.05 0.10 0.15 C -5 0 5 10 15 x (sample sizes n 1 = 7 and n 2 = 8) (sample std. dev. s 1 = 18 and s 2 = 24) pdf 0.0 0.1 0.2 0.3 0.4 D -5 0 5 10 15 x A B C eller D? Svar: D DTU Compute Introduktion til Statistik Efterår 2016 20 / 53

Two-sample t-test og p-værdi Eksempel - energiforbrug Hypotesen om ingen forskel ønskes undersøgt: H 0 : δ = µ 2 µ 1 = 0 versus the non-directional(= two-sided) alternative: H 0 : δ = µ 2 µ 1 0 Først beregninger af t obs og ν: t obs = 10.298 8.293 2.0394/9 + 1.954/9 = 3.01 and ν = ( 2.0394 9 + 1.954 ) 2 9 (2.0394/9) 2 8 + (1.954/9)2 8 = 15.99 DTU Compute Introduktion til Statistik Efterår 2016 21 / 53

Two-sample t-test og p-værdi Eksempel - energiforbrug Dernæst findes p-værdien: p value = 2 P(T > t obs ) = 2 P(T > 3.01) = 2 0.00415 = 0.0083 ## p-værdi for nulhypotese om ingen forskel mellem sygeplejeskers energiforbrug 1 - pt(3.01, df = 15.99) ## [1] 0.0042 DTU Compute Introduktion til Statistik Efterår 2016 22 / 53

Two-sample t-test og p-værdi Kristiske værdier og hypotesetest Acceptområdet er værdier for teststatistikken t obs som ligger indenfor de kritiske værdier: Acceptance Rejection Rejection t 0.025 0 t 0.975 Acceptområdet er værdier for teststatistikken t obs som ligger indenfor de kritiske værdier: DTU Compute Introduktion til Statistik Efterår 2016 23 / 53

Two-sample t-test og p-værdi Den standardiserede skala Hvis t obs er i acceptområdet, så accepteres H 0 Rejection Acceptance Rejection t0.975 0 t0.975 Den egentlige skala Hvis x ȳ er i acceptområdet, så accepteres H 0 δ0 sim1 Rejection s δ0 2 1 t0.975 n 2 1 Acceptance + s2 2 n 2 2 δ0 s δ0 + 2 1 t0.975 n 2 1 Rejection + s2 2 n 2 2 sim1 sim2 DTU Compute Introduktion til Statistik Efterår 2016 24 / 53

Konfidensinterval for forskellen Metode 3.69: Konfidensinterval for µ 1 µ 2 Konfidensintervallet for middelforskellen bliver: For two samples x 1,...,x n1 and y 1,...,y n2 the 100(1 α)% confidence interval for µ 1 µ 2 is given by s 2 1 x ȳ ± t 1 α/2 + s2 2 n 1 n 2 where t 1 α/2 is the 100(1 α/2)%-quantile from the t-distribution with ν degrees of freedom given from equation (3.26) (as above). DTU Compute Introduktion til Statistik Efterår 2016 26 / 53

Konfidensinterval for forskellen Den standardiserede skala Hvis t obs er i acceptområdet, så accepteres H 0 Rejection Acceptance Rejection t0.975 0 t0.975 Den egentlige skala Hvis x ȳ er i acceptområdet, så accepteres H 0 sim1 sim2 sim3 sim4 sim5 Rejection Rejection Rejection Rejection Rejection s δ0 2 1 t0.975 n 2 1 Acceptance Acceptance Acceptance Acceptance Acceptance + s2 2 n 2 2 δ0 Rejection Rejection s δ0 + 2 1 t0.975 n 2 1 Rejection Rejection Rejection + s2 2 n 2 2 Konfidensintervallet Nulhypoteser med x ȳ udenfor konfidensintervallet ville være blevet afvist δ sim1 DTU Compute Introduktion til Statistik Efterår 2016 27 / 53

Konfidensinterval for forskellen Eksempel - energiforbrug - det hele i R: Let us find the 95% confidence interval for µ 2 µ 1 : Since the relevant t-quantile is, using ν = 15.99, the confidence interval becomes: t 0.975 = 2.120 10.298 8.293 ± 2.120 which then gives the result as also seen above: [0.59; 3.42] 2.0394 9 + 1.954 9 DTU Compute Introduktion til Statistik Efterår 2016 28 / 53

Konfidensinterval for forskellen Eksempel - energiforbrug - det hele i R: ################################ ## t-test for forskel i middelværdi på sygeplejeskers energiforbrug xa <- c(7.53, 7.48, 8.08, 8.09, 10.15, 8.4, 10.88, 6.13, 7.9) xb <- c(9.21, 11.51, 12.79, 11.85, 9.97, 8.79, 9.69, 9.68, 9.19) ## Default i t.test() er H_0: mu_1 = mu_2 (ingen forskel i middelværdi) t.test(xb, xa) ## ## Welch Two Sample t-test ## ## data: xb and xa ## t = 3, df = 20, p-value = 0.008 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## 0.59 3.42 ## sample estimates: ## mean of x mean of y ## 10.3 8.3 DTU Compute Introduktion til Statistik Efterår 2016 29 / 53

Konfidensinterval for forskellen I pausen: Installer Angry Birds (den originale) på jeres device (Android, Windows phone eller iphone) DTU Compute Introduktion til Statistik Efterår 2016 30 / 53

Overlappende konfidensintervaller? Eksempel - energiforbrug - Præsentation af resultat Barplot med error bars ses ofte Et grupperet barplot med nogle error bars - herunder er 95%-konfidensintervallerne for hver gruppe vist: 0 2 4 6 8 10 A B DTU Compute Introduktion til Statistik Efterår 2016 32 / 53

Overlappende konfidensintervaller? Vær varsom med at bruge overlappende konfidensintervaller Remark 3.73. Regel for brug af overlappende konfidensintervaller : When two CIs DO NOT overlap: The two groups are significantly different When two CIs DO overlap: We do not know what the conclusion is DTU Compute Introduktion til Statistik Efterår 2016 33 / 53

Det parrede setup Motiverende eksempel - sovemedicin Forskel på sovemedicin? I et studie er man interesseret i at sammenligne 2 sovemidler A og B. For 10 testpersoner har man fået følgende resultater, der er givet i forlænget søvntid (i timer) (Forskellen på effekten af de to midler er angivet): Stikprøve, n = 10: person A B D = B A 1 +0.7 +1.9 +1.2 2-1.6 +0.8 +2.4 3-0.2 +1.1 +1.3 4-1.2 +0.1 +1.3 5-1.0-0.1 +0.9 6 +3.4 +4.4 +1.0 7 +3.7 +5.5 +1.8 8 +0.8 +1.6 +0.8 9 0.0 +4.6 +4.6 10 +2.0 +3.4 +1.4 DTU Compute Introduktion til Statistik Efterår 2016 35 / 53

Det parrede setup Parret setup og analyse: Brug one-sample analyse ## Det parrede setup: Tag forskellen og brug one-sample test x1 <- c(.7,-1.6,-.2,-1.2,-1,3.4,3.7,.8,0,2) x2 <- c(1.9,.8,1.1,.1,-.1,4.4,5.5,1.6,4.6,3.4) dif <- x2-x1 t.test(dif) ## ## One Sample t-test ## ## data: dif ## t = 5, df = 9, p-value = 0.001 ## alternative hypothesis: true mean is not equal to 0 ## 95 percent confidence interval: ## 0.86 2.48 ## sample estimates: ## mean of x ## 1.7 DTU Compute Introduktion til Statistik Efterår 2016 36 / 53

Det parrede setup Parret setup og analyse: Brug one-sample analyse ## Eller angiv at testen er parret med "paired=true" t.test(x2, x1, paired=true) ## ## Paired t-test ## ## data: x2 and x1 ## t = 5, df = 9, p-value = 0.001 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## 0.86 2.48 ## sample estimates: ## mean of the differences ## 1.7 DTU Compute Introduktion til Statistik Efterår 2016 37 / 53

Det parrede setup Parret versus independent eksperiment Completely Randomized (independent samples) 20 patients are used and completely at random allocated to one of the two treatments (but usually making sure to have 10 patients in each group). Hence: different persons in the different groups. Paired (dependent samples) 10 patients are used, and each of them tests both of the treatments. Usually this will involve some time in between treatments to make sure that it becomes meaningful, and also one would typically make sure that some patients do A before B and others B before A. (and doing this allocation at random). Hence: the same persons in the different groups. DTU Compute Introduktion til Statistik Efterår 2016 38 / 53

Det parrede setup Eksempel - Sovemedicin - FORKERT analyse ## ## Welch Two Sample t-test ## ## data: x1 and x2 ## t = -2, df = 20, p-value = 0.07 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## -3.49 0.15 ## sample estimates: ## mean of x mean of y ## 0.66 2.33 DTU Compute Introduktion til Statistik Efterår 2016 39 / 53

Det parrede setup Undersøgelse af computerspil Undersøgelse om et computerspil er designet så man forbedrer sig når man spiller: Forsøg: Personer spiller samme bane i spillet tre gange i træk Nogle har spillet det før og er derfor erfarne. Alle angiver deres erfaring ved: nybegynder, mellem og øvet Scoren måles for hver person de tre gange de spiller banen Der testes for forskellen mellem nybegyndere og øvede personer: Hvilket setup skal benyttes? A: Parret B: Ikke parret C: Ved ikke Svar) B: Ikke parret Der testes for forskellen i score fra første til tredje gang de spiller banen: Hvilket setup skal benyttes? A: Parret B: Ikke parret C: Ved ikke Svar) A: Parret DTU Compute Introduktion til Statistik Efterår 2016 40 / 53

Det parrede setup Undersøgelse af computerspil Gå ind i første level (POACHED EGGS) og spil BANE 2 tre gange i træk (hvis det er første gang så skal man lige først klare BANE 1). Noter score. Hvis man får 0 point en gang, så er det en ommer Gå ind på game.html (følg link under uge6 på Course material ) og indtast scores Download analysergame.r (følg link under uge6 på Course material ): Kan der påvises en signifikant forskel fra nybegyndere til meget øvede på α = 5% niveau? Kan der påvises en signifikant forbedring mellem første og tredje gang banen spilles på α = 5% niveau? DTU Compute Introduktion til Statistik Efterår 2016 41 / 53

Checking the normality assumptions Eksempel - Q-Q plot inden for hver stikprøve: ## Check af normalitetsantagelsen med QQ-plots par(mfrow=c(1,2)) qqnorm(xa, main="hospital A") qqline(xa) qqnorm(xb, main="hospital B") qqline(xb) Hospital A Hospital B Sample Quantiles 6 7 8 9 10 11 Sample Quantiles 9 10 11 12-1.5-1.0-0.5 0.0 0.5 1.0 1.5-1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles Theoretical Quantiles DTU Compute Introduktion til Statistik Efterår 2016 43 / 53

Checking the normality assumptions -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles Eksempel - Sammenligning med simulerede, A ## Check af normalitetsantagelsen med QQ-plots og Wally-plot ## Brug pakken MESS (install.packages("mess")) library(mess) fit1 <- lm(xa ~ 1) residualer <- resid(fit1) qqwrap <- function(x, y,...) {qqnorm(y, main="",...); abline(a = 0, b = 1)} wallyplot(residualer, FUN = qqwrap) Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 Sample Quantiles -2-1 0 1 2 3 DTU Compute Introduktion til Statistik Efterår 2016 44 / 53

Checking the normality assumptions -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles -1.5-1.0-0.5 0.0 0.5 1.0 1.5 Theoretical Quantiles Eksempel - Sammenligning med simulerede, B ## Check af normalitetsantagelsen med QQ-plots og Wally-plot fit1 <- lm(xb ~ 1) residualer <- resid(fit1) qqwrap <- function(x, y,...) {qqnorm(y, main="",...); abline(a = 0, b = 1)} wallyplot(residualer, FUN = qqwrap) Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 Sample Quantiles -1 0 1 2 DTU Compute Introduktion til Statistik Efterår 2016 45 / 53

Checking the normality assumptions Styrke og stikprøvestørrelse - two-sample Finding the power of detecting a group difference of 2 with σ = 1 for n = 10: ## Power beregning power.t.test(n = 10, delta = 2, sd = 1, sig.level = 0.05) ## ## Two-sample t test power calculation ## ## n = 10 ## delta = 2 ## sd = 1 ## sig.level = 0.05 ## power = 0.99 ## alternative = two.sided ## ## NOTE: n is number in *each* group DTU Compute Introduktion til Statistik Efterår 2016 46 / 53

Checking the normality assumptions Styrke og stikprøvestørrelse - two-sample Finding the sample size for detecting a group difference of 2 with σ = 1 and power= 0.9: ## Beregn stikprøvestørrelsen power.t.test(power = 0.90, delta = 2, sd = 1, sig.level = 0.05) ## ## Two-sample t test power calculation ## ## n = 6.4 ## delta = 2 ## sd = 1 ## sig.level = 0.05 ## power = 0.9 ## alternative = two.sided ## ## NOTE: n is number in *each* group DTU Compute Introduktion til Statistik Efterår 2016 47 / 53

Checking the normality assumptions Styrke og stikprøvestørrelse - two-sample Finding the detectable effect size (delta) with σ = 1, n = 10 and power= 0.9: ## Beregn margin of error power.t.test(power = 0.90, n = 10, sd = 1, sig.level = 0.05) ## ## Two-sample t test power calculation ## ## n = 10 ## delta = 1.5 ## sd = 1 ## sig.level = 0.05 ## power = 0.9 ## alternative = two.sided ## ## NOTE: n is number in *each* group DTU Compute Introduktion til Statistik Efterår 2016 48 / 53

The pooled t-test - a possible alternative Metode 3.64: The pooled two-sample t-test statistic Beregning af den poolede teststørrelse (og 3.63) When considering the null hypothesis about the difference between the means of two independent samples: δ = µ 2 µ 1 the pooled two-sample t-test statistic is H 0 : δ = δ 0 t obs = ( x 1 x 2 ) δ 0 s 2 p/n 1 + s 2 p/n 2 DTU Compute Introduktion til Statistik Efterår 2016 50 / 53

The pooled t-test - a possible alternative Theorem 3.65: Fordelingen af den poolede test-størrelse er en t-fordeling The pooled two-sample statistic seen as a random variable: T = ( X 1 X 2 ) δ 0 (1) S p/n 2 1 + Sp/n 2 2 follows, under the null hypothesis and under the assumption that σ 2 1 = σ 2 2, a t-distribution with n 1 + n 2 2 degrees of freedom if the two population distributions are normal. DTU Compute Introduktion til Statistik Efterår 2016 51 / 53

The pooled t-test - a possible alternative Vi bruger altid Welch versionen Nogenlunde (idiot)sikkert at bruge Welch-versionen altid if s 2 1 = s2 2 the Welch and the Pooled test statistics are the same. Only when the two variances become really different the two test-statistics may differ in any important way, and if this is the case, we would not tend to favour the pooled version, since the assumption of equal variances appears questionable then. Only for cases with a small sample sizes in at least one of the two groups the pooled approach may provide slightly higher power if you believe in the equal variance assumption. And for these cases the Welch approach is then a somewhat cautious approach. DTU Compute Introduktion til Statistik Efterår 2016 52 / 53

Oversigt The pooled t-test - a possible alternative 1 Motiverende eksempel - energiforbrug 2 Hypotesetest (Repetition) 3 Two-sample t-test og p-værdi 4 Konfidensinterval for forskellen 5 Overlappende konfidensintervaller? 6 Det parrede setup 7 Checking the normality assumptions 8 The pooled t-test - a possible alternative DTU Compute Introduktion til Statistik Efterår 2016 53 / 53