572

Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Course 02403: Introduktion til matematisk statistik

Forelæsning 1: Intro, R og beskrivende statistik

Jan Kloppenborg Møller

DTU Compute, Dynamiske SystemerBygning 303B, Rum 007Danmarks Tekniske Universitet2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 1 / 57

Page 2: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 2 / 57

Page 3: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Praktisk Information

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 3 / 57

Page 4: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Praktisk Information

Praktisk Information

Undervisning: Hver dag 08-12

Generel daglig agenda:FØR undervisningsmodulet: læs det annoncerede i eNoten!2x45 minutters forelæsning (dagens pensum)2 timers øvelser: Enote Excersises

Skriftlig eksamen: Sidste dag i 3-ugers (21/6).

OBLIGATORISK projekt: 1 stk - skal

godkendes for at kunne gå til eksamen.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 4 / 57

Page 5: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Praktisk Information

Praktisk Information

Campusnet: https://cn.inside.dtu.dkForelæsningsplanSlidesMeddelelserProjekt - beskrivelse OG aeveringLæsemateriale: eNoter

Ekstra materiale02402.compute.dtu.dk (bliver ikke vedligeholdt under kurset ogafspejler ikke pensum til dette kursus 100%).Læsemateriale: eNoterPodcasts af gl. forelæsninger (02402) (På dansk OG engelsk)Quizzer

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 5 / 57

Page 6: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Praktisk Information

Introduktion til Matematisk Statistik

Forskellen mellem "Introduktion til Matematisk Statistik"(02403) og"Introduktion til Statistik"(02402/02323) er generelt lille, men et parpunkter er at vi:

Gennemgår en (lille) del af det sandsynlighedsteoretiske grundlag forstatistiken.

Gennemføre (små) beviser, baseret på relevante antagelser.

Lægger lidt mindre vægt på konkrete eksempler og fordelinger.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 6 / 57

Page 7: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduction to Statistics - a primer

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 7 / 57

Page 8: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduction to Statistics - a primer

Millennium list (EDITORIAL: Looking Back on theMillennium in Medicine) 1

Elucidation of Human Anatomy and Physiology

Discovery of Cells and Their Substructures

Elucidation of the Chemistry of Life

Application of Statistics to Medicine

Development of Anesthesia

Discovery of the Relation of Microbes to Disease

Elucidation of Inheritance and Genetics

Knowledge of the Immune System

Development of Body Imaging

Discovery of Antimicrobial Agents

Development of Molecular Pharmacotherapy1N Engl J Med, 342:42-49, January 6, 2000.

http://www.nejm.org/doi/full/10.1056/NEJM200001063420108Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 8 / 57

Page 9: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduction to Statistics - a primer

James Lind

"One of the earliest clinical trials took place in 1747, when James Lindtreated 12 scorbutic ship passengers with cider, an elixir of vitriol,vinegar, sea water, oranges and lemons, or an electuary recommendedby the ship's surgeon. The success of the citrus-containing treatmenteventually led the British Admiralty to mandate the provision of limejuice to all sailors, thereby eliminating scurvy from the navy."(See alsohttp://en.wikipedia.org/wiki/James_Lind).

Man kan altså undersøge fænomener man ikke forstår og derefterbegynde at forstå dem!Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 9 / 57

Page 10: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduction to Statistics - a primer

John Snow

"The origin of modern epidemiology is often traced to 1854, whenJohn Snow demonstrated the transmission of cholera fromcontaminated water by analyzing disease rates among citizens servedby the Broad Street Pump in London's Golden Square. He arrestedthe further spread of the disease by removing the pump handle fromthe polluted well."(See alsohttp://en.wikipedia.org/wiki/John_Snow_(physician)).

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 10 / 57

Page 11: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduction to Statistics - a primer

Google - Big Data

A quote from New York Times, 5. August 2009, from the article titled"For Today's Graduate, Just One Word: Statistics is:

"I keep saying that the sexy job in the next 10 years will bestatisticians,"said Hal Varian, chief economist at Google. "And I'mnot kidding.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 11 / 57

Page 12: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduction to Statistics - a primer

IBM - Big Data

"The key is to let computers do what they are good at, which istrawling these massive data sets for something that is mathematicallyodd,"said Daniel Gruhl, an I.B.M. researcher whose recent workincludes mining medical data to improve treatment. "And that makesit easier for humans to do what they are good at - explain thoseanomalies."

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 12 / 57

Page 13: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro Case stories

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 13 / 57

Page 14: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro Case stories

Intro Case stories

Senior Scientist Hanne Refsgaard, Novo

Nordisk A/S

IBM Social media by Henrik H. Eliasen, IBM

Skive Fjord podcasts by Jan K. Møller, DTU

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 14 / 57

Page 15: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 15 / 57

Page 16: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Introduktion til Statistik

Hvordan behandles (eller analyseres) data?

Hvad er tilfældig variation?

Statistik er et værktøj til at træe beslutninger:Hvor mange computere har vi solgt det sidste år?Styring af energisystemer med uktuerende vedvarende energi?Er maskine A mere eektiv end maskine B ?

Statistik er et metodefag, der kan anvendes inden for deeste fagområder, og er derfor et meget vigtigt værktøj

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 16 / 57

Page 17: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Statistik og Ingeniører

Statistik er et vigtigt værktøj i problemløsning

Analyse af data

Kvalitetforbedring

Forsøgsplanlægning

Forudsigelse af fremtidige værdier

.. og meget mere!

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 17 / 57

Page 18: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Statistik

Moderne statistik har baggrund i sandsynlighedsregningog beskrivende statistik

Statistik handler ofte om at analysere en stikprøve

(sample), der er taget fra en population (population)

Baseret på stikprøven, vil vi generalisere (eller udtaleos) om populationen

Det er derfor vigtigt, at stikprøven er repræsentativ forpopulationen

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 18 / 57

Page 19: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Statistik

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 19 / 57

Page 20: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Statistical software

Der eksisterer en række forskellige statistiske softwareprogrammer, i dette kursus bruger vi R:

Open source (www.r-project.org)

Stort antal bidrag ydere (så det vokser hurtigt)

Skal bruge et interface, vi bruger R-studio (www.rstudio.com), også opensource. Der er andre muligheder, eksempelvis Emacs Speak Statistics.

I skal instalere R og jeg vil anbefale at i instalere R-studio

Vi bruger R gennem kurset og i SKAL lave projektet i R.

Et statistisk software program er en uundværlig det af statistisk analyse,MEN vi er nødt til at tænke over hvad vi putter in i R, dvs. brug blyant ogpapir (og hovedet).

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 20 / 57

Page 21: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til Statistik

Eksempel 1

Udtag stikprøve til brug for udregning af nøgletal....

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 21 / 57

Page 22: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beskrivende statistik: Nøgletal

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 22 / 57

Page 23: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beskrivende statistik: Nøgletal

Nøgletal (summary statistics)

Vi anvender en række nøgletal (eller statistikker) for at opsummere ogbeskrive data (og stokastiske variable)

Gennemsnit: tyngdepunkt eller centrering

Median: tyngdepunkt eller centrering

Varians: variation

Spredning: variation (samme enhed som data)

Variations koecient: variationen i data (enhedsløs)

Kovarians: samvariation mellem værdier

Korrelation: samvariation mellem værdier (enhedsløs)

Fraktiler: siger noget om fordelingen af data

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 23 / 57

Page 24: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beskrivende statistik: Nøgletal

Nøgletal (summary statistics)

Lad x1, ..., xn og y1, ..., yn være stikprøver

Denition RGennemsnit: x 1

n

∑ni=1 xi mean(x)

Varians: s2 1n−1

∑ni=1(xi − x)2 var(x)

Spredning: s√s2 sd(x)

Kovarians: sxy1

n−1

∑ni=1 (xi − x) (yi − y) cov(x,y)

Korrelation: rsxysx·sy cor(x,y)

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 24 / 57

Page 25: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beskrivende statistik: Nøgletal

Nøgletal (summary statistics)

Lad x(1) ≤ x(2) ≤ ... ≤ x(n) betegne den sorterede rækkefølge af x1, ..., xn.

Denition RVarianskoecient: V s

x · 100

Fraktiler: τp(x(np)+x(np+1))

2 , np = dnpe quantile(x,...)1

x(dnpe), np 6= dnpeFørste kvartil Q1 τ0.25

Median x τ0.50 median(x)

Tredie kvartil Q3 τ0.75

1brug quantile(x, probs = p, type = 2) for denitionen ovenfor

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 25 / 57

Page 26: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 26 / 57

Page 27: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Grask Fremstilling

Histogram

Empirisk kumulativ tæthedsfunktion

Boxplot

Scatterplot

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 27 / 57

Page 28: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Eksempel: Skive fjord

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 28 / 57

Page 29: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Eksempel: Skive fjord, data

Data sættet indeholder en række månedlige gennemssnits observationer offorskellige variable, idag ser vi på

chla der er er en måling af klorofyll i vandet, dvs. der er en indikatorfor mængden af alger i vandet.

temp temperaturen i vandet

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 29 / 57

Page 30: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Eksempel: nogle nøgletal

> ## read data

> skiveAvg <- read.table("skiveAvg.csv", sep = ";", header = TRUE)

>

> ## number of observations

> dim(skiveAvg)

## [1] 300 17

> ## Some key numbers

> summary(skiveAvg[ ,c("year","month","chla","temp")])

## year month chla temp

## Min. :1982 Min. : 1.00 Min. :0.00050 Min. :-0.74

## 1st Qu.:1988 1st Qu.: 3.75 1st Qu.:0.00356 1st Qu.: 3.75

## Median :1994 Median : 6.50 Median :0.00792 Median : 8.36

## Mean :1994 Mean : 6.50 Mean :0.01205 Mean : 9.53

## 3rd Qu.:2000 3rd Qu.: 9.25 3rd Qu.:0.01524 3rd Qu.:15.42

## Max. :2006 Max. :12.00 Max. :0.12092 Max. :21.77

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 30 / 57

Page 31: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Histogram

> ## Data from Skive fjord

> skiveAvg <- read.table("skiveAvg.csv", sep = ";", header = TRUE)

> y <- log(skiveAvg$chla)

> hist(skiveAvg$chla); hist(y)

Histogram of skiveAvg$chla

skiveAvg$chla

Fre

quen

cy

0.00 0.02 0.04 0.06 0.08 0.10 0.12

050

100

150

Histogram of y

y

Fre

quen

cy

−8 −7 −6 −5 −4 −3 −2

010

2030

4050

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 31 / 57

Page 32: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Empirisk fordelingsfunktion

> plot(ecdf(y))

−8 −7 −6 −5 −4 −3 −2

0.0

0.2

0.4

0.6

0.8

1.0

ecdf(y)

x

Fn(

x)

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 32 / 57

Page 33: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Empirisk fordelingsfunktion

ecdf(y)

y

Fn(

x)

min Q1 Q2 Q3 max

0.00

0.25

0.50

0.75

1.00

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 33 / 57

Page 34: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Boxplot

> par(mfrow=c(1,2),cex.main=2,cex.lab=2,cex.axis=1.5)

> boxplot(skiveAvg[ ,"chla"])

> boxplot(y)

0.00

0.02

0.04

0.06

0.08

0.10

0.12

−7

−6

−5

−4

−3

−2

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 34 / 57

Page 35: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Empirisk fordelingsfunktion

ecdf(y)

y

Fn(

x)

τ0.025 y τ0.975

0.02

50.

500

0.97

5

yy+/−2sd(x)

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 35 / 57

Page 36: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Scatterplot

> plot(log(chla) ~ temp, data = skiveAvg)

0 5 10 15 20

−7

−6

−5

−4

−3

−2

temp

log(

chla

)

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 36 / 57

Page 37: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Scatterplot

0 5 10 15 20

−7

−6

−5

−4

−3

−2

r = 0.58

temp

log(

chla

)xi < xyi > y(xi − x)(yi − y)<0

xi < xyi < y(xi − x)(yi − y)>0

xi > xyi < y(xi − x)(yi − y)<0

xi > xyi > y(xi − x)(yi − y)>0

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 37 / 57

Page 38: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Korrelation (igen) - egenskaber

r is always between −1 and 1: −1 ≤ r ≤ 1

r measures the degree of linear relation between x and y

r = ±1 if and only if all points in the scatterplot are exactly on a line

r > 0 if and only if the general trend in the scatterplot is positive

r < 0 if and only if the general trend in the scatterplot is negative

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 38 / 57

Page 39: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Grask Fremstilling

Korrelation

0.0 0.2 0.4 0.6 0.8 1.0

0.0

0.4

0.8

1.2

r ≈ 0.95

x

y

0.0 0.2 0.4 0.6 0.8 1.0

−2

−1

01

r ≈ − 0.5

x

y

0.0 0.2 0.4 0.6 0.8 1.0

−3

−2

−1

01

2

r ≈ 0

x

y

0.0 0.2 0.4 0.6 0.8 1.0

0.0

0.4

0.8

r ≈ 0

x

y

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 39 / 57

Page 40: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 40 / 57

Page 41: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Stokastiske variable

En stokastisk variabel (random variable) repræsenterer udfaldet af eteksperiment der endnu ikke er udført

Et terningekast

Antallet af seksere i 10 terningekast

km/l for en bil

Måling af sukkerniveau i blodprøve

...

eller med andre en beskrivelse af hvordan data realiseres.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 41 / 57

Page 42: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Diskret eller kontinuert

Vi skelner mellem diskret og kontinuert

Diskret kan tælles:

Hvor mange der bruger briller herindeAntal mange yvere letter den næste time

Kontinuert:

VindmålingTiden det tog at komme til DTU

I dag er det primært diskrete stokastiske variable i morgen er detkontinuerte.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 42 / 57

Page 43: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Stokastisk variabel

Før eksperimentet er udført stokastisk variabel haves

Xi

noteret med stort bogstav.Så udføres eksperimentet, og vi har da en realisation eller observation

xi

noteret med småt bogstav.Formelt er Xi en funktion, mens xi er et tal.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 43 / 57

Page 44: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Simuler et terningekast

Vælg et tal fra (1, 2, 3, 4, 5, 6) med lige sandsynlighed for hvert udfald

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 44 / 57

Page 45: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Diskrete fordelinger

For diskrete fordelinger (dvs. tælleligt udfaldrum), altså X kan antageværdierne 0, 1, 2, ...

Kan naturligvis også være endeligt dvs. X kan antage værdierne0, 1, 2, ..., N

I alle tilfælde skal vi beskrive alle mulige udfald ved en model.

I denne sammenhæng er en model en beskrivelse af sandsynlighedenfor hvert enkelt (mulige) udfald.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 45 / 57

Page 46: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable Tæthedsfunktionen (Diskrete fordelinger)

Tæthedsfunktion (Diskrete fordelinger)

En stokastisk variabel har en tæthedsfunktion (probability density function(pdf))

Denition

f(x) = P (X = x)

Sandsynligheden for at X bliver udfaldet x når eksperimentet udføres.Der gælder at:

f(x) ≥ 0 for all x∑x

f(x) = 1

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 46 / 57

Page 47: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable Tæthedsfunktionen (Diskrete fordelinger)

Tæthedsfunktion

En fair ternings tæthedsfunktion

0.0

0.2

0.4

0.6

0.8

1.0

x

Den

sity

1 2 3 4 5 6

Empirical pdfpdf

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 47 / 57

Page 48: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable Tæthedsfunktionen (Diskrete fordelinger)

Stikprøve

Hvis vi har n observationer, så har vi en stikprøve (a sample)

x1, x2, ..., xn

og da kan vi begynde at se fordelingen. Jo størrere n jo mere information.

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 48 / 57

Page 49: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 49 / 57

Page 50: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Middelværdi (mean) og forventningsværdi (expectation)

Stokastisk variabels middelværdi

µ = E(X) =∑alle x

xf(x)

Det rigtige gennemsnit

Fortæller hvor midten af X er

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 50 / 57

Page 51: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Middelværdi eksempel

Middelværdi af en terning

µ = E(X) = 1 · 16+ 2 · 1

6+ 3 · 1

6+ 4 · 1

6+ 5 · 1

6+ 6 · 1

6= 3.5

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 51 / 57

Page 52: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Jo ere observationer, jo tættere kommer man på den rigtige middelværdi2

limn→∞

µ = µ

hvor µ er det observerede gennemsnit

Prøv det i R

2Givet at µ eksistereJan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 52 / 57

Page 53: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Varians

Denition

σ2 = Var(X) =∑alle x

(x− µ)2f(x)

Et mål for spredningen

Den rigtige spredning af X (modsat empirisk varians (samplevariance))

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 53 / 57

Page 54: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Varians eksempel

Varians af terningekast

σ2 = E[(X − µ)2] = (1− 3.5)2 · 1

6+ (2− 3.5)2 · 1

6+ (3− 3.5)2 · 1

6

+ (4− 3.5)2 · 1

6+ (5− 3.5)2 · 1

6+ (6− 3.5)2 · 1

6≈ 2.92

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 54 / 57

Page 55: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians

Nøgletal

Empirisk Diskret stokastisk variableMiddelværdi x =

∑xi

1n µ =

∑xif(xi)

Varians s2 =∑

(xi − x)2 1n−1 σ2 =

∑(xi − µ)2f(xi)

Kovarians 1n−1

∑ni=1 (xi − x) (yi − y)

Median x(dn/2e)1 F−1(0.5) 2

Fraktil Qτ1 F−1(τ)

1se slide 25 for præcis denition2Mere præcist: x s.t. P (X ≤ x) ≥ 0.5 og P (X ≥ x) ≥ 0.5

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 55 / 57

Page 56: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians I morgen

I morgen:

Stokastiske variable, Sandsynligheder, diskrete ogkuntinuerte fordelinger fordelinger - kapitel 2 i eNoten

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 56 / 57

Page 57: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Middelværdi og varians I morgen

Oversigt

1 Praktisk Information

2 Introduction to Statistics - a primer

3 Intro Case stories

4 Introduktion til Statistik

5 Beskrivende statistik: Nøgletal

6 Grask Fremstilling

7 Stokastiske variableTæthedsfunktionen (Diskrete fordelinger)

8 Middelværdi og varians

Jan K. Møller ([email protected]) Introduktion til Matematisk Statistik Juni 2018 57 / 57

Page 58: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Course 02403 Introduktion til Matamatisk Statistik

Forelæsning 2: Stokastiske variabel og fordelinger

Jan Kloppenborg Møller

DTU Compute, Dynamiske Systemer

Bygning 305, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 1 / 51

Page 59: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Stokastiske variable

2 Konkrete Statistiske fordelinger

3 Kontinuerte Stokastiske variable og fordelinger

4 Konkrete Kontinuerte fordelinger

5 Kontinuerte og diskrete fordelinger

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 2 / 51

Page 60: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Oversigt

1 Stokastiske variableTæthedsfunktionFordelingsfunktion

2 Konkrete Statistiske fordelinger

3 Kontinuerte Stokastiske variable og fordelinger

4 Konkrete Kontinuerte fordelinger

5 Kontinuerte og diskrete fordelinger

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 3 / 51

Page 61: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable

Stokastisk variabel

Før eksperimentet er udført stokastisk variabel haves

Xi

noteret med stort bogstav.Så udføres eksperimentet, og vi har da en realisation eller observation

xi

noteret med småt bogstav.

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 4 / 51

Page 62: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable Tæthedsfunktion

Tæthedsfunktion

En stokastisk variabel har en tæthedsfunktion (probability density function(pdf))

Denition

f(x) = P (X = x)

Sandsynligheden for at X bliver udfaldet x når eksperimentet udføres.Der gælder at:

f(x) ≥ 0 for all x∑x

f(x) = 1

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 5 / 51

Page 63: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable Fordelingsfunktion

Fordelingsfunktion (distribution function eller cumulativedensity function (cdf))

Denition

Fordelingsfunktionen (cdf) er tæthedsfunktionen akkumuleret

F (x) = P (X ≤ x) =∑

j hvor xj≤xf(xj)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 6 / 51

Page 64: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Stokastiske variable Fordelingsfunktion

Fair terning eksempel

Lad X repræsentere et kast med en fair terningUdregn sandsynligheden for at få udfald under 3:

P (X < 3) = P (X ≤ 2)

= F (2) fordelingsfunktionen

= P (X = 1) + P (X = 2)

= f(1) + f(2) tæthedsfunktioner

=1

6+

1

6=

1

3

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 7 / 51

Page 65: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger

Oversigt

1 Stokastiske variable

2 Konkrete Statistiske fordelingerBinomial fordelingenHypergeometrisk fordelingPoissonfordelingenMiddelværdi og varians

3 Kontinuerte Stokastiske variable og fordelinger

4 Konkrete Kontinuerte fordelinger

5 Kontinuerte og diskrete fordelinger

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 8 / 51

Page 66: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger

Konkrete Statistiske fordelinger

Der ndes en række statistiske fordelinger, som kan bruges til atbeskrive og analysere forskellige problemstillinger med

Vi starter med diskrete fordelinger:

Binomial fordelingen

Den hypergeometriske fordeling

Poisson fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 9 / 51

Page 67: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Binomial fordelingen

Binomial fordelingen

Et eksperiment med to udfald (succes eller ikke-succes) gentages

X er antal succeser efter n gentagelser

Så følger X en binomial fordelingen

X ∼ B(n, p)

Binomial fordelingens tæthedsfunktion giver sandsynligheden for xantal succeser

f(x;n, p) = P (X = x) =

(n

x

)px(1− p)n−x

n antal gentagelser

p sandsynligheden for succes i hver gentagelse

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 10 / 51

Page 68: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Binomial fordelingen

Binomial fordelingen: Eksempel

Hvad er sandsynligheden for at slå 2 seksere i 4 slag med en ærlig terning?

6 * (1 / 6)^2 * (5 / 6)^2

[1] 0.11574

dbinom(2,4,1/6)

[1] 0.11574

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 11 / 51

Page 69: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Binomial fordelingen

Binomial fordelingen: Eksempel

Hvad er sandsynligheden for at slå 2 seksere i 4 slag med en ærlig terning?

6 * (1 / 6)^2 * (5 / 6)^2

[1] 0.11574

dbinom(2,4,1/6)

[1] 0.11574

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 11 / 51

Page 70: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Hypergeometrisk fordeling

Hypergeometrisk fordeling

X er igen antal succeser, men nu er det uden tilbgelægning ved

gentagelsen

X følger da den hypergeometriske fordeling

X ∼ H(n, a,N)

Sandsynligheden for at få x succeser er

f(x;n, a,N) = P (X = x) =

(ax

)(N−an−x

)(Nn

)hvor

n er antallet af trækninger

a er antallet af succeser i populationen

N elementer i population

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 12 / 51

Page 71: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Hypergeometrisk fordeling

Hypergeometrisk fordelingen: Eksempel

En skål indeholder 10 sorte og 2 hvide kugler, hvis der trækkes 4 kuglerhvad er da sandsylingheden for at 2 er hvide?

choose(2,2) * choose(10,2) / choose(12,4)

[1] 0.090909

dhyper(2,2,10,4)

[1] 0.090909

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 13 / 51

Page 72: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Poissonfordelingen

Poissonfordelingen

Poisson fordelingen anvendes ofte som en fordeling (model) fortælletal, hvor der ikke er nogen naturlig øvre grænse

Poisson fordelingen karakteriseres ved en intensitet, dvs. på formenantal/enhed

Parameteren λ angiver intensiteten

Typisk hændelser per tidsinterval

Intervallerne mellem hændelserne er uafhængige, dvs. processen erhukommelsesløs

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 14 / 51

Page 73: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Poissonfordelingen

Poissonfordelingen

X følger Poisson fordelingen

X ∼ P (λ)

Tæthedsfunktion:f(x) = P (X = x) = λx

x! e−λ

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 15 / 51

Page 74: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Poissonfordelingen

Eksempel

Det antages, at der i gennemsnit bliver indlagt 0.3 patienter pr. dag påkøbenhavnske hospitaler som følge af luftforurening.

Hvad er sandsynligheden for at der på en vilkårlig dag bliver indlagt højst 2

patienter som følge af luftforurening?

Step 1) Hvad skal repræsenteres: X er antal patienter pr. dag

Step 2) Hvilken fordeling: X følger Poisson fordelingen

Step 3) Hvilken sandsynlighed:P (X ≤ 2)

Step 4) Hvad er raten: λ = 0.3 patienter per dag

ppois(2,lambda=0.3)

[1] 0.9964

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 16 / 51

Page 75: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Poissonfordelingen

Binomial, hypergeometrisk, eller Poisson

Binomial fordelingen anvendes også for at analysere stikprøvermed tilbagelægning (Tænk på en terningekast)

Når man vil analysere stikprøver uden tilbagelægning anvendes denhypergeometriske fordeling (Tænk på træk fra en hat).

Poisson anvendes når der ikke er et naturligt loft over antalobservationer.

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 17 / 51

Page 76: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Fordelinger i R

R og diskrete fordelinger

R Betegnelse

binom Binomialhyper hypergeometriskpois Poisson

d Tæthedsfunktion f(x) (probability density function).

p Fordelingsfunktion F (x) (cumulative distribution function).

r Tilfældige tal fra den anførte fordeling. (Forelæsning 10)

q Fraktil (quantile) i fordeling.

Husk at hjælp til funktion mm. fåes ved at sætte '?' foran navnet.

Eksempel binomial fordelt: P (X ≤ 5) = F (5; 10, 0.6)

pbinom(q=5, size=10, prob=0.6)

## Få hjælpen med

?pbinom

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 18 / 51

Page 77: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Middelværdi og varians

Middelværdi (mean) og forventningsværdi (expectation)

Stokastisk variabels middelværdi

µ = E(X) =∑alle x

xf(x)

Det rigtige gennemsnit

Fortæller hvor midten af X er

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 19 / 51

Page 78: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Middelværdi og varians

Varians

Denition

σ2 = Var(X) =∑alle x

(x− µ)2f(x)

Et mål for spredningen

Den rigtige spredning af X (modsat empirisk varians (samplevariance))

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 20 / 51

Page 79: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Statistiske fordelinger Middelværdi og varians

Diskrete fordelinger: oversigt

Fordeling Ω pdf µ σ2

Generel f(x)∑xif(xi)

∑(µ− xi)2f(xi)

Binomial 0, . . . , n(nx

)px(1− p)n−x np np(1− p)

Hypergeo. max(0, n + a−N),(ax)(

N−an−x)

(Nn)naN n a

N(N−a)N

N−nN−1

...,min(n, a)

Poisson 0, 1, . . . λx

x! e−λ λ λ

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 21 / 51

Page 80: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger

Oversigt

1 Stokastiske variable

2 Konkrete Statistiske fordelinger

3 Kontinuerte Stokastiske variable og fordelingerTæthedsfunktionFordelingsfunktionMiddelværdi af en kontinuert stokastisk variabel

4 Konkrete Kontinuerte fordelinger

5 Kontinuerte og diskrete fordelinger

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 22 / 51

Page 81: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Tæthedsfunktion

Tæthedsfunktion (probability density function (pdf))

Tæthedsfunktionen for en stokastisk variabel betegnes ved f(x)

f(x) siger noget om hyppigheden af udfaldet x for den stokastiskevariabel X

For kontinuerte variable svarer tætheden ikke til sandsynligheden, dvs.f(x) 6= P (X = x)

Et godt plot af f(x) er et histogram (kontinuert)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 23 / 51

Page 82: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Tæthedsfunktion

Tæthedsfunktion for en kontinuert variabel

For en kontinuert stokastisk variabel skrives tæthedsfunktionen som:

f(x)

Der gælder:

f(x) ≥ 0 for alle mulige x

∫ ∞−∞

f(x)dx = 1

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 24 / 51

Page 83: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Fordelingsfunktion

Fordelingsfunktion (distribution function ellercumulative density function (cdf))

Fordelingsfunktion for en kontinuert stokastisk variabel betegnes vedF (x).Fordelingsfunktionen svarer til den kumulerede tæthedsfunktion:

F (x) = P (X ≤ x)

F (x) =

∫ x

−∞f(u)du

f(x) = F′(x)

Et godt plot for fordelingsfunktionen er den kumulative fordeling

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 25 / 51

Page 84: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Middelværdi af en kontinuert stokastisk variabel

Middelværdi (mean) og varians af en kontinuert stokastiskvariabel

Middelværdien af en kontinuert stokastisk variabel

µ =

∫ ∞−∞

x · f(x)dx

Variansen af en kontinuert stokastisk variabel:

σ2 =

∫ ∞−∞

(x− µ)2 · f(x)dx

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 26 / 51

Page 85: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger

Oversigt

1 Stokastiske variable

2 Konkrete Statistiske fordelinger

3 Kontinuerte Stokastiske variable og fordelinger

4 Konkrete Kontinuerte fordelingerUniform fordelingenEksponential fordelingenNormalfordelingenLog-Normal fordelingenKontinuerte fordelinger i RKontinuerte fordelinger: oversigt

5 Kontinuerte og diskrete fordelingerJan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 27 / 51

Page 86: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger

Konkrete statistiske fordelinger

Der ndes en række statistiske fordelinger, som kan bruges til atbeskrive og analysere forskellige problemstillinger med

Vi betragter nu kontinuerte fordelinger

Uniform fordelingen

Normal fordelingen

Log-Normal fordelingen

Eksponential fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 28 / 51

Page 87: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Uniform fordelingen

Uniform fordelingen

Skrivemåde:

X ∼ U(α, β)

Tæthedsfunktion:

f(x) = 1β−α ; x ∈ [α, β]

Middelværdi:

µ = α+β2

Varians:

σ2 = 112(β − α)

2

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 29 / 51

Page 88: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Uniform fordelingen

Uniform fordelingen

α β

01

(α+

β)1

pdfCDF

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 30 / 51

Page 89: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Eksponential fordelingen

Eksponentialfordelingen

Eksponential fordelingen er et special tilfælde af Gamma fordelingen

Eksponential fordelingen anvendes f.eks. til at beskrive levetider ogventetider

Eksponential fordelingen kan bruges til at beskrive (vente)tidenmellem hændelser i poisson fordelingen

Tæthedsfunktion

f(x) =

λe−λx x > 0, λ > 00 ellers

Middelværdi µ = 1λ

Varians σ2 = 1λ2

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 31 / 51

Page 90: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Eksponential fordelingen

Sammenhæng mellem Eksponential og Poisson fordelingen

tid t

∗ ∗ ∗ ∗ ∗ ∗ ∗

t1 t2

Poisson: Diskrete hændelser pr. enhed

Eksponential: Kontinuert afstand mellem hændelser

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 32 / 51

Page 91: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Eksponential fordelingen

Eksponential fordelingen

−1 0 1 2 3 4 5 6 7 8 9 100

0.2

0.4

0.6

0.8

1

EXP(1)

x

Tae

thed

, f(x

)

Eksponential fordeling med β=1

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 33 / 51

Page 92: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Eksponential fordelingen

Eksempel

Kø-model - poisson proces

Tiden mellem kundeankomster på et posthus er eksponential fordelt medmiddelværdi µ = 2 minutter.

Spørgsmål:

En kunde er netop ankommet. Hvad er sandsynligheden for at der ikke

kommer ere kunder indefor en periode på 2 minutter?

1-pexp(2,rate=1/2)

[1] 0.36788

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 34 / 51

Page 93: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Normal fordelingen

Skrivemåde:

X ∼ N(µ, σ2)

Tæthedsfunktion:

f(x) = 1σ√

2πe−

(x−µ)2

2σ2

Middelværdi:µ = µ

Varians:

σ2 = σ2

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 35 / 51

Page 94: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Normalfordelingen

−5 −4 −3 −2 −1 0 1 2 3 4 5−0.05

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

−2σ −σ µ−3σ 3σ2σσ

x

Tae

thed

, f(x

)

Normalfordeling N(0,12)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 36 / 51

Page 95: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Normalfordelingen

−5 0 5 10−0.05

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45N(0,12) N(5,12)

Sammenligning af to normalfordelinger med forskellig middelvardi og ens varians

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 37 / 51

Page 96: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Normalfordelingen

−10 −8 −6 −4 −2 0 2 4 6 8 10

0

0.1

0.2

0.3

0.4

0.5

Sammenligning af tre normalfordelinger med ens middelvardi og forskellig varians

x

Tae

thed

, f(x

)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 38 / 51

Page 97: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Normal fordelingen

En standard normal fordeling:

Z ∼ N(0, 12)

En normalfordeling med middelværdi 0 og varians 1.

Standardisering:

En vilkårlig normal fordelt variabel X ∼ N(µ, σ2) kan standardiseres ved atberegne

Z =X − µσ

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 39 / 51

Page 98: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Eksempel

Målefejl:

En vægt har en målefejl, Z, der kan beskrives ved en standardnormalfordeling, dvs

Z ∼ N(0, 12)

dvs. middelværdi µ = 0 og spredning σ = 1 gram.Vi måler nu vægten af ét emne

Spørgsmål a):

Hvad er sandsynligheden for at vægten måler mindst 2 gram for lidt?

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 40 / 51

Page 99: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Normalfordelingen

Eksempel

Spørgsmål b):

Hvad er sandsynligheden for at vægten måler mindst 2 gram for meget?

Spørgsmål c):

Find d så P (−d < Z < d) = 0.95

Spørgsmål d):

Hvis X ∼ N(µ, σ2), nd d så P (µ− d < X < µ+ d) = 0.95

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 41 / 51

Page 100: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Log-Normal fordelingen

Log-Normal fordelingen

Lad X ∼ N(α, β2) så følger Y = eX en log-normal fordeling

Skrivemåde:

Y ∼ LN(α, β2)

Tæthedsfunktion:

f(x) =

1

xβ√2πe−(ln(x)−α)

2/2β2x > 0, β > 0

0 ellers

Middelværdi:

µ = eα+β2/2

Varians:

σ2 = e2α+β2(eβ

2 − 1)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 42 / 51

Page 101: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Log-Normal fordelingen

Log-Normal fordelingen

0 5 10 15 20 25 300

0.05

0.1

0.15

0.2

0.25

LN(1,1)

x

Tae

thed

, f(x

)

Log−Normalfordeling LN(1,1)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 43 / 51

Page 102: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Log-Normal fordelingen

Log-Normal fordelingen

Lognormal og Normalfordelingen:

En log-normal fordelt variabel Y ∼ LN(α, β2), kan transformeres til enstandard normal fordelt variabel X ved

X =ln(Y )− α

β

dvs.X ∼ N(0, 12)

Ved antagelse om log-normalfordelte data foretages analysen sædvanligvispå log-transformerede data.

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 44 / 51

Page 103: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Kontinuerte fordelinger i R

Kontinuerte fordelinger i R

Sammelign klorofyll data fra Skive fjord med en relevant fordelinger.Sammelign log-klorofyll data fra Skive fjord med en relevant fordelinger.

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 45 / 51

Page 104: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Kontinuerte fordelinger i R

Kontinuerte fordelinger i R

R Betegnelse

norm Normalfordelingenunif Den uniforme fordelinglnorm Log-normalfordelingenexp Exponentialfordelingen

d Tæthedsfunktion f(x) (probability density function).

p Fordelingsfunktion F (x) (cumulative distribution function).

q Fraktil (quantile) i fordeling.

r Tilfældige tal fra fordelingen.

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 46 / 51

Page 105: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Konkrete Kontinuerte fordelinger Kontinuerte fordelinger: oversigt

Kontinuerte fordelinger: oversigt

Fordeling Ω pdf µ σ2

Generel f(x)∫xf(x)dx

∫(µ− x)2f(x)dx

Uniform [α, β] 1β−α

α+β2

(β−α)212

Exponential [0,∞) λe−λx 1λ

1λ2

Normal R 1σ√2πe−

(x−µ)2

2σ2 µ σ2

log-Normal (0,∞) 1xβ√2πe−(ln(x)−α)

2/2β2

eα+β2/2 µ2(eβ

2 − 1)

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 47 / 51

Page 106: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte og diskrete fordelinger

Oversigt

1 Stokastiske variable

2 Konkrete Statistiske fordelinger

3 Kontinuerte Stokastiske variable og fordelinger

4 Konkrete Kontinuerte fordelinger

5 Kontinuerte og diskrete fordelinger

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 48 / 51

Page 107: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte og diskrete fordelinger

Kontinuerte og diskrete fordelinger: some facts

Diskret Kontinuert

f(x) = P (X = x) f(x) 6= P (X = x) = 0

F (x) =∑x−∞ f(x) F (x) =

∫ x−∞ f(x)dx

P (X ≤ x) 6= P (X < x) P (X ≤ x) = P (X < x)

P (x1 < X ≤ x2) =∑x2

x1+1 f(x) P (x1 < X ≤ x2) =∫ x2

x1f(x)dx

P (x1 < X ≤ x2) = F (x2)− F (x1) P (x1 < X ≤ x2) = F (x2)− F (x1)

E[X] =∑∞−∞ xf(x) E[X] =

∫∞−∞ xf(x)

V [X] =∑∞−∞(E[X]− x)2f(x) V [X] =

∫∞−∞(E[X]− x)2f(x)dx

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 49 / 51

Page 108: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte og diskrete fordelinger

Oversigt

1 Stokastiske variable

2 Konkrete Statistiske fordelinger

3 Kontinuerte Stokastiske variable og fordelinger

4 Konkrete Kontinuerte fordelinger

5 Kontinuerte og diskrete fordelinger

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 50 / 51

Page 109: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte og diskrete fordelinger

På tirsdag

På tirsdag fortsætter vi med kapitel 2, samt første del af kapitel 4

Regneregler for middelværdi og varians

Simulation som generelt værktøj

Kovarians og uafhængighed

Jan K. Møller ([email protected]) 02403, Forelæsning 2 Juni 2018 51 / 51

Page 110: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Course 02403 Introduktion til Matematisk Statistik

Forelæsning 3: Regneregler, uafhængighed og simulation

Jan Kloppenborg Møller

DTU Compute, Dynamiske SystemerBygning 303B, Rum 007Danmarks Tekniske Universitet2800 Lyngby Danmark

e-mail: [email protected]

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 1 / 46

Page 111: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

Tæthedsfunktion

Middelværdi af en kontinuert stokastisk variabel

2 Normalfordelingen

Kontinuerte fordelinger i R

3 Regneregler for stokastiske variable

4 Simulation

Hvad er simulering egentlig?

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 2 / 46

Page 112: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

Tæthedsfunktion

Middelværdi af en kontinuert stokastisk variabel

2 Normalfordelingen

3 Regneregler for stokastiske variable

4 Simulation

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 3 / 46

Page 113: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Tæthedsfunktion

Tæthedsfunktion (probability density function (pdf))

Tæthedsfunktionen for en stokastisk variabel betegnes ved f (x)

f (x) siger noget om hyppigheden af udfaldet x for den stokastiskevariabel X.

Der gælder:

f (x)≥ 0 for alle mulige x

∫∞

−∞

f (x)dx = 1

Fordelingsfunktionen svarer til den kumulerede tæthedsfunktion:

F(x) = P(X ≤ x) =∫ x

−∞

f (u)du

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 4 / 46

Page 114: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Tæthedsfunktion

Tæthedsfunktion for en kontinuert variabel

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

x

f(x)

P(a < X ≤ b)

a b -4 -2 0 2 4

0.0

0.2

0.4

0.6

0.8

1.0

xF(x)

P(a

<X≤

b)=

F(b)−

F(a)

a b

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 5 / 46

Page 115: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kontinuerte Stokastiske variable og fordelinger Middelværdi af en kontinuert stokastisk variabel

Middelværdi (mean) af en kontinuert stokastisk variabel

Middelværdien af en kontinuert stokastisk variabel

µ =∫

−∞

x · f (x)dx

Variansen af en kontinuert stokastisk variabel:

σ2 =

∫∞

−∞

(x−µ)2 · f (x)dx

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 6 / 46

Page 116: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

2 Normalfordelingen

Kontinuerte fordelinger i R

3 Regneregler for stokastiske variable

4 Simulation

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 7 / 46

Page 117: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen

Konkrete statistiske fordelinger

Der ndes en række statistiske fordelinger, som kan bruges til atbeskrive og analysere forskellige problemstillinger med

Vi har set en række kontinuerte fordelinger

Uniform fordelingen

Eksponential fordelingen

Normal fordelingen

Log-Normal fordelingen

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 8 / 46

Page 118: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen

Normalfordelingen

−5 −4 −3 −2 −1 0 1 2 3 4 50

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5Normalfordeling

x

Tae

thed

, f(x

)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 9 / 46

Page 119: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen

Normal fordelingen

Skrivemåde:

X ∼ N(µ,σ2)

Tæthedsfunktion:

f (x) = 1σ√

2πe−

(x−µ)2

2σ2

Middelværdi:µ = µ

Varians:

σ2 = σ2

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 10 / 46

Page 120: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen

Normal fordelingen

En standard normal fordeling:

Z ∼ N(0,12)

En normalfordeling med middelværdi 0 og varians 1.

Standardisering:

En vilkårlig normal fordelt variabel X ∼ N(µ,σ2) kan standardiseres ved atberegne

Z =X−µ

σ

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 11 / 46

Page 121: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen

Linear kombination af Normale Stokastiske variable

Hvis Xi ∼ N(µi,σ2i ), (i = 1, . . . ,n) er uafhængige stokastiske variable så er

Y = a0 +a1X1 + · · ·+anXn

også normal fordelt.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 12 / 46

Page 122: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normalfordelingen Kontinuerte fordelinger i R

Kontinuerte fordelinger i R

R Betegnelsenorm Normalfordelingenunif Den uniforme fordelinglnorm Log-normalfordelingenexp Exponentialfordelingen

d Tæthedsfunktion f (x) (probability density function).

p Fordelingsfunktion F(x) (cumulative distribution function).

q Fraktil (quantile) i fordeling.r Tilfældige tal fra fordelingen.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 13 / 46

Page 123: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Regneregler for stokastiske variable

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

2 Normalfordelingen

3 Regneregler for stokastiske variable

4 Simulation

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 14 / 46

Page 124: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Regneregler for stokastiske variable

Regneregler for stokastiske variable

(Gælder BÅDE kontinuert og diskret)

X er en stokastisk variabel.

Vi antager at a og b er konstanter Da gælder:

Middelværdi-regel:

E(aX+b) = aE(X)+b

Varians-regel:

Var(aX+b) = a2Var(X)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 15 / 46

Page 125: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Regneregler for stokastiske variable

Eksempel 1

X er en stokastisk variabel.

En stokastisk variabel X har middelværdi 4 og varians 6.

Spørgsmål:

Beregn middelværdi og varians for Y =−3X+2

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 16 / 46

Page 126: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Regneregler for stokastiske variable

Regneregler for stokastiske variable

X1, . . . ,Xn er stokastiske variable

Da gælder:

Middelværdi-regel:

E(a1X1 +a2X2 + ..+anXn)

= a1E(X1)+a2E(X2)+ ..+anE(Xn)

Hvis Xi og Xj (i 6= j) er uafhængige gælder desuden

Varians-regel:

Var(a1X1 +a2X2 + ..+anXn)

= a21Var(X1)+ ..+a2

nVar(Xn)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 17 / 46

Page 127: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Regneregler for stokastiske variable

Eksempel 2

Flypassager-planlægning

Vægten af passagerer på en ystrækning antages normalfordeltX ∼ N(70,102).

Et y, der kan tage 55 passagerer, må max. lastes med 4000 kg (kunpassageres vægt betragtes som last).

Spørgsmål:

Beregn sandsynligheden for at yet bliver overlastet

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 18 / 46

Page 128: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Regneregler for stokastiske variable

Eksempel 3

Lad X1, . . . ,Xn være uafhængige identisk fordelte (i.i.d.) stokastiskevariable, hvad er E(X) og Var(X)?

Hvis yderligere Xi er normalfordelte hvilken fordeling følger da X?

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 19 / 46

Page 129: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

2 Normalfordelingen

3 Regneregler for stokastiske variable

4 Simulation

Hvad er simulering egentlig?

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 20 / 46

Page 130: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation

Motivation

Mange relevant beregningsstørrelser ("computed features") harkomplicerede samplingfordelinger:

Et trimmed gennemsnitMedianenFraktiler generelt, dvs. f.eks. også IQR= Q3−Q1VariationkoecientenEnhver ikke-lineær funktion af en eller ere input variable(Spredningen)

Data/populations fordelingen kan være ikke-normal, hvilketkomplicerer den statistiske teori for selv en simpelgennemsnitsberegning

Vi kan HÅBE på the magic of CLT (Central Limit Theorem)

MEN men: Vi kan aldrig være helt sikre på om det er godt nok -simulering kan gøre os mere sikre!

Kræver: Brug af computer - R er et super værktøj til dette!

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 21 / 46

Page 131: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation Hvad er simulering egentlig?

Hvad er simulering egentlig?

(Pseudo)tilfældige tal genereret af en computer

En tilfældighedsgenerator er en algoritme der kan generere xi+1 ud fraxi

xi+1 = f (xi)

Sekvensen af tal "ser tilfældige ud

Kræver en "start - kaldet "seed .(Bruger typisk uret i computeren)

Grundlæggende simuleres den uniforme fordeling, og så bruges:

Hvis U ∼ Uniform(0,1) og F er en fordelingsfunktion for en eller andensandsynlighedsfordeling, så vil F−1(U) følge fordelingen givet ved F

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 22 / 46

Page 132: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation Hvad er simulering egentlig?

Eksempel: Exponentialfordelingen med λ = 0.5:

F(x) =∫ x

0f (t)dt = 1− e−0.5x

−5 0 5 10

0.0

0.2

0.4

0.6

0.8

1.0

x

U=

F(x

)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 23 / 46

Page 133: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation Hvad er simulering egentlig?

I praksis i R

De forskellige fordelinger er gjort klar til simulering:

rbinom Binomialfordelingenrpois Poissonfordelingenrhyper Den hypergeometriske fordelingrnorm Normalfordelingenrlnorm Lognormalfordelingenrexp Eksponentialfordelingenrunif Den uniforme(lige) fordelingrt t-fordelingenrchisq χ2-fordelingenrf F-fordelingen

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 24 / 46

Page 134: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation Hvad er simulering egentlig?

Eksempel 4: Vejen til arbejde

Jeg cykler på arbejde, turen kan deles op i nogle enkeltdele

Cykeltid (hvor cyklen bevæger sig) Xc ∼ N(16,1)

Aevere min datter i skole Xd ∼ Exp(1/2) (E[Xd] = 2)

Der er 4 lyskryds Xl,i ∼ Exp(2) (E[Xl,i] = 1/2)På 1 ud af 30 ture punkterer jeg

Hvis jeg punkterer er lappetiden fordelt som Xla ∼ N(8,2)

Hvad er

Den samlede middeltid i minutter?

Variansen af den samlede tid?

Hvad er sandsynligheden for at det tager mere en 30 minutter atkomme på arbejde?

Hvad er den samlede fordeling?

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 25 / 46

Page 135: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulation Hvad er simulering egentlig?

The simulation approach has a number of crucial advantages:1 It oers a simple tool to compute many other quantities than just the

standard deviation (the theoretical derivations of such other quantitiescould be much more complicated than what was shown for thevariance here)

2 It oers a simple tool to use any other distribution than the normal, ifwe believe such better reect reality.

3 It does not rely on any linear approximations of the true non-linearrelations.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 26 / 46

Page 136: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

2 Normalfordelingen

3 Regneregler for stokastiske variable

4 Simulation

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 27 / 46

Page 137: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

2-dimensionale diskrete stokastiske variable

Tæthedsfunktionen for en 2-dimensional stokastisk variabel [X,Y] er givet

f (x,y) = P(X = x,Y = y)

Der gælder at

f (x,y)≥ 0; ∑x

∑y

f (x,y) = 1

Desuden bruger vi

fX(x) = ∑y

f (x,y); fY(y) = ∑x

f (x,y)

fX og fY kaldes de marginale fordelinger.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 28 / 46

Page 138: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 5:

To kast med en ærlig mønt (dvs. p = 12), dener den stokastiske variable Xi

ved Xi = 1 i = 1,2 hvis krone og Xi = 0 ellers, vi har nu udfaldene

(X1,X2) =

(0,0)(0,1)(1,0)(1,1)

hver med sandsynligheden P(X1 = l,X2 = k) = 14 , l,k = 0,1. De marginale

tætheder bliver

fX1(x) =2

∑x2=1

P(X1 = x,X2 = x2) =12

; x = 0,1

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 29 / 46

Page 139: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

2-dimensionale kontinuerte stokastiske variable

Tæthedsfunktionen for en 2-dimensional kontinuert stokastisk variabel[X,Y] er givet

f (x,y)

Der gælder at

f (x,y)≥ 0;∫ ∫

f (x,y)dxdy = 1

Desuden bruger vi

fX(x) =∫

f (x,y)dy; fY(y) =∫

f (x,y)dx

fX og fY kaldes de marginale fordelinger.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 30 / 46

Page 140: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

2-dimensionale kontinuerte stokastiske variabele

For en kontinuert stokastisk vektor [X,Y] ndes middelværdi og varians forX ved

µX =∫ ∫

xf (x,y)dxdy

σ2X =

∫ ∫(x−µX)

2f (x,y)dxdy

Kovariansen og korrelation mellem X og Y er givet ved

Cov(X,Y) =∫ ∫

(x−µX)(y−µY)f (x,y)dxdy

=E[(x−µX)(y−µY)]

Cor(X,Y) =Cov(X,Y)√

σ2Xσ2

Y

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 31 / 46

Page 141: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Regneregler for stokastiske variable

(Gælder BÅDE kontinuert og diskret) Lad X og Y være stokastiske variablemed Z1 = a0 +a1X+a2Y og Z2 = b0 +b1X+b2Y da gælder

E(Z1) =a0 +a1E(X)+a2E(Y)

Cov(Z1,Z2) =a1b1V(X)+a2b2V(Y)+(a1b2 +a2b1)Cov(X,Y)

V(Z1) =a21V(X)+a2

2V(Y)+2a1a2Cov(X,Y)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 32 / 46

Page 142: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Regneregler for stokastiske variable

X1, . . . ,Xn er stokastiske variable

Da gælder:

Varians-regel:

Z =a1X1 +a2X2 + ..+anXn

Var(Z) =a21Var(X1)+ ..+a2

nVar(Xn)+2a1a2Cov(X1,X2)+ ...+

2a1anCov(X1,Xn)+2a2a3Cov(X2,X3)+ ...+

2an−1anCov(Xn−1,Xn)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 33 / 46

Page 143: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 6

Hvis X ∼ N(2,3) og Y ∼ N(0,1) (X og Y uafhængige), hvad er så E(Z),V(Z) og Cov(X,Z) når Z = X+2Y?

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 34 / 46

Page 144: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Uafhængighed

De diskrete stokastiske variable (X og Y) er uafhængige hvis

f (x,y) = P(X = x,Y = y) = P(X = x)P(Y = y)

De kontinuerte stokastiske variable (X og Y) er uafhængige hvis

f (x,y) = fX(x)fY(y)

Hvis 2 stokastiske variable er uafhængige er de også ukorrelerede(Cor(X,Y) = 0), men det modsatte er ikke nødvendigvis tilfældet.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 35 / 46

Page 145: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 5 forts.:

To kast med en ærlig mønt (dvs. p = 12), dener den stokastiske variable Xi

ved Xi = 1 i = 1,2 hvis krone og Xi = 0 ellers, vi har nu udfaldene

(X1,X2) =

(0,0)(0,1)(1,0)(1,1)

hver med sandsynligheden P(X1 = l,X2 = k) = 14 , l,k = 0,1. Da

P(X1 = k) = P(X2 = l) = 12 har vi at

P(X1 = l,X2 = k) = P(X1 = l)P(X2 = k) =14

; l,k = 0,1

og dermed er X1 og X2 uafhængige.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 36 / 46

Page 146: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 5 forts:

Dener X1 og X2 som ovenfor, men vi observere nu kun X1 og Z = X1 +X2vi har nu udfaldene

(X1,Z) =

(0,0)(0,1)(1,1)(1,2)

hver med sandsynligheden 14 . Dermed har vi også

P(X1 = 0) = P(X1 = 1) = 12 , P(Z = 0) = P(Z = 2) = 1

4 og P(Z = 1) = 12 , vi

får nu eksempelvis

P(X1 = 1,Z = 2) =146= P(X1 = 1)P(Z = 2) =

12

14=

18

og dermed er X1 og Z ikke uafhængige (hvilket passer godt med voresintuition).

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 37 / 46

Page 147: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 5 forts.: Middelværdi, varians og kovarians

Vi har

E[X] =12

; E[Z] = 1

V[X] =14

; V[Z] =12

Kovariansen fås til

Cov[X,Z] =1

∑x=0

x+1

∑z=x

(x− 1

2

)(z−1)P(X = x,Z = z)

=− 12(0−1) · 1

4+

(−1

2

)(1−1) · 1

4+

(12

)0 · 1

4+

(12

)(2−1) · 1

4

=18+0+0+

18=

14

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 38 / 46

Page 148: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Middelværdi vektor og Varians-Kovarians matricen

Lad X = [X1, ...,Xn] være en stokastisk vektor, da er middelværdivektor ogvarians-kovarians matricen deneret ved

µ =

µ1...

µn

; Σ =

σ21 . . . σ1n...

. . ....

σn1 . . . σ2n

with σij = Cov(Xi,Xj) and σ2

i = V[Xi].

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 39 / 46

Page 149: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Multivariat normalfordeling

En stokastisk vektor X = [X1, ...,Xn] siges at følge en multivariatnormalfordeling hvis tæthedsfunktionen er givet ved

f (x1, ..,xn) =1

(2π)n/2√

det(Σ)e−

12 (x−µ)T Σ

−1(x−µ)

og vi skriver X ∼ N(µ,Σ) (Σ er positiv denit).

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 40 / 46

Page 150: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel: Bivariat Normal fordeling

x1

x 2

-2

-1

0

1

2

-2 -1 0 1 2

0

-2 -1 0 1 2

0.75

0.00

0.05

0.10

0.15

0.20

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 41 / 46

Page 151: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Konstruktion af en multivariat normalfordeling

Hvis Z = [Z1, ...,Zn] følger uafhængige standard normal fordelinger, og

A ∈ Rm×n er en m×n matrix

b ∈ Rn

så følger X = b+AZ en multivariat normal fordeling med middelværdiµ = b, og varians-kovariansmatrix Σ = AAT .

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 42 / 46

Page 152: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 6, forts.

Hvis X ∼ N(2,3) og Y ∼ N(0,1) (X og Y uafhængige), nd ved matrixopskrivning E(Z), V(Z) og Cov(X,Z) når Z = X+2Y.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 43 / 46

Page 153: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Eksempel 7:

Lad Xi ∼ N(µ,σ2) (i.i.d.) nd Cov(X,Xi−X), efterprøv med simulation.

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 44 / 46

Page 154: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

Oversigt

1 Kontinuerte Stokastiske variable og fordelinger

Tæthedsfunktion

Middelværdi af en kontinuert stokastisk variabel

2 Normalfordelingen

Kontinuerte fordelinger i R

3 Regneregler for stokastiske variable

4 Simulation

Hvad er simulering egentlig?

5 Uafhængighed og kovarians

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 45 / 46

Page 155: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Uafhængighed og kovarians

På onsdag

På onsdag fortsætter vi i kapitel 2, hvor vi snakker om samplingsfordelinger(t og χ2 - fordelinger)

J.K. Møller ([email protected]) Kursus 02403 Juni 2018 46 / 46

Page 156: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 4: Stikprøvefordelinger

Jan Kloppenborg Møller

DTU Compute, Dynamiske Systemer

Bygning 305, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 1 / 36

Page 157: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 2 / 36

Page 158: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulering af eksperimenter

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 3 / 36

Page 159: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulering af eksperimenter

Eksempel: Gennemsnit og varians af normalfordelt stikprøve

Antag at vi planlægger et studie hvor vi udtager 5 observations enheder. Viantager desunden at middelværdi og varians i population er hhv µ = 10 ogσ2 = 2, hvad er fordelingen af gennemsnit og empirisk varians under disseantagelser?Der er (mindst to) måder at svare på spørgsmålet

1: Gennemgå de teoretiske udledninger for at få de præcisefordelingsfunktioner

2: Udfør eksperimentet et stort antal gange (eks. 10.000) på dincomputer og nd den empiriske fordeling

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 4 / 36

Page 160: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulering af eksperimenter

Eksempel: Gennemsnit og varians af normalfordelt stikprøve

Simuleringssvaret ndes ved

> set.seed(125)

> n <- 5; k <- 10000

> ## Simuleringen

> X <- matrix(rnorm(n * k, mean = 10, sd = sqrt(2)),

+ ncol = n, nrow = k)

> head(X)

## [,1] [,2] [,3] [,4] [,5]

## [1,] 11.3199 9.4356 6.6461 8.1428 9.5086

## [2,] 9.2575 9.9915 10.2699 10.5822 9.4101

## [3,] 12.5660 10.2551 10.2662 9.7488 9.0320

## [4,] 10.1174 10.5482 7.9771 11.6162 10.2075

## [5,] 10.5596 8.4286 11.9226 9.7385 11.6490

## [6,] 6.8977 8.5435 9.0741 9.9761 10.5987

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 5 / 36

Page 161: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Simulering af eksperimenter

Eksempel: Gennemsnit og varians af normalfordelt stikprøve

Fordelingerne af X og S2 ndes ved

> X.bar <- apply(X, 1, mean)

> S2 <- apply(X, 1, var)

> hist(X.bar, prob = TRUE); hist(S2, prob = TRUE)

Histogram of X.bar

X.bar

Den

sity

8 9 10 11 12 13

0.0

0.1

0.2

0.3

0.4

0.5

Histogram of S2

S2

Den

sity

0 2 4 6 8 10 12

0.00

0.05

0.10

0.15

0.20

0.25

0.30

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 6 / 36

Page 162: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistisk inferens og generel ramme

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 7 / 36

Page 163: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistisk inferens og generel ramme

Den formelle ramme for statistisk inferens

Fra eNote, Chapter 1:

An observational unit is the single entity/level about whichinformation is sought (e.g. a person) (Observationsenhed)

The statistical population consists of all possible measurements oneach observational unit (Population)

The sample from a statistical population is the actual set of datacollected. (Stikprøve)

Sprogbrug og koncepter:

µ og σ er parametre, som beskriver populationen

x er estimatet for µ (konkret udfald)

X og S2 er estimatorer for µ hhv. σ2(nu set som stokastisk variabel)

Begrebet 'statistic(s)' er en fællesbetegnelse for begge

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 8 / 36

Page 164: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistisk inferens og generel ramme

Statistisk inferens

I statistik har vi typisk et antal nøgletal (eks. x og s2) fra en stikprøve.

Vi ønsker at udtale os om populationens parametre (eks. µ og σ2)

Generelt kræver det en fordelingsantagelse for populationen(eksempelvis normalfordelingen)1

For at kvanticere usikkerheder har vi brug for aedte fordelinger,eksempelvis fordelingen af X og S2

Studiet af disse aedte fordelinger under normalfordelingsantagelsen eremnet for dagens forelæsning.

Vi bruger en blanding af små eller delvise beviser og simulation til atanskueligøre resultaterne

1eller mere præcist vi får bedre styrke i konklussioner hvis vi har en fodelings antagelseJan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 9 / 36

Page 165: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistisk inferens og generel ramme

Begreber

Central Estimator:En estimator θ er central (eller ikke-biased), hvis og kun hvis,middelværdien af stikprøvefordelingen for estimatoren er lig θ

Consistent EstimatorEn central estimator θ, der konvergere i sandsynlighed (du kan tænke pådet som V (θn)→ 0).

Ecient EstimatorEn estimator θ1 er en mere ecient estimator for θ end estimatoren θ2 hvis:

1 θ1 og θ2 begge er centrale estimatorer af θ

2 Variansen af stikprøvefordelingen for θ1 er mindre end for θ2

EstimatNår vi har udtaget vores stikprøve og udregnet vores nøgle tal har vi etestimat (det er ikke en stokastisk variabel)

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 10 / 36

Page 166: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistisk inferens og generel ramme

Eksempel:

Hvis X1, .., Xn i.i.d. N(µ, σ2) stokastiske variable, så er

X = µ en cetral estimator for µ (E[X] = µ).

X er også en konsistent estimator for µ (V [X] = σ2

n → 0, n→∞).

x er et estimat for µ.

medianen er også en central og konsistent estimator for µ, menmedianen er mindre ecient.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 11 / 36

Page 167: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normal fordelingen

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 12 / 36

Page 168: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Normal fordelingen

Fordeling for gennemsnit af normalfordelinger (Theorem 3.2)

(Stikprøve-) fordelingen/ The (sampling) distribution for X

Assume that X1, . . . , Xn are independent and identically normallydistributed random variables, Xi ∼ N(µ, σ2), i = 1, . . . , n, then:

X =1

n

n∑i=1

Xi ∼ N(µ,σ2

n

)

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 13 / 36

Page 169: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 14 / 36

Page 170: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel: Middelværdi af varians estimator

Lad X1 ∼ N(µ, σ2) og X2 ∼ N(µ, σ2) være uafhængige stokastiskevariable, hvad er middelværdi og varians af

Q = (X1 −X)2 + (X2 −X)2

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 15 / 36

Page 171: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel: Middelværdi af varians estimator

Lad X1, . . . , Xn være uafhængige og identisk fordelte stokastiske variablemed middelværdi E[Xi] = µ og varians V [Xi] = σ2, lad Q være

Q =

n∑i=1

(Xi −X)2

Hvad er middelværdien af Q?

E[Q] =

n∑i=1

E[(Xi −X)2]

=

n∑i=1

E[(Xi − µ+ µ−X)2]

=

n∑i=1

E[(Xi − µ)2 + (µ−X)2 + 2(Xi − µ)(µ−X)]

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 16 / 36

Page 172: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel: Middelværdi af varians estimator

Lad X1, . . . , Xn være uafhængige og identisk fordelte stokastiske variablemed middelværdi E[Xi] = µ og varians V [Xi] = σ2, lad Q være

Q =

n∑i=1

(Xi −X)2

Hvad er middelværdien af Q?

E[Q] =

n∑i=1

E[(Xi −X)2]

=

n∑i=1

E[(Xi − µ+ µ−X)2]

=

n∑i=1

E[(Xi − µ)2 + (µ−X)2 + 2(Xi − µ)(µ−X)]

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 16 / 36

Page 173: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel forts: Middelværdi af varians estimator

E[Q] =

n∑i=1

E[(Xi − µ)2] + E[(µ−X)2]− 2Cov[Xi, X]

=nσ2 + σ2 − 2

n∑i=1

1

nCov

Xi,

n∑j=1

Xj

=(n+ 1)σ2 − 2

n∑i=1

1

nCov (Xi, Xi)

=(n+ 1)σ2 − 2σ2

=(n− 1)σ2

Dermed er S2 = 1n−1

∑ni=1(Xi −X)2 en central estimator for σ2.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 17 / 36

Page 174: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

χ2-fordelingen

Hvis X1, .., Xn er iid N(0,1) så følger

Q =

n∑i=1

X2i

en χ2-fordeling med n-frihedsgrader, vi skriver Q ∼ χ2(n)Tæthedsfunktionen for en χ2-fordeling er givet ved

f(x) =1

2n2 Γ(n2

) xn2−1e−x2 ; x ≥ 0.

hvor Γ (·) er Gamma funktionen og n er antal frihedsgrader.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 18 / 36

Page 175: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

χ2-fordelingen

0 5 10 15

0.0

0.1

0.2

0.3

0.4

x

f(x)

n=1n=3n=6

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 19 / 36

Page 176: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Egenskaber ved χ2-fordelingen

Hvis Q ∼ χ2(n) så er

E(Q) =n

V (Q) =2n

Hvis Q1 ∼ χ2(n1) og Q2 ∼ χ2(n2) er uafhængige så gælder

Q = Q1 +Q2 ∼ χ2(n1 + n2)

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 20 / 36

Page 177: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel

Hvis X1, . . . , X10 er i.i.d. N(µ, σ2) og

Q =1

σ2

10∑i=1

(Xi − µ)2

Hvad er så P (Q > 10)?

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 21 / 36

Page 178: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Fordeling af varians estimator

Hvis X1, . . . , Xn er i.i.d. N(µ, σ2), med X, S2 hhv. gennemsnit ogempirisk varians. Så gælder at

1

σ2

n∑i=1

(Xi − µ)2 =(n− 1)S2

σ2+

(X − µσ/√n

)2

og det følger at

(n− 1)S2

σ2∼ χ2(n− 1)

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 22 / 36

Page 179: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Bevis (Skitse)

1: 1σ2

∑ni=1(Xi − µ)2 ∼ χ2(n) og (X−µ)2

σ2/n∼ χ2(1)

2: 1σ2

∑ni=1(Xi − µ)2 = (n−1)S2

σ2 + (X−µ)2

σ2/n

3: Cov(X, X −Xi) = 0⇒ S2 og (X − µ)2 uafhængige

4: Hvis Q1 ∼ χ2(n1) og Q2 ∼ χ2(n2) uafhængige, så gælderQ1 +Q2 ∼ χ2(n1 + n2)

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 23 / 36

Page 180: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel

Find E(S2) og V (S2).

Svar:

E[S2] =σ2

n− 1E

[n− 1

σ2S2

]V [S2] =

(σ2

n− 1

)2

V

[n− 1

σ2S2

]Da n−1

σ2 S2 ∼ χ2(n− 1) følger det at

E[S2] =σ2

n− 1(n− 1) = σ2

V [S2] =σ4

(n− 1)22(n− 1) =

2σ4

n− 1

Det betyder at S2 er en central og konsistent estimator for σ2

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 24 / 36

Page 181: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel

Find E(S2) og V (S2). Svar:

E[S2] =σ2

n− 1E

[n− 1

σ2S2

]V [S2] =

(σ2

n− 1

)2

V

[n− 1

σ2S2

]Da n−1

σ2 S2 ∼ χ2(n− 1) følger det at

E[S2] =σ2

n− 1(n− 1) = σ2

V [S2] =σ4

(n− 1)22(n− 1) =

2σ4

n− 1

Det betyder at S2 er en central og konsistent estimator for σ2

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 24 / 36

Page 182: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

χ2-fordelingen

Eksempel: Sammenvægtet varians

Lad X1, ..., Xn1 og Y1, ..., Yn2 (i.i.d. stokastiske variable) følge 2uafhængige normalfordelinger, Xi ∼ N(µ1, σ

2), og Yi ∼ N(µ2, σ2). Med

a ∈ [0, 1] nd a så V [S2p ] minimeres når

S2P = aS2

1 + (1− a)S22

hvor S21 og S2

2 er stikprøve variansen for hhv. X og Y . Opskriv S2P og nd

V [S2P ].

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 25 / 36

Page 183: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 26 / 36

Page 184: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

t-fordelingen

Hvis X ∼ N(0, 1) og Q ∼ χ2(n) og X og Q er uafhængige så følger

T =X√Q/n

(1)

en t-fordeling med n-frihedsgrader.Tæthedsfunktionen for en t-fordeling er givet ved

fT (t) =Γ(n+1

2 )√nπ Γ(n2 )

(1 + t2

n

)−n+12

; t ∈ R (2)

hvor n er antallet af frihedsgrader og Γ() er Gamma funktionen.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 27 / 36

Page 185: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

t-fordelingen

−4 −2 0 2 4

0.0

0.1

0.2

0.3

0.4

x

f(x)

n=1n=3n=6N(0,1)

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 28 / 36

Page 186: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

t-fordelingen som stikprøvefordeling

Lad X1, . . . , Xn være i.i.d. ∼ N(µ, σ2) så følger

T =X − µ√S2/n

(3)

en t-fordeling med n− 1 frihedsgrader.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 29 / 36

Page 187: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

t-fordelingen som stikprøvefordeling - Bevis

Vi skal vise at T kan skrives som en standard normal fordeling dividet meden χ2-fordeling med n− 1 frihedsgrader (og at tæller og nævner eruafhængige).

1: Vi har vist at X og S2 er uafhængige

2: Z = X−µσ/√n∼ N(0, 1) og Q = n−1

σ2 S2 ∼ χ2(n− 1)

3:

T =

1σ/√n

(X − µ)√1

σ2/nn−1n−1S

2/n=

Z√Q/(n− 1)

så per denition følger T en t-fordeling med n− 1 frihedsgrader.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 30 / 36

Page 188: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Eksempel: Kondensinterval

Lad X1, . . . , Xn være i.i.d. ∼ N(µ, σ2), nd d så (0 < α < 0.5)

1− α = P (µ− d · S < X < µ+ d · S)

Svar:

P (µ− d · S < X < µ+ d · S) =P

(−d < X − µ

S< d

)=P

(−d√n <

X − µS/√n< d√n

)=FT (d

√n)− FT (−d

√n) = 2FT (d

√n)− 1

ved at sætte ovenstående lig med 1− α og løse for d fås

d =1√nF−1T

(1− α

2

)=t1−α

2√n

hvor t1−α2er 1− α

2 -fraktilen i en t-fordeling med n− 1 frihedsgrader.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 31 / 36

Page 189: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Eksempel: Kondensinterval

Lad X1, . . . , Xn være i.i.d. ∼ N(µ, σ2), nd d så (0 < α < 0.5)

1− α = P (µ− d · S < X < µ+ d · S)

Svar:

P (µ− d · S < X < µ+ d · S) =P

(−d < X − µ

S< d

)=P

(−d√n <

X − µS/√n< d√n

)=FT (d

√n)− FT (−d

√n) = 2FT (d

√n)− 1

ved at sætte ovenstående lig med 1− α og løse for d fås

d =1√nF−1T

(1− α

2

)=t1−α

2√n

hvor t1−α2er 1− α

2 -fraktilen i en t-fordeling med n− 1 frihedsgrader.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 31 / 36

Page 190: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Eksempel: Kondensinterval

Vi har altså

1− α = P

(µ−

t1−α2√n· S < X < µ+

t1−α2√n· S)

= P

(X −

t1−α2√n· S < µ < X +

t1−α2√n· S)

Læg mærke til at i den sidste omskrivning er intervallet stokastiske, mens µer en fast størrelse.I statistik vil vi typisk udtale os om en ukendt størrelse (eksempelvis µ) påbasis af realisationer af gennemsnit (x) og (empirisk) varians (s2), og vikan eksempelvis skrive at vi er 95% sikre på at µ ligger i intervallet

x± t0.975 · s/√n

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 32 / 36

Page 191: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Kondensintervaller for stigende stikprøvestørrelse

0 5 10 15 20 25 30

−3

−2

−1

01

23

n

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 33 / 36

Page 192: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Eksempel

Brug α = 0.05

Udregn d afstandsdata udtaget på dag 1

opskriv intervallet x± d · sgiv en fortolkning af dette interval

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 34 / 36

Page 193: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

Oversigt

1 Simulering af eksperimenter

2 Statistisk inferens og generel ramme

3 Normal fordelingen

4 χ2-fordelingen

5 t-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 35 / 36

Page 194: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

t-fordelingen

I morgen

I morgen tager vi hul på eNote 3 og starter dermed med mere specikkestatistiske metoder.

Jan K. Møller ([email protected]) 02403, Forelæsning 4 Juni 2018 36 / 36

Page 195: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 5: One sample situationer

Jan Kloppenborg Møller

DTU Compute, Dynamiske Systemer

Bygning 303B, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 1 / 52

Page 196: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 2 / 52

Page 197: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-normale data, Central Grænseværdisætning (CLT)

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 3 / 52

Page 198: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-normale data, Central Grænseværdisætning (CLT)

Theorem 3.14: The Central Limit Theorem

Gennemsnittet af en tilfældig stikprøve følger uanset hvad ennormalfordeling:

Let X be the mean of a random sample of size n taken from a populationwith mean µ and variance σ2, then

Z =X − µσ/√n

is a random variable whose distribution function approaches that of thestandard normal distribution, N(0, 12), as n→∞

Dvs., hvis n er stor nok, kan vi (tilnærmelsesvist) antage:

X − µσ/√n∼ N(0, 12)

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 4 / 52

Page 199: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-normale data, Central Grænseværdisætning (CLT)

Konsekvens af CLT:

Vores normal fordelings baserede metoder virker OGSÅ for ikke-normaledata:

Vi kan bruge kondens-interval baseret på t-fordelingen i stort set allesituationer, blot n er stor nok

Hvad er stor nok?

Faktisk svært at svare præcist på, MEN:

Tommelngerregel:n ≥ 30

Selv for mindre n kan formlen være (næsten)gyldig for ikke-normaledata.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 5 / 52

Page 200: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 6 / 52

Page 201: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

Theorem 3.3: Fordeling for gennemsnit af normalfordelinger

(Stikprøve-) fordelingen/ The (sampling) distribution for X

Assume that X1, . . . , Xn are independent and identically normallydistributed random variables, Xi ∼ N(µ, σ2), i = 1, . . . , n, then:

X =1

n

n∑i=1

Xi ∼ N(µ,σ2

n

)

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 7 / 52

Page 202: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

Standardiseret version af de samme ting, Theorem 3.4:

Fordelingen for den standardiserede fejl vi begår:

Assume that X1, . . . , Xn are independent and identically normallydistributed random variables, Xi ∼ N (µ, σ2) where i = 1, . . . , n,then:

Z =X − µσ(X−µ)

=X − µσ/√n∼ N

(0, 12

)That is, the standardized sample mean Z follows a standard normal

distribution.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 8 / 52

Page 203: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

Theorem 3.5: More applicable extension of the same stu:

t-fordelingen tager højde for usikkerheden i at bruge s:

Assume that X1, . . . , Xn are independent and identically normallydistributed random variables, where Xi ∼ N

(µ, σ2

)and i = 1, . . . , n, then:

T =X − µS/√n∼ t

where t is the t-distribution with n− 1 degrees of freedom.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 9 / 52

Page 204: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

t-fordelingen med 9 frihedsgrader (n = 10):

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

x

dt(x,

9)

Black: standard normal

Red: t(9)

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 10 / 52

Page 205: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

t-fordelingen med 9 frihedsgrader ogstandardnormalfordelingen:

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

x

dt(x,

9)

Black: standard normal

Red: t(9)

P(T>2)=0.038

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 11 / 52

Page 206: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fordelingen for gennemsnittet

t-fordelingen med 9 frihedsgrader ogstandardnormalfordelingen:

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

x

dt(x,

9)

Black: standard normal

Red: t(9)

P(Z>2)=0.023

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 12 / 52

Page 207: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den statistiske sprogbrug og formelle ramme

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 13 / 52

Page 208: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den statistiske sprogbrug og formelle ramme

Den formelle ramme for statistisk inferens

Fra eNote, Chapter 1:

An observational unit is the single entity/level about whichinformation is sought (e.g. a person) (Observationsenhed)

The statistical population consists of all possible measurements oneach observational unit (Population)

The sample from a statistical population is the actual set of datacollected. (Stikprøve)

Sprogbrug og koncepter:

µ og σ er parametre, som beskriver populationen

x er estimatet for µ (konkret udfald)

X er estimatoren for µ (nu set som stokastisk variabel)

Begrebet 'statistic(s)' er en fællesbetegnelse for begge

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 14 / 52

Page 209: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den statistiske sprogbrug og formelle ramme

Den formelle ramme for statistisk inferens - Eksempel

Fra eNote, Chapter 1, højdeeksempel

Vi måler højden for 10 tilfældige personer i Danmark

Stikprøven/The sample:

De 10 konkrete talværdier: x1, . . . , x10

Populationen:

Højderne for alle mennesker i Danmark.

Observationsenheden:En person

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 15 / 52

Page 210: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den statistiske sprogbrug og formelle ramme

Statistisk inferens = Learning from data

Learning from data:

Is learning about parameters of distributions that describe populations.

Vigtigt i den forbindelse:

Stikprøven skal på meningsfuld vis være repræsentativ for en eller andenveldeneret population

Hvordan sikrer man det:

F.eks. ved at sikre at stikprøven er fuldstændig tilfældig udtaget

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 16 / 52

Page 211: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den statistiske sprogbrug og formelle ramme

Tilfældig stikprøveudtagning

Denition 3.11:

A random sample from an (innite) population: A set ofobservations X1, X2, ..., Xn constitutes a random sample of sizen from the innite population f(x) if:

1 Each Xi is a random variable whose distribution is given byf(x)

2 These n random variables are independent

Hvad betyder det????

1 Alle observationer skal komme fra den samme population2 De må IKKE dele information med hinanden (f.eks. hvis man

havde udtaget hele familier i stedet for enkeltindivider)

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 17 / 52

Page 212: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensintervallet for µ

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 18 / 52

Page 213: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensintervallet for µ

'Repeated sampling' fortolkning

I det lange løb fanger vi den sande værdi i 95% af tilfældene:

Kondensintervallet vil variere i både bredde (s) og position (x) hvis mangentager sit studie.

Mere formelt udtrykt (Theorem 3.5):

P

(|X − µ|S/√n

< t0.975

)= 0.95

Som er ækvivalent med:

P

(X − t0.975

S√n< µ < X + t0.975

S√n

)= 0.95

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 19 / 52

Page 214: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensintervallet for µ

Metodeboks 3.9: One-sample kondensinterval for µ

Brug den rigtige t-fordeling til at lave kondensintervallet:

For a sample x1, . . . , xn the 100(1− α)% condence interval is given by:

x± t1−α/2 ·s√n

where t1−α/2 is the 100(1− α)% quantile from the t-distribution withn− 1 degrees of freedom.

Mest almindeligt med α = 0.05:

The most commonly used is the 95%-condence interval:

x± t0.975 ·s√n

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 20 / 52

Page 215: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensintervallet for µ

Der ndes en R-funktion, der kan gøre det hele (med mere):

## Angiv data

x <- c(180 ,180 ,184 ,182 ,178 ,190 ,175)/100

## Beregn 99% konfidensinterval

t.test(x, conf.level=0.99)

##

## One Sample t-test

##

## data: x

## t = 100, df = 6, p-value = 6.7e-11

## alternative hypothesis: true mean is not equal to 0

## 99 percent confidence interval:

## 1.7458 1.8799

## sample estimates:

## mean of x

## 1.8129

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 21 / 52

Page 216: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for varians og spredning

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 22 / 52

Page 217: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for varians og spredning

Eksempel

Produktion af tabletter

Vi producere pulverblanding og tabletter deraf, såkoncentrationen af det aktive stof i tabletterne skal være 1mg/g med den mindst mulige spredning. En tilfældigstikprøve udtages, hvor vi måler mængden af aktivt stof.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 23 / 52

Page 218: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for varians og spredning

Stikprøvefordelingen for varians-estimatet (Theorem 2.81)

Variansestimater opfører sig som en χ2-fordeling:

Let

S2 =1

n− 1

n∑i=1

(Xi − X)2

then:

χ2 =(n− 1)S2

σ2

is a random variable following the χ2-distribution with v = n− 1 degrees offreedom.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 24 / 52

Page 219: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for varians og spredning

Metode 3.19: Kondensinterval for stikprøvevarians og-spredning

Variansen:

A 100(1− α)% condence interval for the variance σ2 is:[(n− 1)s2

χ21−α/2

;(n− 1)s2

χ2α/2

]

where the quantiles come from a χ2-distribution with ν = n− 1 degrees of

freedom.

Spredningen:

A 100(1− α)% condence interval for the standard deviation σ is:[√(n− 1)s2

χ21−α/2

;

√(n− 1)s2

χ2α/2

]

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 25 / 52

Page 220: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for varians og spredning

Eksempel

Data:

En tilfældig stikprøve med n = 20 tabletter er udtaget og fra denne fårman:

µ = x = 1.01, σ2 = s2 = 0.072

95%-kondensinterval for variansen - vi skal bruge χ2-fraktilerne:

χ20.025 = 8.9065, χ2

0.975 = 32.8523

## 2.5% og 97.5% fraktilerne i chi^2 fordelingen for n=20

qchisq(c(0.025, 0.975), df = 19)

## [1] 8.9065 32.8523

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 26 / 52

Page 221: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for varians og spredning

Eksempel

Så kondensintervallet for variansen σ2 bliver:[19 · 0.72

32.85;

19 · 0.72

8.907

]= [0.002834; 0.01045]

Og kondensintervallet for spredningen σ bliver:[√0.002834;

√0.01045

]= [0.053; 0.102]

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 27 / 52

Page 222: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel - sovemedicin

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 28 / 52

Page 223: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel - sovemedicin

Motiverende eksempel - sovemedicin

Forskel på sovemedicin?

I et studie er man interesseret i at sammenligne 2 sovemidler A og B. For10 testpersoner har man fået følgende resultater, der er givet i forlængetsøvntid (i timer) (Forskellen på eekten af de to midler er angivet):

Stikprøve, n = 10:person x = Beect - Aeect

1 1.2

2 2.4

3 1.3

4 1.3

5 0.9

6 1.0

7 1.8

8 0.8

9 4.6

10 1.4

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 29 / 52

Page 224: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel - sovemedicin

Eksempel - sovemedicin

Hypotesen om ingen forskel ønskes undersøgt:

H0 : µ = 0

Sample mean og standarddeviation:

x = 1.670 = µ

s = 1.13 = σ

Er data i overenstemmelse mednulhyposen H0?

Data: x = 1.67, H0 : µ = 0

NYT:p-værdi:

p− værdi = 0.00117

(Beregnet under det scenarie, atH0 er sand)

NYT:Konklusion:

Idet data er usandsynligt underH0, så forkaster vi H0 - vi harpåvist en signikant eekt afmiddel B ift. middel A.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 30 / 52

Page 225: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 31 / 52

Page 226: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi

Metode 3.23: One-sample t-test og p-værdi

Hvordan beregner man p-værdien?

For a (quantitative) one sample situation, the (non-directional) p-value isgiven by:

p-value = 2 · P (T > |tobs|)

where T follows a t-distribution with (n− 1) degrees of freedom.The observed value of the test statistics to be computed is

tobs =x− µ0

s/√n

where µ0 is the value of µ under the null hypothesis:

H0 : µ = µ0

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 32 / 52

Page 227: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi p-værdier og hypotesetest (HELT generelt)

Denition og fortolkning af p-værdien (HELT generelt)

Denition 3.22 af p-værdien:

The p-value is the probability of obtaining a test statistic that is at leastas extreme as the test statistic that was actually observed. This probabilityis calculated under the assumption that the null hypothesis is true.

p-værdien udtrykker evidence imod nulhypotesen Tabel 3.1:

p < 0.001 Very strong evidence against H0

0.001 ≤ p < 0.01 Strong evidence against H0

0.01 ≤ p < 0.05 Some evidence against H0

0.05 ≤ p < 0.1 Weak evidence against H0

p ≥ 0.1 Little or no evidence against H0

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 33 / 52

Page 228: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi p-værdier og hypotesetest (HELT generelt)

Eksempel - sovemedicin

Hypotesen om ingen forskel ønskes undersøgt:

H0 : µ = 0

Beregne test-størrelsen:

tobs =1.67− 0

1.13/√

10= 4.67

Beregne p-værdien:

2P (T > 4.67) = 0.00117

2 * (1-pt(4.67, 9))

Fortolkning af p-værdi i lyset af Tabel 3.1:

Der er stærk evidens imod nulhypotesen.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 34 / 52

Page 229: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi p-værdier og hypotesetest (HELT generelt)

Eksempel - sovemedicin - i R - manuelt

## Angiv data

x <- c(1.2, 2.4, 1.3, 1.3, 0.9, 1.0, 1.8, 0.8, 4.6, 1.4)

n <- length(x)

## Beregn den observerede t værdi - den observerede test statistik

tobs <- (mean(x) - 0) / (sd(x) / sqrt(n))

## Beregn p-værdien, som sandsynligheden for at få tobs eller mere ekstremt

pvalue <- 2 * (1-pt(abs(tobs), df=n-1))

pvalue

## [1] 0.0011659

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 35 / 52

Page 230: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi p-værdier og hypotesetest (HELT generelt)

Eksempel - sovemedicin - i R - med indbygget funktion

## Kald funktionen med data x

t.test(x)

##

## One Sample t-test

##

## data: x

## t = 4.67, df = 9, p-value = 0.0012

## alternative hypothesis: true mean is not equal to 0

## 95 percent confidence interval:

## 0.86133 2.47867

## sample estimates:

## mean of x

## 1.67

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 36 / 52

Page 231: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi p-værdier og hypotesetest (HELT generelt)

Denition af hypotesetest og signikans (HELT generelt)

Denition 3.24. Hypotesetest:

We say that we carry out a hypothesis test when we decide against a nullhypothesis or not, using the data.

A null hypothesis is rejected if the p-value, calculated after the data hasbeen observed, is less than some α, that is if the p-value < α, where α issome pre-specifed (so-called) signicance level. And if not, then the nullhypothesis is said to be accepted.

Denition 3.29. Statistisk signikans:

An eect is said to be (statistically) signicant if the p-value is less thanthe signicance level α.(OFTE bruges α = 0.05)

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 37 / 52

Page 232: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi p-værdier og hypotesetest (HELT generelt)

Eksempel - sovemedicin

Med α = 0.05 kan vi konkludere:

Idet p-værdien er mindre end α så forkaster vi nulhypotesen.

Og dermed:

Vi har påvist en signikant eekt af middel B ift. middel A. (Og dermedat B virker bedre end A)

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 38 / 52

Page 233: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi Kritisk værdi og kondensinterval

Kritisk værdi

Denition 3.31 - de kritiske værdier for t-testet:

The (1− α)100% critical values for the (non-directional) one-sample t-testare the (α/2)100% and (1− α/2)100% quantiles of the t-distribution withn− 1 degrees of freedom:

tα/2 and t1−α/2

Metode 3.32: One-sample t-test vha. kritisk værdi:

A null hypothesis is rejected if the observed test-statistic is more extremethan the critical values:

If |tobs| > t1−α/2 then reject H0

otherwise accept.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 39 / 52

Page 234: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi Kritisk værdi og kondensinterval

Kritisk værdi og hypotesetest

Acceptområdet er de mulige værdier for µ som ikke ligger for langt væk fradata - her på den standardiserede skala:

AcceptanceRejection Rejection

t0.025 t0.9750

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 40 / 52

Page 235: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi Kritisk værdi og kondensinterval

Kritisk værdi og hypotesetest

Acceptområdet er de mulige værdier for µ som ikke ligger for langt væk fradata - nu på den egentlige skala:

AcceptanceRejection Rejection

x - t0.025s n x + t0.975s nx

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 41 / 52

Page 236: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi Kritisk værdi og kondensinterval

Kritisk værdi, kondensinterval og hypotesetest

Theorem 3.33:Kritisk-værdi-metode ækvivalent med Kondensinterval-metode

We consider a (1− α) · 100% condence interval for µ:

x± t1−α/2 ·s√n

The condence interval corresponds to the acceptance region for H0 whentesting the (non-directional) hypothesis

H0 : µ = µ0

(Ny) fortolkning af kondensintervallet:

De (hypotetiske) værdier for µ, som vi accepterer ved det tilsvarendehypotesetest.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 42 / 52

Page 237: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

One-sample t-test og p-værdi Kritisk værdi og kondensinterval

Bevis:

Remark 3.34

A µ0 inside the condence interval will fullll that

|x− µ0| < t1−α/2 ·s√n

which is equivalent to|x− µ0|

s√n

< t1−α/2

and again to|tobs| < t1−α/2

which then exactly states that µ0 is accepted, since the tobs is within thecritical values.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 43 / 52

Page 238: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 44 / 52

Page 239: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer

Hypotese-test med alternativer

Indtil nu - underforstået: (= non-directional)

Alternativet til H0 : µ = µ0 er : H1 : µ 6= µ0

MEN der kan være andre settings, e.g. one-sided (=directional), less:

Alternativet til H0 : µ = µ0 er : H1 : µ < µ0

Eller one-sided (=directional), greater:

Alternativet til H0 : µ = µ0 er : H1 : µ > µ0

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 45 / 52

Page 240: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Metode 3.36. Steps ved hypotesetests - et overblik

Helt generelt består et hypotesetest af følgende trin:1 Formulate the hypotheses and choose the level of signicance α

(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 samplingdistribution, and compare the p-value and the signicance level α andmake a conclusion

4 (Alternatively, make a conclusion based on the relevant criticalvalue(s))

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 46 / 52

Page 241: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Det tosidede (non-directional) one-sample t-test igen

Et level α test er:1 Compute tobs as before2 Compute the evidence against the null hypothesis H0 : µ = µ0 vs. the

alternative hypothesis H1 : µ 6= µ0 by the

pvalue = 2 · P (T > |tobs|)

where the t-distribution with n− 1 degrees of freedom is used.3 If pvalue < α: We reject H0, otherwise we accept H0.4 The rejection/acceptance conclusion could alternatively, but

equivalently, be made based on the critical value(s) ±t1−α/2:If |tobs| > t1−α/2 we reject H0, otherwise we accept H0.

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 47 / 52

Page 242: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Mulige fejl ved hypotesetests

Der ndes to slags fejl (dog kun een af gangen!)

Type I: Rejection of H0 when H0 is trueType II: Non-rejection of H0 when H1 is true

Risikoen for de to typer fejl kaldes sædvanligvis:

P (Type I error) = α

P (Type II error) = β

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 48 / 52

Page 243: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Retsalsanalogi

En person står stillet for en domstol:

A man is standing in a court of law accused of criminal activity.The null- and the the alternative hypotheses are:

H0 : The man is not guilty

H1 : The man is guilty

At man ikke kan bevises skyldig er ikke det samme som at man er bevistuskyldig:

Absence of evidence is NOT evidence of absence!

Or dierently put:Accepting a null hypothesis is NOT a statistical proof of the nullhypothesis being true!

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 49 / 52

Page 244: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Mulige fejl ved hypotesetests

To mulige sandheder vs. to mulige konklusioner:

Reject H0 Fail to reject H0

H0 is true Type I error (α) Correct acceptance of H0

H0 is false Correct rejection of H0 (Power) Type II error (β)

Theorem 3.39: Signikansniveauet = Risikoen for Type I fejl

The signicance level α in hypothesis testing is the overall Type I risk:

P (Type I error) = P (Rejection of H0 when H0 is true) = α

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 50 / 52

Page 245: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Eksempel: Sommervandtemperatur i Skive fjord

Hvad er:

Den forventede vandtemperatur i Skive fjord i juli måned?

Variationen i vandtemperaturen i jui måned i Skive fjord fra år til år?

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 51 / 52

Page 246: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotese-test med alternativer Hypotesetest - generel metode

Oversigt

1 Ikke-normale data, Central Grænseværdisætning (CLT)

2 Fordelingen for gennemsnittet

3 Den statistiske sprogbrug og formelle ramme

4 Kondensintervallet for µ

5 Kondensinterval for varians og spredning

6 Motiverende eksempel - sovemedicin

7 One-sample t-test og p-værdip-værdier og hypotesetest (HELT generelt)Kritisk værdi og kondensinterval

8 Hypotese-test med alternativerHypotesetest - generel metode

Jan K. Møller ([email protected]) 02403, Forelæsning 5 Juni 2018 52 / 52

Page 247: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 6: Two sample situationer

Jan Kloppenborg Møller

DTU Compute, Dynamiske Systemer

Bygning 303B, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 1 / 49

Page 248: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 2 / 49

Page 249: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 3 / 49

Page 250: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption The Normal QQ plot

Eksempel

Vi har følgende observationer af radon koncentrationer

################################

## Eksempel radon data

radon <- c(2.4, 4.2, 1.8, 2.5, 5.4, 2.2, 4.0, 1.1, 1.5, 5.4,

6.3, 1.9, 1.7, 1.1, 6.6, 3.1, 2.3, 1.4, 2.9, 2.9)

Find et 95% kondeninterval for det forventede radon niveau og udførhypotese testen H0 : µ ≥ 3.5, mod det ensided alternativH1 : µ < 3.5.

Undersøg om modellens forudsætninger er opfyldt.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 4 / 49

Page 251: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption The Normal QQ plot

Eksempel - Radon data

hist(radon,freq=FALSE)

curve(dnorm(x, mean=mean(radon),sd=sd(radon)),col=2,lwd=2,add=TRUE)

plot(ecdf(radon))

curve(pnorm(x, mean=mean(radon),sd=sd(radon)),col=2,lwd=2,add=TRUE)

Histogram of radon

radon

Den

sity

1 2 3 4 5 6 7

0.00

0.05

0.10

0.15

0.20

0.25

0.30

0.35

1 2 3 4 5 6 7

0.0

0.2

0.4

0.6

0.8

1.0

ecdf(radon)

x

Fn(x)

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 5 / 49

Page 252: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption The Normal QQ plot

Normal Q-Q plot

En bedre metode er at sammenligne de observerede fraktiler direkte med deforventede fraktiler i normal fordelingen.

Metode 3.42 - Den formelle denition

The ordered observations x(1), . . . , x(n) are plotted versus a set of expectednormal quantiles zp1 , . . . , zpn . Dierent denitions of p1, . . . , pn exist:

In R, when n > 10:

pi =i− 0.5

n, i = 1, . . . , n

In R, when n ≤ 10:

pi =i− 3/8

n+ 1/4, i = 1, . . . , n

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 6 / 49

Page 253: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption The Normal QQ plot

Eksempel - Radon data

Punkterne skal ligge på en ret linie

qqnorm(radon,pch=19)

qqline(radon)

Histogram of radon

radon

Den

sity

1 2 3 4 5 6 7

0.00

0.05

0.10

0.15

0.20

0.25

0.30

0.35

1 2 3 4 5 6 7

0.0

0.2

0.4

0.6

0.8

1.0

ecdf(radon)

x

Fn(x)

-2 -1 0 1 2

12

34

56

Normal Q-Q Plot

Theoretical Quantiles

Sample

Quantiles

Er det for langt fra den rette linie? Wallyplot kan hjælpe...

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 7 / 49

Page 254: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption Transformation towards normality

Hvad hvis data ikke er normafordelte?

I tilfælde hvor normalfordelingen ikke holder kan man prøve at transformeredata, nogle muligheder er

log(x),√x, og x1/3 (gør store værdier mindre, dvs. ved højreskæve

fordelinger)

x2 eller x3 (gør store værdier størrer, dvs. ved venstreskævefordelinger)

Udfør statistiske test på transformerede data

OBS: Fraktiler en invariante ifht. (monotone) transformationer, det ermiddelværdier ikke!

log-transformationen er den klart mest anvendte.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 8 / 49

Page 255: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumption Transformation towards normality

Eksempel - Radon data - log-transformerede data er tætterepå normal fordelingen

##TRANSFORM USING NATURAL LOGARITHM

logRadon<-log(radon)

hist(logRadon)

qqnorm(logRadon,ylab = 'Sample quantiles',xlab = "Normal quantiles")

qqline(logRadon)

Histogram of logRadon

logRadon

Frequen

cy

0.0 0.5 1.0 1.5 2.0

01

23

45

67

-2 -1 0 1 2

0.5

1.0

1.5

Normal Q-Q Plot

Normal quantiles

Sample

quantiles

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 9 / 49

Page 256: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 10 / 49

Page 257: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Planlægning, KI - formulering

KI = x± t1−α/2s√n

= x±ME

Hvis σ er kendt får vi

KI = x± z1−α/2σ√n

= x±ME

For kendt σ og ønsket ME kan vi løse for n

n =(z1−α/2σ

ME

)2

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 11 / 49

Page 258: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Planlægning, Styrke (=Power)

Hvad er styrken for et kommende studie/eksperiment:

Sandsynligheden for at opdage en (formodet) eekt

P (Forkaste H0 når H1 er sand)

Probability of correct rejection of H0

Udfordring: Nulhypotesen kan være forkert på mange måder!

I praksis: Scenarie-baseret approach

E.g. "Hvad nu hvis µ = 86, hvor godt vil mit studie være til at opdage

dette? "

E.g. "Hvad nu hvis µ = 84, hvor godt vil mit studie være til at opdage

dette? "

etc

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 12 / 49

Page 259: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Planlægning, Styrke (=Power)

Når man har fastlagt hvilket test, der skal bruges:

Kender man (eller fastlægger/gætter på) re ud af følgende femoplysninger, kan man regne sig frem til den femte:

Stikprøvestørrelse (sample size) n

Signicance level α of the test.

A change in mean that you would want to detect (eect size) µ0 − µ1.The population standard deviation, σ.

The power (1− β)=P (Forkaste H0 når H1 er sand).

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 13 / 49

Page 260: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Low power eksempel

Low power

Pro

babi

lity

dens

ity

µ0 µ1

0.0

0.1

0.2

0.3

0.4

0.5

αβ Power

Under H0

Under H1

αβ

Power

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 14 / 49

Page 261: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

High power eksempel

High power

Pro

babi

lity

dens

ity

µ0 µ1

0.0

0.1

0.2

0.3

0.4

0.5

αβPower

Under H0

Under H1

αβ

Power

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 15 / 49

Page 262: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Planlægning, Sample size n

Det store spørgsmål i praksis: HVAD skal n være?

Forsøget skal være stort nok til at kunne opdage en relevant eekt medstor power (som regel mindst 80%):

Metode 3.65: Sample size for one-sample t-test:

One-sample t-test for given α, β and σ:

n =

(σz1−β + z1−α/2

(µ0 − µ1)

)2

Where µ0 − µ1 is the change in means that we would want to detect andz1−β , z1−α/2 are quantiles of the standard normal distribution.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 16 / 49

Page 263: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Planlægning: Power og sample size

Eksempel - The sample size for power= 0.80

## Stikprøvestørrelse for t-test

power.t.test(power = .80, delta = 4, sd = 12.21,

type = "one.sample")

##

## One-sample t test power calculation

##

## n = 75.077

## delta = 4

## sd = 12.21

## sig.level = 0.05

## power = 0.8

## alternative = two.sided

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 17 / 49

Page 264: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 18 / 49

Page 265: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Motiverende eksempel - energiforbrug

Forskel på energiforbrug?

I et ernæringsstudie ønsker man at undersøge om der er en forskel ienergiforbrug for forskellige typer (moderat fysisk krævende) arbejde. Istudiet er energyforbruget for 9 sygeplejersker fra hospital A målt ogenergyforbruget for 9 (andre) sygeplejersker fra hospital B målt. Målingerneer givet i mega Joule (MJ):

Stikprøve fra hver hospital,n1 = n2 = 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

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 19 / 49

Page 266: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Eksempel - energiforbrug

Hypotesen om ingen forskel ønskes undersøgt:

H0 : µ1 = µ2

Sample means og standarddeviations:

µA = xA = 8.293, (sA = 1.428)

µB = xB = 10.298, (sB = 1.398)

Er data i overenstemmelse mednulhyposen H0?

Data: xB − xA = 2.005

Nulhypotese: H0 : µB − µA = 0

NYT:p-værdi for forskel:

p− værdi = 0.0083

(Beregnet under det scenarie, atH0 er sand)

NYT:Kondensinterval for

forskel:

2.005± 1.412 = [0.59; 3.42]

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 20 / 49

Page 267: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Sammenvægtet (Pooled) variance set up

Assume that X1,i ∼ N(µ1, σ) and X2,j ∼ N(µ2, σ). Then the pooledtwo-sample statistic seen as a random variable (Theorem 3.54, Example2.85 og Exercise 2.16):

T =(X1 − X2)− δ0√S2p/n1 + S2

p/n2(1)

follows, under the null hypothesis and under the assumption that σ21 = σ22,a t-distribution with n1 + n2 − 2 degrees of freedom if the two populationdistributions are normal.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 21 / 49

Page 268: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

The pooled two-sample t-test statistic

Beregning af den poolede teststørrelse (Metode 3.52 og 3.53)

When considering the null hypothesis about the dierence between themeans of two independent samples:

δ = µ2 − µ1

H0 : δ = δ0

the pooled two-sample t-test statistic is

tobs =(x1 − x2)− δ0√s2p/n1 + s2p/n2

With s2p =(n1−1)s21+(n2−1)s22

n1+n2−2 .

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 22 / 49

Page 269: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Theorem 3.50: Fordelingen af (Welch) t-teststørrelsen

Welch t-teststørrelsen er t-fordelt

The (Welch) two-sample statistic seen as a random variable:

T =(X1 − X2)− δ0√S21/n1 + S2

2/n2

approximately, under the null hypothesis, follows a t-distribution with νdegrees of freedom, where

ν =

(s21n1

+s22n2

)2(s21/n1)2

n1−1 +(s22/n2)2

n2−1

.

if the two population distributions are normal or if the two sample sizes arelarge enough.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 23 / 49

Page 270: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Metode 3.49: Two-sample t-test

Beregning af teststørrelsen

When considering the null hypothesis about the dierence between themeans of two independent samples:

δ = µ2 − µ1

H0 : δ = δ0

the (Welch) two-sample t-test statistic is

tobs =(x1 − x2)− δ0√s21/n1 + s22/n2

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 24 / 49

Page 271: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Metode 3.51: Two-sample t-test

Et level α test er

1 Compute tobs and ν as given above.

2 Compute the evidence against the null hypothesisa H0 : µ1 − µ2 = δvs. the alternative hypothesis H1 : µ1 − µ2 6= δ by the

pvalue = 2 · P (T > |tobs|)

where the t-distribution with ν degrees of freedom is used.

3 If pvalue < α: We reject H0, otherwise we accept H0.

4 The rejection/acceptance conclusion could alternatively, butequivalently, be made based on the critical value(s) ±t1−α/2:If |tobs| > t1−α/2 we reject H0, otherwise we accept H0.

a

We are often interested in the test where δ = 0

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 25 / 49

Page 272: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Eksempel - energiforbrug

Hypotesen om ingen forskel ønskes undersøgt:

H0 : δ = µB − µA = 0

versus the non-directional(= two-sided) alternative:

H0 : δ = µB − µA 6= 0

Først beregninger af tobs og ν:

tobs =10.298− 8.293√

2.0394/9 + 1.954/9= 3.01

and

ν =

(2.0394

9 + 1.9549

)2(2.0394/9)2

8 + (1.954/9)2

8

= 15.99

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 26 / 49

Page 273: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Two-sample t-test og p-værdi

Eksempel - energiforbrug

Dernæst ndes p-værdien:

pvalue = 2 · P (T > |tobs|) = 2P (T > 3.01) = 2 · 0.00415 = 0.0083

2 * (1 - pt(3.01, df = 15.99))

## [1] 0.0083089

Vurder evidencen (Tabel 3.1):

Der er stærk evidence imod nulhypotesen.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 27 / 49

Page 274: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for forskellen

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 28 / 49

Page 275: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for forskellen

Metode 3.47: Kondensinterval for µ1 − µ2

Kondensintervallet for middelforskelen bliver:

For two samples x1, . . . , xn and y1, . . . , yn the 100(1− α)% condenceinterval for µ1 − µ2 is given by

x− y ± t1−α/2 ·

√s21n1

+s22n2

where t1−α/2 is the 100(1− α/2)%-quantile from the t-distribution with νdegrees of freedom given from equation (3.26) (as above).

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 29 / 49

Page 276: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for forskellen

Kondensinterval og hypotesetest (Repetition)

Acceptområdet er de mulige værdier for µ som ikke ligger for langt væk fradata:

Acceptance

Rejection Rejection

x - t0.025s n x + t0.975s nx

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 30 / 49

Page 277: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for forskellen

Eksempel - energiforbrug - det hele i R:

Let us nd the 95% condence interval for µB − µA. Since the relevantt-quantile is, using ν = 15.99,

t0.975 = 2.120

the condence interval becomes:

10.298− 8.293± 2.120 ·√

2.0394

9+

1.954

9

which then gives the result as also seen above:

[0.59; 3.42]

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 31 / 49

Page 278: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for forskellen

Eksempel - energiforbrug - det hele i R:

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)

t.test(xB, xA)

##

## Welch Two Sample t-test

##

## data: xB and xA

## t = 3.01, df = 16, p-value = 0.0083

## alternative hypothesis: true difference in means is not equal to 0

## 95 percent confidence interval:

## 0.59228 3.41661

## sample estimates:

## mean of x mean of y

## 10.2978 8.2933

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 32 / 49

Page 279: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Overlappende kondensintervaller?

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 33 / 49

Page 280: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Overlappende kondensintervaller?

Eksempel - energiforbrug - Præsentation af resultat

Barplot med error bars ses ofte

Et grupperet barplot med nogle error bars - herunder er95%-kondensintervallerne for hver gruppe vist:

A B

02

46

810

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 34 / 49

Page 281: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Overlappende kondensintervaller?

Vær varsom med at bruge overlappendekondensintervaller

Man bruger ikke den rigtige variation til at vurdere forskellen:

Stand. dev. of (XA − XB) 6= Stand. dev. of XA + Stand. dev. of XB

Var (XA − XB) = Var (XA) + Var (XB)

Antag at de to standard-errors er 3 og 4: Summen er 7, men√

32 + 42 = 5

Det korrekte forhold mellem de to er således:

Stand. dev. of (XA − XB) < Stand. dev. of XA + Stand. dev. of XB

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 35 / 49

Page 282: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Overlappende kondensintervaller?

Vi bruger altid Welch' versionen

Nogenlunde sikkert at bruge Welch-versionen altid

if s21 = s22 the Welch and the Pooled test statistics are the same.

Only when the two variances become really dierent the twotest-statistics may dier in any important way, and if this is the case,we would not tend to favour the pooled version, since the assumptionof equal variances appears questionable then.

Only for cases with a small sample sizes in at least one of the twogroups the pooled approach may provide slightly higher power if youbelieve in the equal variance assumption. And for these cases theWelch approach is then a somewhat cautious approach.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 36 / 49

Page 283: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 37 / 49

Page 284: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Motiverende eksempel - sovemedicin

Forskel på sovemedicin?

I et studie er man interesseret i at sammenligne 2 sovemidler A og B. For10 testpersoner har man fået følgende resultater, der er givet i forlængetsøvntid (i timer) (Forskellen på eekten 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

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 38 / 49

Page 285: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Parret t-test

Vi betragter nu en situation hvor vi vil sammenligne 2 middelværdier,men hvor data er parret

Hypotesetestet foregår derfor ved at undersøge forskellen, Di, mellemde parrede observationer:

Di = Xi − Yi for i = 1, 2, ..., n

Vi kan herefter beregne middelværdi D og varians S2D for D. Test af D

gøres nu som de sædvanlige test for én middelværdi

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 39 / 49

Page 286: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Parret setup og analyse = one-sample analyse

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 = 4.67, df = 9, p-value = 0.0012

## alternative hypothesis: true mean is not equal to 0

## 95 percent confidence interval:

## 0.86133 2.47867

## sample estimates:

## mean of x

## 1.67

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 40 / 49

Page 287: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Parret setup og analyse = one-sample analyse

t.test(x2, x1, paired=TRUE)

##

## Paired t-test

##

## data: x2 and x1

## t = 4.67, df = 9, p-value = 0.0012

## alternative hypothesis: true difference in means is not equal to 0

## 95 percent confidence interval:

## 0.86133 2.47867

## sample estimates:

## mean of the differences

## 1.67

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 41 / 49

Page 288: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Parret versus independent eksperiment

Completely Randomized (independent samples)

20 patients are used and completely at random allocated to one of the twotreatments (but usually making sure to have 10 patients in each group).So: dierent persons in the dierent 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 surethat it becomes meaningful, and also one would typically make sure thatsome patients do A before B and others B before A. (and doing thisallocation at random). So: the same persons in the dierent groups.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 42 / 49

Page 289: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Eksempel - Sovemedicin - FORKERT analyse

t.test(x1,x2)

##

## Welch Two Sample t-test

##

## data: x1 and x2

## t = -1.93, df = 17.9, p-value = 0.069

## alternative hypothesis: true difference in means is not equal to 0

## 95 percent confidence interval:

## -3.48539 0.14539

## sample estimates:

## mean of x mean of y

## 0.66 2.33

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 43 / 49

Page 290: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Det parrede setup

Eksempel:

Test om der er forskel på nitrat udledningen til Skive fjord i 1999 og 2006.

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 44 / 49

Page 291: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumptions

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 45 / 49

Page 292: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumptions

Eksempel - Q-Q plot inden for hver stikprøve:

-1.5 -1.0 -0.5 0.0 0.5 1.0 1.5

67

89

10

11

Hospital A

Theoretical Quantiles

Sample

Quantiles

-1.5 -1.0 -0.5 0.0 0.5 1.0 1.5

910

11

12

Hospital B

Theoretical Quantiles

Sample

Quantiles

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 46 / 49

Page 293: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumptions

Styrke og stikprøvestørrelse - two-sample

Finding the power of detecting a group dierence of 2 with σ = 1 forn = 10:

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.98818

## alternative = two.sided

##

## NOTE: n is number in *each* group

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 47 / 49

Page 294: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumptions

Styrke og stikprøvestørrelse - two-sample

Finding the sample size for detecting a group dierence of 2 with σ = 1and power= 0.9:

power.t.test(power = 0.90, delta = 2, sd = 1, sig.level = 0.05)

##

## Two-sample t test power calculation

##

## n = 6.3868

## delta = 2

## sd = 1

## sig.level = 0.05

## power = 0.9

## alternative = two.sided

##

## NOTE: n is number in *each* group

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 48 / 49

Page 295: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Checking the normality assumptions

Oversigt

1 Checking the normality assumption

The Normal QQ plot

Transformation towards normality

2 Planlægning: Power og sample size

3 Two-sample t-test og p-værdi

4 Kondensinterval for forskellen

5 Overlappende kondensintervaller?

6 Det parrede setup

7 Checking the normality assumptions

Jan K. Møller ([email protected]) 02403, Forelæsning 6 Juni 2018 49 / 49

Page 296: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 7: Simuleringsbaseret statistik

Jan Kloppenborg Møller

DTU Compute, Dynamiske SystemerBygning 303B, Rum 007Danmarks Tekniske Universitet2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 1 / 55

Page 297: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Introduktion til simulationHvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrapIntroduction to bootstrapOne-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelseTwo-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrapOne-sample kondensinterval for en vilkårlig størrelseOne-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 2 / 55

Page 298: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation

Oversigt

1 Introduktion til simulation

Hvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrap

Introduction to bootstrap

One-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelse

Two-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrap

One-sample kondensinterval for en vilkårlig størrelse

One-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 3 / 55

Page 299: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation

Motivation

Mange relevant beregningsstørrelser ("computed features") harkomplicerede samplingfordelinger:

Et trimmed gennemsnitMedianenFraktiler generelt, dvs. f.eks. også IQR= Q3 −Q1

VariationkoecientenEnhver ikke-lineær function af en eller ere input variable(Spredningen)

Data/populations fordelingen kan være ikke-normal, hvilketkomplicerer den statistiske teori for selv en simpelgennemsnitsberegning

Vi kan HÅBE på the magic of CLT (Central Limit Theorem)

MEN men: Vi kan aldrig være helt sikre på om det er godt nok -simulering kan gøre os mere sikre!

Kræver: Brug af computer - R er et super værktøj til dette!

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 4 / 55

Page 300: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation Hvad er simulering egentlig?

Hvad er simulering egentlig?

(Pseudo)tilfældige tal genereret af en computer

En tilfældighedsgenerator er en algoritme der kan generere xi+1 ud fraxi

En sekvens af tal "ser tilfældige ud

Kræver en "start - kaldet "seed .(Bruger typisk uret i computeren)

Grundlæggende simuleres den uniforme fordeling, og så bruges:

Hvis U ∼ Uniform(0, 1) og F er en fordelingsfunktion for en eller andensandsynlighedsfordeling, så vil F−1(U) følge fordelingen givet ved F

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 5 / 55

Page 301: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation Hvad er simulering egentlig?

I praksis i R

De forskellige fordelinger er gjort klar til simulering:

rbinom Binomialfordelingenrpois Poissonfordelingenrhyper Den hypergeometriske fordelingrnorm Normalfordelingenrlnorm Lognormalfordelingenrexp Eksponentialfordelingenrunif Den uniforme(lige) fordelingrt t-fordelingenrchisq χ2-fordelingenrf F-fordelingen

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 6 / 55

Page 302: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation Hvad er simulering egentlig?

The simulation approach has a number of crucial advantages:1 It oers a simple tool to compute many other quantities than just the

standard deviation (the theoretical derivations of such other quantitiescould be much more complicated than what was shown for thevariance here)

2 It oers a simple tool to use any other distribution than the normal, ifwe believe such better reect reality.

3 It does not rely on any linear approximations of the true non-linearrelations.

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 7 / 55

Page 303: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation Hvad er simulering egentlig?

Eksempel 5, Areal af plader:

En virksomhed producerer rektangulære plader. Længden af pladerne (imeter), X, antages at kunne beskrives med en normalfordeling N(2, 0.012)og bredden af pladerne (i meter), Y , antages at kunne beskrives med ennormalfordeling N(3, 0.022). Man er interesseret i arealet, som jo så givetved A = XY .

Hvad er middelarealet?

Hvad er spredningen i arealet fra plade til plade?

Hvor ofte sådanne plader har et areal, der afviger mere end 0.1m2 frade 6m2?

Sandsynligheden for andre mulige hændelser?

Generelt: Hvad er sandsynlighedsfordelingen for A?

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 8 / 55

Page 304: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Introduktion til simulation Hvad er simulering egentlig?

Fejlophobning - ved simulering

Method 4.4: Error propagation by simulation

Assume that X1, . . . , Xn follow som distribution e.g. N(µi, σi)1 Simulate k outcomes of all n random variables from the assumed

distributions.2 Calculate the standard deviation directly as the observed standard

deviation of the k simulated values of f :

ssimf(X1,...,Xn)=

√√√√ 1

k − 1

k∑i=1

(fj − f)2

wherefj = f(X

(j)1 , . . . , X(j)

n )

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 9 / 55

Page 305: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Oversigt

1 Introduktion til simulation

Hvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrap

Introduction to bootstrap

One-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelse

Two-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrap

One-sample kondensinterval for en vilkårlig størrelse

One-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 10 / 55

Page 306: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Fejlophobningslove

Antag at Xi er stokastiske variable med E(Xi) = µi og V (Xi) = σ2i ogCov(Xi, Xj) = σij

Har brug for at nde:

σ2f(X1,...,Xn)= Var(f(X1, . . . , Xn))

(Generalisering af) Method 4.3: for ikke-lineære funktioner:

σ2f(X1,...,Xn)≈

n∑i=1

(∂f

∂xi

)2

σ2i + 2∑i

∑j>i

∂f

∂xi

∂f

∂xjσij

Hvor de aedte af f evalueres i µ1, ..., µn.Læg mærke til at hvis X1, ..., Xn uafhængige fås (Method 4.3)

σ2f(X1,...,Xn)≈

n∑i=1

(∂f

∂xi

)2

σ2i

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 11 / 55

Page 307: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Fejlophobning ved Taylorudvikling

Lad f(X1, . . . , Xn) være en ikke-lineær funktion af de stokastiske variableX1, ..., Xn.Vi tager nu første ordens Taylor udviklingen omkringµ = [E(X1), ..., E(Xn)]T

f(x1, . . . , xn) =f(µ) +

n∑i=1

∂f

∂xi

∣∣∣∣x=µ

(xi − µi) +HOT

≈f(µ) +

n∑i=1

∂f

∂xi

∣∣∣∣x=µ

(xi − µi)

Dermed har vi

f(X1, . . . , Xn) ≈f(µ) +

n∑i=1

∂f

∂xi

∣∣∣∣x=µ

(Xi − µi)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 12 / 55

Page 308: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Fejlophobning ved Taylorudvikling - Fortsat

Tag nu forventningsværdien

E[f(X1, . . . , Xn)] ≈E[f(µ)] +

n∑i=1

∂f

∂xi

∣∣∣∣x=µ

E[Xi − µi]

=f(µ)

Dermed har vi

f(X)− E[f(X)] ≈n∑i=1

∂f

∂xi

∣∣∣∣x=µ

(Xi − µi)

Vi kan nde variansen af f(X), V [f(X)] = E[(f(X)− E[f(X)])2]

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 13 / 55

Page 309: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Fejlophobning ved Taylorudvikling - Fortsat

Vi kan nu tage variansen af f(X), V [f(X)] = E[(f(X)− E[f(X)])2]

V [f(X)] ≈E

( n∑i=1

∂f

∂xi

∣∣∣∣x=µ

(Xi − µi)

)2

=

n∑i=1

(∂f

∂xi

∣∣∣∣x=µ

)2

E[(Xi − µi)2

]+

∑i 6=j

(∂f

∂xi

∂f

∂xj

) ∣∣∣∣x=µ

E [(Xi − µi)(Xj − µj)]

=

n∑i=1

(∂f

∂xi

∣∣∣∣x=µ

)2

σ2i + 2

n∑i=1

∑j>i

(∂f

∂xi

∂f

∂xj

) ∣∣∣∣x=µ

σij

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 14 / 55

Page 310: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Varians af BMI

Body Mass Index er deneret ved

BMI =V

H2

hvor V er en persons vægt (kg), mens H er personens højde (m). Antagnu at kender kender en populations middelhøjde og middelvægt (µV , ogµH), samt varians- kovariansmatricen for vægt og højde (σV , σH og σV H).

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 15 / 55

Page 311: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Varians af BMI

Find (en approksimation til) middel BMI og varians for denne

E[BMI] ≈µVµ2H

V [BMI] ≈(∂BMI

∂V

)2

σ2V +

(∂BMI

∂H

)2

σ2H + 2

(∂BMI

∂H

∂BMI

∂V

)σV H

=

(1

µ2H

)2

σ2V +

(−2

µVµ3H

)2

σ2H + 2

(−2

µVµ3H

1

µ2H

)σV H

=σ2Vµ4H

+4µ2V σ

2H

µ6H− 4µV σV H

µ5H

=1

µ4H

(σ2V +

4µ2V σ2H

µ2H− 4µV σV H

µH

)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 16 / 55

Page 312: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Eksempel 1, fortsat

Varianserne er:

σ21 = V ar(X) = 0.012 og σ22 = V ar(Y ) = 0.022

Funktionen og de aedede er:

f(x, y) = xy,∂f

∂x= y,

∂f

∂y= x

Så resultatet bliver:

V ar(A) ≈(∂f

∂x

)2

σ21 +

(∂f

∂y

)2

σ22

= µ2yσ21 + µ2xσ

22

= 3.002 · 0.012 + 2.002 · 0.022

= 0.0025Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 17 / 55

Page 313: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Eksempel 1, fortsat

Faktisk kan man nde variansen for A = XY teoretisk:

Var(XY ) = E[(XY )2

]− [E(XY )]2

= E(X2)E(Y 2)− E(X)2E(Y )2

=[Var(X) + E(X)2

] [Var(Y ) + E(Y )2

]− E(X)2E(Y )2

= Var(X)Var(Y ) + Var(X)E(Y )2 + Var(Y )E(X)2

= 0.012 × 0.022 + 0.012 × 32 + 0.022 × 22

= 0.00000004 + 0.0009 + 0.0016

= 0.00250004

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 18 / 55

Page 314: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Fejlophobningslove

Areal-eksempel et summary

Tre forskellige approaches:1 Simuleringsbaseret2 Teoretisk udledning3 Den analytiske, men approksimative, error propagation metode

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 19 / 55

Page 315: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap

Oversigt

1 Introduktion til simulation

Hvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrap

Introduction to bootstrap

One-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelse

Two-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrap

One-sample kondensinterval for en vilkårlig størrelse

One-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 20 / 55

Page 316: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap Introduction to bootstrap

Bootstrapping

Bootstrapping ndes i to versioner:1 Parametrisk bootstrap: Simuler gentagne samples fra den antagede

(og estimerede) fordeling.2 Ikke-parametrisk bootstrap: Simuler gentagne samples direkte fra data.

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 21 / 55

Page 317: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for µ

Eksempel: Kondensinterval for middelværdien i eneksponentialfordeling

Antag at vi har observeret følgende 10 opkaldsventetider (i sekunder) i etcall center:

32.6, 1.6, 42.1, 29.2, 53.4, 79.3, 2.3, 4.7, 13.6, 2.0

Vi estimerer fra data:

µ = x = 26.08 og dermed er raten: λ = 1/26.08 = 0.03834356

Antagelse:

Xi ∼ Exp(λ)

Hvad er kondensintervallet for µ?

Lille stikprøve og ikke normalfordelt, dvs. vores antagelser holder ikke.

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 22 / 55

Page 318: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for µ

Kondensinterval for en vilkårlig beregningsstørrelse

Method 4.7: Condence interval for any feature θ by parametric bootstrap

Assume we have actual observations x1, . . . , xn and assume that they stemfrom some probability distribution with density f .

1 Simulate k samples of n observations from the assumed distribution fwhere the mean a is set to x.

2 Calculate the statistic θ in each of the k samples θ∗1, . . . , θ∗k.

3 Find the 100(α/2)% and 100(1− α/2)% quantiles for these,q∗100(α/2)% and q∗100(1−α/2)% as the 100(1− α)% condence interval:[q∗100(α/2)%, q

∗100(1−α/2)%

]aAnd in some cases more quantities e.g. mean and variance (normal

distribution)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 23 / 55

Page 319: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for µ

Og fodnoten...

And otherwise chosen to match the data as good as possible:

Some distributions have more than just a single mean relatedparameter.

The normal or the log-normal. For these one should use a distributionwith a variance that matches the sample variance of the data.

Even more generally the approach would be to match the chosendistribution to the data by the so-called maximum likelihood approach

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 24 / 55

Page 320: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for µ

Eksempel: Kondensinterval for middelværdien i eneksponentialfordeling

## Set the number of simulations:

k <- 100000

## 1. Simulate 10 exponentials with the right mean k times:

set.seed(9876)

simSamples <- replicate(k, rexp(10, 1/26.08))

## 2. Compute the mean of the 10 simulated observations k times:

simMeans <- apply(simSamples, 2, mean)

## 3. Find the two relevant quantiles of the k simulated means:

quantile(simMeans, c(0.025, 0.975))

## 2.5% 97.5%

## 12.587 44.627

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 25 / 55

Page 321: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for µ

Example: Kondensinterval for middelværdien i eneksponentialfordeling

Histogram of simMeans

simMeans

Frequency

20 40 60 80

02000

4000

6000

8000

10000

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 26 / 55

Page 322: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for en vilkårlig størrelse

Eksempel: Kondensinterval for medianen i eneksponentialfordeling

Antag at vi har observeret følgende 10 opkaldsventetider (i sekunder) i etcall center:

32.6, 1.6, 42.1, 29.2, 53.4, 79.3, 2.3, 4.7, 13.6, 2.0

Vi estimerer fra data:

Median = 21.4 og µ = x = 26.08

Antagelse:

Xi ∼ Exp(λ)

Hvad er kondensintervallet for medianen?

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 27 / 55

Page 323: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for en vilkårlig størrelse

Eksempel: Kondensinterval for medianen i eneksponentialfordeling

## Beregn konfidensinterval for middelværdien med parametrisk bootstrapping

## Set the number of simulations:

k <- 100000

## 1. Simulate 10 exponentials with the right mean k times:

set.seed(9876)

simSamples <- replicate(k, rexp(10, 1/26.08))

## 2. Compute the median of the n=10 simulated observations k times:

simmedians <- apply(simSamples, 2, median)

## 3. Find the two relevant quantiles of the k simulated medians:

quantile(simmedians, c(0.025, 0.975))

## 2.5% 97.5%

## 7.038 38.465

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 28 / 55

Page 324: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for en vilkårlig størrelse

Eksempel: Kondensinterval for medianen i eneksponentialfordeling

Histogram of simmedians

simmedians

Frequency

0 20 40 60 80

02000

4000

6000

8000

10000

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 29 / 55

Page 325: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap One-sample kondensinterval for en vilkårlig størrelse

Et andet eksempel: 99% kondensinterval for Q3 for ennormalfordeling

## Konfidensinterval for den øvre kvartil (Q_3) i en normalfordeling

## Read in the heights data:

x <- c(168, 161, 167, 179, 184, 166, 198, 187, 191, 179)

n <- length(x)

## Set the number of simulations:

k <- 100000

## 1. Simulate k samples of n=10 normals with the right mean and variance:

set.seed(9876.543)

simSamples <- replicate(k, rnorm(n, mean(x), sd(x)))

## 2. Compute the Q3 of the n=10 simulated observations k times:

simQ3s <- apply(simSamples, 2, quantile, prob = 0.75)

## 3. Find the two relevant quantiles of the k simulated medians:

quantile(simQ3s, c(0.005, 0.995))

## 0.5% 99.5%

## 172.82 198.00

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 30 / 55

Page 326: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap Two-sample kondensintervaller for en vilkårlig fordeling

Two-sample kondensinterval for en vilkårlig featuresammenligning θ1 − θ2 (inkl. µ1 − µ2)

Method 4.10: Two-sample condence interval for any feature comparisonθ1 − θ2 by parametric bootstrap

Assume we have actual observations x1, . . . , xn1 and y1, . . . , yn1 andassume that they stem from some probability distributions with density f1and f2.

1 Simulate k sets of 2 samples of n1 and n2 observations from theassumed distributions setting the means a to µ1 = x and µ2 = y,respectively.

2 Calculate the dierence between the features in each of the k samplesθ∗x1 − θ∗y1, . . . , θ∗xk − θ∗yk.

3 Find the 100(α/2)% and 100(1− α/2)% quantiles for these,q∗100(α/2)% and q∗100(1−α/2)% as the 100(1− α)% condence interval:[q∗100(α/2)%, q

∗100(1−α/2)%

]aAs before

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 31 / 55

Page 327: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap Two-sample kondensintervaller for en vilkårlig fordeling

Eksempel: Kondensinterval for the forskellen mellem toexponentielle middelværdier

## Konfidensinterval for the forskellen mellem to exponentielle middelværdier

## Day 1 data:

x <- c(32.6, 1.6, 42.1, 29.2, 53.4, 79.3,

2.3 , 4.7, 13.6, 2.0)

## Day 2 data:

y <- c(9.6, 22.2, 52.5, 12.6, 33.0, 15.2,

76.6, 36.3, 110.2, 18.0, 62.4, 10.3)

## Keep sample sizes

n1 <- length(x)

n2 <- length(y)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 32 / 55

Page 328: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Parametric bootstrap Two-sample kondensintervaller for en vilkårlig fordeling

Parametrisk bootstrap - et overblik

Vi antager en eller anden fordeling!

To kondensinterval-metodeboxe blev givet:

One-sample Two-sample

For any feature Method 4.7 Method 4.10

Parret / ikke parret situationer behandles/bestemmes somfor den sædvanlige t-test.

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 33 / 55

Page 329: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap

Oversigt

1 Introduktion til simulation

Hvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrap

Introduction to bootstrap

One-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelse

Two-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrap

One-sample kondensinterval for en vilkårlig størrelse

One-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 34 / 55

Page 330: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap

Ikke-parametrisk bootstrap - et overblik

Vi antager IKKE noget om nogen fordelinger!

To kondensinterval-metodeboxe bliver givet:

One-sample Two-sample

For any feature Method 4.15 Method 4.17

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 35 / 55

Page 331: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap One-sample kondensinterval for en vilkårlig størrelse

One-sample kondensinterval for en vilkårlig feature θ (inkl.µ)

Method 4.15: Condence interval for any feature θ by non-parametricbootstrap

Assume we have actual observations x1, . . . , xn.1 Simulate k samples of size n by randomly sampling among the

available data (with replacement)2 Calculate the statistic θ in each of the k samples θ∗1, . . . , θ

∗k.

3 Find the 100(α/2)% and 100(1− α/2)% quantiles for these,q∗100(α/2)% and q∗100(1−α/2)% as the 100(1− α)% condence interval:[q∗100(α/2)%, q

∗100(1−α/2)%

]

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 36 / 55

Page 332: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap One-sample kondensinterval for µ

Eksempel: Kvinders cigaretforbrug

I et studie undersøgte man kvinders cigaretforbrug før og efter fødsel. Mank følgende observationer af antal cigaretter pr. dag:

før efter før efter8 5 13 1524 11 15 197 0 11 1220 15 22 06 0 15 620 20

Sammenlign før og efter! Er der sket nogen ændring i gennemsnitsforbruget!

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 37 / 55

Page 333: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap One-sample kondensinterval for µ

Eksempel: Kvinders cigaretforbrug

Et parret t-test setup, MEN med tydeligvis ikke-normale data!

## Parret test af middelværdiforskel med ikke-parametrisk bootstrapping

## Input the two cigaret use samples

x1 <- c(8, 24, 7, 20, 6, 20, 13, 15, 11, 22, 15)

x2 <- c(5, 11, 0, 15, 0, 20, 15, 19, 12, 0, 6)

## Calculate the difference

dif <- x1 - x2

dif

## [1] 3 13 7 5 6 0 -2 -4 -1 22 9

## And the sample mean

mean(dif)

## [1] 5.2727

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 38 / 55

Page 334: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap One-sample kondensinterval for µ

Eksempel: Kvinders cigaretforbrug - bootstrapping

## Resample from the dif sample

t(replicate(5, sample(dif, replace = TRUE)))

## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]

## [1,] -4 0 0 -4 6 0 5 0 22 0 0

## [2,] 3 0 6 -1 7 -1 -1 -2 -4 -4 22

## [3,] 3 5 7 7 13 9 0 22 6 -1 9

## [4,] 13 13 5 9 -4 -1 7 3 13 22 -4

## [5,] 9 -1 6 22 9 -4 13 -4 7 3 22

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 39 / 55

Page 335: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap One-sample kondensinterval for µ

Eksempel: Kvinders cigaretforbrug - de ikke-parametriskbootstrap resultater:

## Resample many time

k = 100000

simSamples = replicate(k, sample(dif, replace = TRUE))

## Take the mean for every resample

simMeans = apply(simSamples, 2, mean)

## Take the two quantiles to get the confidence interval

quantile(simMeans, c(0.025,0.975))

## 2.5% 97.5%

## 1.3636 9.7273

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 40 / 55

Page 336: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap One-sample kondensinterval for µ

Eksempel: Kvinders cigaretforbrug

Lad os nde 95% kondensintervallet for ændringen af mediancigaretforbruget

## Simulate many times

k = 100000

simsamples = replicate(k, sample(dif, replace = TRUE))

## Take the median for each resample

simmedians = apply(simsamples, 2, median)

## Take the two quantiles to get the confidence interval

quantile(simmedians, c(0.025,0.975))

## 2.5% 97.5%

## -1 9

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 41 / 55

Page 337: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap Two-sample kondensintervaller

Eksempel: Tandsundhed og askebrug

I et studie ville man undersøge, om børn der havde fået mælk fra askesom barn havde dårligere eller bedre tænder end dem, der ikke havde fåetmælk fra aske. Fra 19 tilfældigt udvalgte børn registrerede man hvornår dehavde haft deres første tilfælde af karies.

aske alder aske alder aske aldernej 9 nej 10 ja 16ja 14 nej 8 ja 14ja 15 nej 6 ja 9nej 10 ja 12 nej 12nej 12 ja 13 ja 12nej 6 nej 20ja 19 ja 13

Find kondensintervallet for forskellen!

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 42 / 55

Page 338: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap Two-sample kondensintervaller

Two-sample kondensinterval for θ1 − θ2 (inkl. µ1 − µ2)med ikke-parametrisk bootstrap

Method 4.17: Two-sample condence interval for θ1− θ2 by non-parametricbootstrap

Assume we have actual observations x1, . . . , xn and y1, . . . , yn.1 Simulate k sets of 2 samples of n1 and n2 observations from the

respective groups (with replacement)2 Calculate the dierence between the features in each of the k samplesθ∗x1 − θ∗y1, . . . , θ∗xk − θ∗yk.

3 Find the 100(α/2)% and 100(1− α/2)% quantiles for these,q∗100(α/2)% and q∗100(1−α/2)% as the 100(1− α)% condence interval:[q∗100(α/2)%, q

∗100(1−α/2)%

]

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 43 / 55

Page 339: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Ikke-parametrisk bootstrap Two-sample kondensintervaller

Bootstrapping - et overblik

Vi har fået 4 ikke så forskellige metode-bokse1 Med eller uden fordeling (parametrisk eller ikke-parametrisk)2 For one- eller two-sample analyse (en eller to grupper)

Bemærk:

Middelværdier(means) er inkluderet i vilkårlige beregningsstørrelser (otherfeatures). Eller: Disse metoder kan også anvendes for andre analyser endfor means!

Hypotesetest også muligt

Vi kan udføre hypotese test ved at kigge på kondensintervallerne!

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 44 / 55

Page 340: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Oversigt

1 Introduktion til simulation

Hvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrap

Introduction to bootstrap

One-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelse

Two-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrap

One-sample kondensinterval for en vilkårlig størrelse

One-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 45 / 55

Page 341: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Nøgletal (summary statistics)

Vi anvender en række nøgletal (eller statistikker) for at opsummere ogbeskrive data (og stokastiske variable)

Gennemsnit: tyngdepunkt eller centrering

Median: tyngdepunkt eller centrering

Varians: variation

Spredning: variation (samme enhed som data)

Variations koecient: variationen i data (enhedsløs)

Kovarians: samvariation mellem datasæt

Korrelation: samvariation mellem datasæt (enhedsløs)

Fraktiler: siger noget om fordelingen af data

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 46 / 55

Page 342: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Grask Fremstilling

Histogram

Empirisk kumulativ tæthedsfunktion

Boxplot

Scatterplot

qqplot

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 47 / 55

Page 343: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Stokastiske variable

Tæthedsfunktioner (f(x))

Sandynligheder (∑f(x) eller

∫f(x)dx)

Middelværdi (e.g. µ =∫xf(x)dx)

Varians (e.g. σ2 =∫

(x− µ)2f(x)dx)

Kovarians og korrelation

Konkrete fordelinger (e.g. Binomial, Normal, log-normal,...)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 48 / 55

Page 344: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Funktioner af stokastiske variable

Simulation (e.g. X og Y ∼ N(µ, σ2), P (X · Y > c))

Error propagation (Taylor omkring E(Xi) plus middelværdi ogvarians/kovarians regneregler)Xi ∼ N(µ1, σ

21), Yi ∼ N(µ2, σ

22)

Fordeling af gennemsnit (normalfordeling)Fordeling af varians estimator (χ2-fordeling)Fordeling af standardliseret gennemsnit (t-fordeling)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 49 / 55

Page 345: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Normal fordelingen

En standard normal fordeling:

Z ∼ N(0, 12)

En normalfordeling med middelværdi 0 og varians 1.

Standardisering:

En vilkårlig normal fordelt variabel X ∼ N(µ, σ2) kan standardiseres ved atberegne

Z =X − µσ

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 50 / 55

Page 346: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Fordeling for gennemsnit af normalfordelinger (Theorem 3.2)

(Stikprøve-) fordelingen/ The (sampling) distribution for X

Assume that X1, . . . , Xn are independent and identically normallydistributed random variables, Xi ∼ N(µ, σ2), i = 1, . . . , n, then:

X =1

n

n∑i=1

Xi ∼ N(µ,σ2

n

)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 51 / 55

Page 347: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Fordeling af varians estimator

Hvis X1, . . . , Xn er i.i.d. N(µ, σ2), og lad X, S2 være hhv. gennemsnit ogempirisk varians. Så gælder der at

1

σ2

n∑i=1

(Xi − µ)2 =(n− 1)S2

σ2+

(X − µσ/√n

)2

og det følger at

(n− 1)S2

σ2∼ χ2(n− 1)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 52 / 55

Page 348: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

t-fordelingen som stikprøvefordeling

Lad X1, . . . , Xn være i.i.d. ∼ N(µ, σ2) så følger

T =X − µ√S2/n

(1)

en t-fordeling med n− 1 frihedsgrader.

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 53 / 55

Page 349: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Hypotesetest og kondensintervaller

Xi ∼ N(µ, σ2):

tobs =x− µ0s/√n

=observeret− hypotese

std(obs)

Under H0

T =X − µ0S/√n∼ t

E.g.p.value = 2P (T > |tobs|)

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 54 / 55

Page 350: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Første del af kurset

Oversigt

1 Introduktion til simulationHvad er simulering egentlig?

2 Fejlophobningslove

3 Parametric bootstrapIntroduction to bootstrapOne-sample kondensinterval for µOne-sample kondensinterval for en vilkårlig størrelseTwo-sample kondensintervaller for en vilkårlig fordeling

4 Ikke-parametrisk bootstrapOne-sample kondensinterval for en vilkårlig størrelseOne-sample kondensinterval for µTwo-sample kondensintervaller

5 Første del af kurset

Jan K. Møller ([email protected]) 02403, Forelæsning 7 Juni 2018 55 / 55

Page 351: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 8: Simpel lineær regression

Jan Kloppenborg Møller

DTU Compute, Dynamiske SystemerBygning 303B, Rum 007Danmarks Tekniske Universitet2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 1 / 44

Page 352: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 2 / 44

Page 353: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel: Højde-vægt

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 3 / 44

Page 354: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel: Højde-vægt

Heights (xi) 168 161 167 179 184 166 198 187 191 179Weights (yi) 65.5 58.3 68.1 85.7 80.5 63.4 102.6 91.4 86.7 78.9

160 170 180 190

6070

8090

100

Height

Wei

ght

1

2

3

4

5

6

7

8

9

10

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 4 / 44

Page 355: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel: Højde-vægt

Heights (xi) 168 161 167 179 184 166 198 187 191 179Weights (yi) 65.5 58.3 68.1 85.7 80.5 63.4 102.6 91.4 86.7 78.9

160 170 180 190

6070

8090

100

Height

Wei

ght

1

2

3

4

5

6

7

8

9

10

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 5 / 44

Page 356: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel: Højde-vægt

Heights (xi) 168 161 167 179 184 166 198 187 191 179Weights (yi) 65.5 58.3 68.1 85.7 80.5 63.4 102.6 91.4 86.7 78.9

##

## Call:

## lm(formula = y ~ x)

##

## Residuals:

## Min 1Q Median 3Q Max

## -5.876 -1.451 -0.608 2.234 6.477

##

## Coefficients:

## Estimate Std. Error t value Pr(>|t|)

## (Intercept) -119.958 18.897 -6.35 0.00022 ***

## x 1.113 0.106 10.50 5.9e-06 ***

## ---

## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

##

## Residual standard error: 3.88 on 8 degrees of freedom

## Multiple R-squared: 0.932,Adjusted R-squared: 0.924

## F-statistic: 110 on 1 and 8 DF, p-value: 5.87e-06

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 6 / 44

Page 357: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Motiverende eksempel: Højde-vægt

Heights (xi) 168 161 167 179 184 166 198 187 191 179Weights (yi) 65.5 58.3 68.1 85.7 80.5 63.4 102.6 91.4 86.7 78.9

160 170 180 190

6070

8090

100

Height

Wei

ght

1

2

3

4

5

6

7

8

9

10

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 7 / 44

Page 358: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Lineær regressionsmodel

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 8 / 44

Page 359: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Lineær regressionsmodel

Opstil en lineær regressionsmodel

Opstil den lineære regressionsmodel

Yi = β0 + β1xi + εi

Yi er den afhængige variabel (dependent variable). En stokastisk

variabel.

xi er en forklarende variabel (explanatory variable)

εi er afvigelsen (error). En stokastisk variabel.

og vi antager

εi er independent and identically distributed (i.i.d.) og N(0, σ2)

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 9 / 44

Page 360: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Lineær regressionsmodel

Model-illustration

−1 0 1 2 3

−20

00

200

400

600

800

x

y

σ

β0 + β1x

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 10 / 44

Page 361: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Mindste kvadraters metode (least squares)

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 11 / 44

Page 362: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Mindste kvadraters metode (least squares)

Mindste kvadraters metode

Minimer variansen σ2 på afvigelsen. Det er på næsten alle måder det

bedste valg i dette setup.

Formelt: Minimer summen af de kvadrerede afvigelser (Residual Sum

of Squares (RSS ))

RSS (β0, β1) =

n∑i=1

ε2i =

n∑i=1

(yi − (β0 + β1xi))2

β0 og β1 minimerer RSS

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 12 / 44

Page 363: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Mindste kvadraters metode (least squares)

Illustration af model, data og t

−1 0 1 2 3

−20

00

200

400

600

800

x

y

σ

β0 + β2x

β0 + β1x

εi = ei

data punkterlineaer modellineaer fit

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 13 / 44

Page 364: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Mindste kvadraters metode (least squares)

Least squares estimator

Theorem 5.4 (her for estimatorer som i eNoten)

The least squares estimators of β0 and β1 are given by

β1 =

∑ni=1(Yi − Y )(xi − x)

Sxx

β0 =Y − β1x

where Sxx =∑n

i=1(xi − x)2.

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 14 / 44

Page 365: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Mindste kvadraters metode (least squares)

Least squares estimater

Theorem 5.4 (her for estimater)

The least squares estimatates of β0 and β1 are given by

β1 =

∑ni=1(yi − y)(xi − x)

Sxx

β0 =y − β1x

where Sxx =∑n

i=1(xi − x)2.

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 15 / 44

Page 366: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistik og lineær regression

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 16 / 44

Page 367: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistik og lineær regression

Hvordan er parameter estimaterne i en lineær regressionsmodel fordelt

(givet normalfordelte afvigelser)?

De er normalfordelte og deres varians kan estimeres:

Theorem 5.8 (første del)

V [β0] =σ2

n+x2σ2

Sxx

V [β1] =σ2

Sxx

Cov[β0, β1] = − xσ2

Sxx

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 17 / 44

Page 368: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Statistik og lineær regression

Estimater af standard afvigelserne på β0 og β1

Theorem 5.8 (anden del)

Where σ2 is usually replaced by its estimate (σ2). The central estimator for

σ2 is

σ2 =RSS(β0, β1)

n− 2=

∑ni=1 e

2i

n− 2.

When the estimate of σ2 is used the variances also become estimates and

we'll refer to them as σ2β0 and σ2β1 .

Estimat af standard afvigelserne for β0 og β1 (ligningerne (5-73))

σβ0 = σ

√1

n+

x2

Sxx; σβ1 = σ

√1∑n

i=1(xi − x)2

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 18 / 44

Page 369: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetests og kondensintervaller for β0 og β1

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 19 / 44

Page 370: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetests og kondensintervaller for β0 og β1

Hypotesetests for parameter estimaterne

Vi kan altså udføre hypotesetests for parameter estimater i en lineær

regressionsmodel:

H0,i : βi = β0,i

H1,i : βi 6= β1,i

Vi bruger de t-fordelte statistikker:

Theorem 5.12

Under the null-hypothesis (β0 = β0,0 and β1 = β0,1) the statistics

Tβ0=β0 − β0,0σβ0

; Tβ1=β1 − β0,1σβ1

,

are t-distributed with n− 2 degrees of freedom, and inference should be based onthis distribution.

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 20 / 44

Page 371: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetests og kondensintervaller for β0 og β1

Kondensintervaller for parametrene

Method 5.15

(1− α) condence intervals for β0 and β1 are given by

β0 ± t1−α/2 σβ0β1 ± t1−α/2 σβ1

where t1−α/2 is the (1− α/2)-quantile of a t-distribution with n− 2degrees of freedom.

husk at σβ0 og σβ1 ndes ved ligningerne (5-74)

i R kan σβ0 og σβ1 aæses ved "Std. Error" ved "summary(t)"

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 21 / 44

Page 372: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og prædiktionsinterval

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 22 / 44

Page 373: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og prædiktionsinterval Kondensinterval for linien

Method 5.18: Kondensinterval for β0 + β1x0

Kondensinterval for β0 + β1x0 svarer til et kondensinterval for linien

i punktet x0

Beregnes med

(β0 + β1x0)± tα/2 · σ

√1

n+

(x0 − x)2

Sxx

Kondensintervallet vil i 100(1− α)% af gangene indeholde den

rigtige linie, altså β0 + β1x0

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 23 / 44

Page 374: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og prædiktionsinterval Prædiktionsinterval

Method 5.18: Prædiktionsinterval for β0 + β1x0 + ε0

Prædiktionsintervallet (prediction interval) for Y0 beregnes med en

værdi x0

Dette gøres før Y0 observeres med

(β0 + β1x0)± tα/2 · σ

√1 +

1

n+

(x0 − x)2

Sxx

Prædiktionsintervallet vil 100(1− α)% af gangene indeholde den

observerede y0

Et prædiktionsinterval bliver altså større end et kondensinterval for

fastholdt α

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 24 / 44

Page 375: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og prædiktionsinterval Prædiktionsinterval

Eksempel med kondensinterval for linien

## Eksempel med konfidensinterval for linien

## Lav en sekvens af x værdier

xval <- seq(from=-2, to=6, length.out=100)

## Brug predict funktionen

CI <- predict(fit, newdata=data.frame(x=xval),interval="confidence",level=.95)

## Se lige hvad der kom

head(CI)

## Plot data, model og intervaller

plot(x, y, pch=20)abline(fit)lines(xval, CI[, "lwr"], lty=2, col="red", lwd=2)lines(xval, CI[, "upr"], lty=2, col="red", lwd=2)

−1 0 1 2 3

−20

00

200

400

600

800

x

y

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 25 / 44

Page 376: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og prædiktionsinterval Prædiktionsinterval

Eksempel med prædiktionsinterval

## Eksempel med prædiktionsinterval

## Lav en sekvens a x værdier

xval <- seq(from=-2, to=6, length.out=100)

## Beregn interval for hvert x

PI <- predict(fit, newdata=data.frame(x=xval),interval="prediction",level=.95)

## Se lige hvad der kom tilbage

head(PI)

## Plot data, model og intervaller

plot(x, y, pch=20)abline(fit)lines(xval, PI[, "lwr"], lty=2, col="blue", lwd=2)lines(xval, PI[, "upr"], lty=2, col="blue", lwd=2)

−1 0 1 2 3

−20

00

200

400

600

800

x

y

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 26 / 44

Page 377: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Linear regression: matrix formuleringen

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 27 / 44

Page 378: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Linear regression: matrix formuleringen

Matrix formulering

The simple linear regression problem can be formulated in vector-matrix

notation as

Y =Xβ + ε; ε ∼ N(0, σ2I)

or Y1...Yn

=

1 x1...

...

1 xn

[β0β1

]+

ε1...εn

; εi ∼ N(0, σ2)

RSS in Matrix-vector notation

RSS =εT ε = (Y −Xβ)T (Y −Xβ)

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 28 / 44

Page 379: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Linear regression: matrix formuleringen

Matrix formulering: Parameter estimater

The estimators of the parameters in the simple linear regression model are

given by

β = (XTX)−1XTY (1)

and the covariance matrix of the estimates is

V [β] = σ2(XTX)−1 (2)

and central estimate for the residual variance is

σ2 =RSS

n− 2(3)

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 29 / 44

Page 380: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Korrelation

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 30 / 44

Page 381: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Korrelation

Hvad bliver mere skrevet ud af summary?

summary(fit)

##

## Call:

## lm(formula = y ~ x)

##

## Residuals:

## Min 1Q Median 3Q Max

## -119.70 -23.74 -4.15 22.44 172.64

##

## Coefficients:

## Estimate Std. Error t value Pr(>|t|)

## (Intercept) 68.2 17.5 3.9 0.001 **

## x 182.6 11.4 16.0 4.2e-12 ***

## ---

## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

##

## Residual standard error: 67.4 on 18 degrees of freedom

## Multiple R-squared: 0.935,Adjusted R-squared: 0.931

## F-statistic: 257 on 1 and 18 DF, p-value: 4.17e-12

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 31 / 44

Page 382: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Korrelation

summary(lm(y∼x)) wrap up

Residuals: Min 1Q Median 3Q Max:

Residualernes: Minimum, 1. kvartil, Median, 3. kvartil, Maximum

Coefficients:

Estimate Std. Error t value Pr(>|t|) "stjerner"

Koecienternes:Estimat σβi

tobs p-værdi

Testen er H0,i : βi = 0 vs. H1,i : βi 6= 0

Residual standard error: XXX on XXX degrees of freedom

εi ∼ N(0, σ2) udskrevet er σ og ν frihedsgrader (brug til hypotesetesten)

Multiple R-squared: XXX

Forklaret varians r2

Resten bruger vi ikke i det her kursus

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 32 / 44

Page 383: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Korrelation

Forklaret varians og korrelation

Forklaret varians af en model er r2, i summary "Multiple R-squared"

Beregnes med

r2 = 1−∑

i(yi − yi)2∑i(yi − y)2

hvor yi = β0 + β1xi

Andel af den totale varians der er forklaret med modellen

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 33 / 44

Page 384: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Korrelation

Forklaret varians og korrelation

Korrelationen ρ er et mål for lineær sammenhæng mellem to

stokastiske variable

Estimeret (i.e. empirisk) korrelation

ρ = r =√r2 sgn(β1)

hvor sgn(β1) er: −1 for β1 ≤ 0 og 1 for β1 > 0

Altså:

Positiv korrelation ved positiv hældningNegativ korrelation ved negativ hældning

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 34 / 44

Page 385: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Korrelation

Test for signikant korrelation

Test for signikant korrelation (lineær sammenhæng) mellem to

variable

H0 : ρ = 0

H1 : ρ 6= 0

er ækvivalent med

H0 : β1 = 0

H1 : β1 6= 0

hvor β1 er estimatet af hældningen i simpel lineær regressionsmodel

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 35 / 44

Page 386: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual Analyse: Model control

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 36 / 44

Page 387: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual Analyse: Model control

Residual Analysis

Method 5.28

Check normality assumption with qq-plot.

Check (non)systematic behavior by plotting the residuals ei as afunction of tted values yi

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 37 / 44

Page 388: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual Analyse: Model control

Residual Analysis in R

fit <- lm(y ~ x)

par(mfrow = c(1, 2))

qqnorm(fit$residuals)

plot(fit$fitted, fit$residuals)

−2 −1 0 1 2

−10

0−

500

5010

015

0

Normal Q−Q Plot

Theoretical Quantiles

Sam

ple

Qua

ntile

s

−200 0 200 400 600

−10

0−

500

5010

015

0

fit$fitted

fit$r

esid

uals

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 38 / 44

Page 389: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual Analyse: Model control

Residual Analyse - Normal antagelsen

OK

−2 −1 0 1 2

Transformer data

−2 −1 0 1 2

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 39 / 44

Page 390: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual Analyse: Model control

Residual Analyse - Systematiske eekter

OK

y

e1

Transformer

y

e2

Ikke modellerede effekter

y

e3

y

ε

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 40 / 44

Page 391: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual Analyse: Model control

Residual Analyse - uafhængighedsantagelsen

For tidsrække data bør uafhængigheds antagelsen også tjekkes, to siple tjek

er

Plot εi vs. εi−1

Udregn cor(εi, εi−1)

OK

e1[−n]

e1[−

1]

Not OK

e2[−n]

e2[−

1]

εi−1

ε i

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 41 / 44

Page 392: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord

Oversigt

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 42 / 44

Page 393: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord

Modellering af phytoplankton

Formuler en lineær model for phytoplankton i Skive fjord, estimer

modellens parametre og foretag modelkontrol.

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 43 / 44

Page 394: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Outline

Outline

1 Motiverende eksempel: Højde-vægt

2 Lineær regressionsmodel

3 Mindste kvadraters metode (least squares)

4 Statistik og lineær regression

5 Hypotesetests og kondensintervaller for β0 og β1

6 Kondensinterval og prædiktionsintervalKondensinterval for linienPrædiktionsinterval

7 Linear regression: matrix formuleringen

8 Korrelation

9 Residual Analyse: Model control

10 Skive fjord

Jan K. Møller ([email protected]) 02403, Forelæsning 8 Juni 2018 44 / 44

Page 395: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 9: Multipel lineær regression

Jan Kloppenborg MøllerDTU Compute, Dynamiske Systemer

Bygning 303B, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 1 / 31

Page 396: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 2 / 31

Page 397: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Warm up med lidt simpel lineær reg.

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 3 / 31

Page 398: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Warm up med lidt simpel lineær reg.

Eksempel: Ozon koncentration

Vi har givet et sæt af sammenhængende målinger af: ozon koncentration

(ppb), temperatur, solindstråling og vindhastighed:

ozone radiation wind temperature month day

41 190 7.4 67 5 1

36 118 8.0 72 5 2...

......

......

18 131 8.0 76 9 29

20 223 11.5 68 9 30

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 4 / 31

Page 399: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Warm up med lidt simpel lineær reg.

Eksempel: Ozonkoncentration

Lad os se på sammenhængen mellem log ozon koncentrationen og

temperaturen

Brug en simpel lineær regressionsmodel

Yi = β0 + β1xi + εi , εi ∼ N(0, σ2) og i.i.d.

hvor

Yi er log ozonkoncentrationen for måling ixi er temperaturen ved måling i

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 5 / 31

Page 400: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 6 / 31

Page 401: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Multipel lineær regression

Y er den afhængige variabel (dependent variable)

Vi er interesseret i at modellere Y 's afhængighed af de forklarende

eller uafhængige variabler (explanatory eller independent variables)

x1, x2, ..., xp

Vi undersøger en lineær sammenhæng mellem Y og x1, x2, ..., xp, veden regressionsmodel på formen

Yi = β0 + β1x1,i + · · ·+ βpxp,i + εi , εi ∼ N(0, σ2) og i.i.d.

Yi og εi er stokastiske variable og xj,i er variable

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 7 / 31

Page 402: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Mindste kvadraters metode (least squares)

Residualerne ndes ved at prædiktionen

yi = β0 + β1xi,1 + · · ·+ βpxi,p

indsættes

yi = yi + ei

"observation = prædiktion+ residual"

og trækkes fra

ei = yi − yi

"residual = observation− prædiktion"

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 8 / 31

Page 403: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Mindste kvadraters metode (least squares)

Ved det bedste estimat for β0, β1, ..., βp forstås de værdier

(β0, β1, ..., βp) der minimerer residual sum of squares (RSS)

n∑i=1

e2i =

n∑i=1

(yi − yi)2

og estimatet for afvigelsernes (εi) varians er

σ2 =1

n− (p+ 1)

n∑i=1

e2i

Find og læs sektion med Theorem 6.2

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 9 / 31

Page 404: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Mindste kvadraters metode

β0, β1, ..., βp ndes ved at løse de såkaldte normalligninger, der for p = 2 er

givet ved

n∑i=1

yi =nβ0 + β1

n∑i=1

xi,1 + β2

n∑i=1

xi,2

n∑i=1

xi,1yi =β0

n∑i=1

xi,1 + β1

n∑i=1

x2i,1 + β2

n∑i=1

xi,1xi,2

n∑i=1

xi,2yi =β0

n∑i=1

xi,2 + β1

n∑i=1

xi,1xi,2 + β2

n∑i=1

x2i,2

Man skal gange nogle matricer sammen.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 10 / 31

Page 405: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Eller Matrix- formulering

0 =∂RSS

∂β=2XT (Y −Xβ) (1)

=2(XTY −XTXβ). (2)

eller (normalligningerne)

XTY =XTXβ (3)

Med løsningen

β = (XTX)−1XTY (4)

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 11 / 31

Page 406: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Matrix formulation

The estimators of the parameters in the simple linear regression model are

given by

β = (XTX)−1XTY (5)

and the covariance matrix of the estimates is

V [β] = σ2(XTX)−1 (6)

and central estimate for the residual variance is

σ2 =RSS

n− (p+ 1)(7)

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 12 / 31

Page 407: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Hypotese test (partial t-test)

The estimate of the parameters in the simple linear regression model are

given by

β = (XTX)−1XTy (8)

and the covariance matrix of the estimates is

Σβ = σ2(XTX)−1 (9)

The obeserved t-statistic for the hypothesis: H0 : βi = βi,0 is

tobs,i =βi − βi,0√(Σβ)ii

. (10)

Should be compared with a t-distribution with n− (p+ 1) degrees offreedom.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 13 / 31

Page 408: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Multipel lineær regression

Kondens og prædiktions interval

xnew = [1, x1,new, . . . , xp,new]:Kondensinterval for middelværdi

V (Ynew) = V (xnewβ) (11)

= σ2xnew(XTX)−1xTnew, (12)

Prediction variance

V (Ynew) = V (xnewβ + εnew) (13)

= σ2(1 + xnew(XTX)−1xTnew). (14)

in practice replace σ2 with its estimate (σ2), and hence use quantiles of the

appropriate t-distribution.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 14 / 31

Page 409: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model udvælgelse

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 15 / 31

Page 410: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model udvælgelse

Udvid modellen (forward selection)

Ikke beskrevet i eNoten

Start med mindste model med den mest signikante (mest

forklarende) variabel

Udvid modellen med de andre forklarende variabler (inputs) en ad

gangen

Stop når der ikke er ere signikante udvidelser

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 16 / 31

Page 411: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model udvælgelse

Formindsk modellen (model reduction eller backwardselection)

Beskrevet i eNoten, sektion 6.5

Start med den fulde model

Fjern den mest insignikante forklarende variabler

Stop hvis alle parameter estimater er signikante

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 17 / 31

Page 412: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model udvælgelse

Model udvælgelse

Der er ikke nogen sikker metode til at nde den bedste model!

Det vil kræve subjektive beslutninger at udvælge en model

Forskellige procedurer, enten forward eller backward, afhænger af

forholdene

Statistiske tests mål til at sammenligne modeller

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 18 / 31

Page 413: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual analyse (model kontrol)

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 19 / 31

Page 414: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual analyse (model kontrol)

Residual analyse (model kontrol)

Model kontrol: Analyser residualerne for at checke at forudsætningerne

er opfyldt

ei ∼ N(0, σ2) og er independent and identically distributed (i.i.d.)

Samme som for simpel lineær model

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 20 / 31

Page 415: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual analyse (model kontrol)

Antagelser

Lav et qq-plot (normal score plot) for at se om de ikke afviger fra at

være normalfordelt

Plot residualerne (ei) mod de prædikterede (ttede) værdier (yi)

Plot residualerne (ei) mod de prædikterede (ttede) værdier (yi)

Plot residualer mod de forklarende variabler

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 21 / 31

Page 416: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Residual analyse (model kontrol)

Uafhængigheds antagelsen (lidt ud over pensum)

Vi antager det ofte uden yderligere undersøgelse

Plot residualerne (ei) som funktion af tiden (hvis meningsfyldt)

Plot ei mod ei−1

Tjek korrelationen mellem ei mod ei−1

og en række andre metoder...

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 22 / 31

Page 417: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kurvelinearitet

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 23 / 31

Page 418: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kurvelinearitet

Kurvelineær (Curvilinear)

Hvis vi ønsker at estimere en model af typen

Yi = β0 + β1xi + β2x2i + εi

kan vi benytte multipel lineær regression i modellen

Yi = β0 + β1xi,1 + β2xi,2 + εi

hvor

xi,1 = xi

xi,2 = x2iog benytte samme metoder som ved multipel lineær regression.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 24 / 31

Page 419: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kurvelinearitet

Udvid ozon modellen med passende kurvelineær regression

Brug modellen

Yi =β0 + β1wind+ β2rad+ β3temp+ β4wind2 + β5rad

2 + β6temp2

+ εi

og brug back-ward selection til at nde den bedste model.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 25 / 31

Page 420: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondens- og prædiktionsintervaller

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 26 / 31

Page 421: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondens- og prædiktionsintervaller

Kondens- og prædiktionsintervaller i R

################################

## Konfidens- og prædiktionsintervaller for den kurvelineære model

fitWindSq <- lm(logOzone ~ temperature + wind + windSq + radiation, data=Air)

## Generer et nyt data.frame med konstant temperatur og instråling, men varierende vindhastighed

wind<-seq(1,20.3,by=0.1)setTemperature <- 78setRadiation <- 186AirForPred <- data.frame(temperature=setTemperature, wind=wind, windSq=wind^2, radiation=setRadiation)

## Udregn konfidens- og prædiktionsintervaller (-bånd)

## Læg mærke til at der tilbage transformeres

CI <- predict(fitWindSq, newdata=AirForPred, interval="confidence", level=0.95)PI <- predict(fitWindSq, newdata=AirForPred, interval="prediction", level=0.95)

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 27 / 31

Page 422: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kollinearitet

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 28 / 31

Page 423: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kollinearitet

Kollinearitet (Collinearity)

Det er problematisk hvis de forklarende variabler er stærkt korrelerede.

De forklarende variable skal være lineært uafhængige.

Tjek korrelationener mellem forklarende variable (ingen tæt på ±1)

Ingen korrelationer i parameter korrelationsmatricen tæt på en.

Det er vigtigt hvordan man designer sit eksperiment!!

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 29 / 31

Page 424: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kollinearitet

Kollinearitet (Colinearity)

Som eksempel se på

yi = β0 + β1x1 + β2x2 + εi; εi ∼ N(0, σ2)

antag at x2 = a+ bx1, så er

yi =β0 + β1x1 + β2(a+ bx1) + εi

=β0 + β2a+ (β1 + β2b)x1 + εi.

Dvs. 2 (ikke 3) parametre.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 30 / 31

Page 425: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kollinearitet

Kollinearitet (Collinearity)

If we have identied a collinarity problem,

We should be carefull about parameter interpretation

We should reduce the model by removing parameters

Other methods exist e.g. Principal Component Regression and Ridge

regression.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 31 / 31

Page 426: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord

Oversigt

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 32 / 31

Page 427: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord

Modellering af phytoplankton

Formuler en lineær model for phytoplankton i Skive fjord, estimer

modellens parametre og foretag modelkontrol.

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 33 / 31

Page 428: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Outline

Outline

1 Warm up med lidt simpel lineær reg.

2 Multipel lineær regression

3 Model udvælgelse

4 Residual analyse (model kontrol)

5 Kurvelinearitet

6 Kondens- og prædiktionsintervaller

7 Kollinearitet

Jan K. Møller ([email protected]) 02403, Forelæsning 9 Juni 2018 34 / 31

Page 429: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 10: Inferens for andele

Jan Kloppenborg MøllerDTU Compute, Dynamiske Systemer

Bygning 303B, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 1 / 46

Page 430: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 2 / 46

Page 431: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 3 / 46

Page 432: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Forskellige analyse/data-situationer

Gennemsnit for kvantitative data:

Hypotesetest/KI for én middelværdi (one-sample)

Hypotesetest/KI for to middelværdier (two samples)

Hypotesetest/KI for ere middelværdier (K samples)

I dag: Andele:

Hypotesetest/KI for én andel

Hypotesetest/KI for to andele

Hypotesetest for ere andele

Hypotesetest for ere multi-categorical andele

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 4 / 46

Page 433: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Estimation af andele

Estimation af andele fås ved at observere antal gange x en hændelsehar indtruet ud af n forsøg:

p =x

n

p ∈ [0; 1]

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 5 / 46

Page 434: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 6 / 46

Page 435: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel

Kondensinterval for én andel

Method 7.3

Såfremt der haves en stor stikprøve, fås et (1− α)% kondensinterval for p

x

n− z1−α/2

√xn(1−

xn)

n< p <

x

n+ z1−α/2

√xn(1−

xn)

n

Hvordan?

Følger af at approximere binomialfordelingen med normalfordelingen.

As a rule of thumb

the normal distribution gives a good approximation of the binomialdistrinution if np and n(1− p) are both greater than 15

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 7 / 46

Page 436: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel

Kondensinterval for én andel

Middelværdi og varians i binomialfordelingen, eNote2:

E(X) = np

V ar(X) = np(1− p)

This means that

E(p) = E

(X

n

)=np

n= p

V ar(p) = V ar

(X

n

)=

1

n2V ar(X) =

p(1− p)n

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 8 / 46

Page 437: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel

Eksempler

Venstrehåndede:

p = Andelen af venstrehåndede i Danmark

og/eller:

Kvindelige ingeniørstuderende:

p = Andelen af kvindelige ingeniørstuderende

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 9 / 46

Page 438: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel

Eksempel

Brug fordelingen den 16. maj:

Find et KI for andelen af stemmer på rod blok

Find et KI for andelen af stemmer på konservative

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 10 / 46

Page 439: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel Bestemmelse af stikprøvestørrelse

Margin of Error på estimat

Margin of Error

med (1− α)% kondens bliver

ME = z1−α/2

√p(1− p)

n

hvor et estimat af p fås ved p = xn

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 11 / 46

Page 440: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel Bestemmelse af stikprøvestørrelse

Bestemmelse af stikprøvestørrelse

Method 7.13

Såfremt man højst vil tillade en Margin of Error ME med (1− α)%kondens, bestemmes den nødvendige stikprøvestørrelse ved

n = p(1− p)(z1−α/2ME

)2

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 12 / 46

Page 441: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel Bestemmelse af stikprøvestørrelse

Bestemmelse af stikprøvestørrelse

Method 7.13

Såfremt man højst vil tillade en Margin of Error ME med (1− α)%kondens, og p ikke kendes, bestemmes den nødvendige stikprøvestørrelseved

n =1

4

(z1−α/2ME

)2idet man får den mest konservative stikprøvestørrelse ved at vælge p = 1

2

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 13 / 46

Page 442: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval for én andel Bestemmelse af stikprøvestørrelse

Eksempel

Hvad er stikprøvestørrelsen hvis man ønsker en Magin of error påmaksimalt den målte afstand mellem blokkene og p = 0.5?

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 14 / 46

Page 443: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for én andel

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 15 / 46

Page 444: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for én andel

Trin ved Hypoteseprøvning

1. Opstil hypoteser og vælg signikansniveau α

2. Beregn teststørrelse

3. Beregn p-værdi (eller kritisk værdi)

4. Fortolk p-værdi og/eller Sammenlign p-værdi og signikansniveau ogdrag en konklusion

(Alternativ 4. Sammenlign teststørrelse og kritisk værdi og drag enkonklusion)

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 16 / 46

Page 445: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for én andel

Hypotesetest for én andel

Vi betragter en nul- og alternativ hypotese for én andel p:

H0 : p = p0

H1 : p 6= p0

Man vælger som sædvanligt enten at acceptere H0 eller at forkaste H0

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 17 / 46

Page 446: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for én andel

Beregning af teststørrelse

Theorem 7.10 og Method 7.11

Såfremt stikprøven er tilstrækkelig bruges teststørrelsen: (np0 > 15 ogn(1− p0) > 15)

zobs =x− np0√np0(1− p0)

Under nulhypotesen gælder at den tilsvarende stokastiske variabel Z følgeren standard normalfordeling, dvs. Z ∼ N(0, 12)

Find p-værdien for to-sidet alternativ (evidence mod nulhypotesen):

If two-sided: 2P (Z > |zobs|)

Kan også gøres ved brug af kritisk værdi.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 18 / 46

Page 447: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for én andel

Eksempel - Hypotesetest

Udfør hypotetesten

H0 : Konservative ryger ud af folketinget

mod et rimeligt alternativ og

H0 : Der er dødt løb mellem blokkene

mod et rimeligt alternativ.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 19 / 46

Page 448: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for én andel

Eksempel

Evt med kritisk værdi i stedet:

z0.975 = 1.96

−4 −2 0 2 4

0.0

0.1

0.2

0.3

0.4

x

dnor

m(x

)

P(Z>1.96)=0.025P(Z<−1.96)=0.025

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 20 / 46

Page 449: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og hypotesetest for to andele

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 21 / 46

Page 450: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og hypotesetest for to andele

Kondensinterval for to andele

Method 7.15

(p1 − p2)± z1−α/2 · σp1−p2hvor

σp1−p2 =

√p1(1− p1)

n1+p2(1− p2)

n2

Rule of thumb:

Både nipi ≥ 10 and ni(1− pi) ≥ 10 for i = 1, 2.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 22 / 46

Page 451: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og hypotesetest for to andele

Hypotesetest for to andele, Method 7.18

Two sample proportions hypothesis test

Såfremt man ønsker at sammenligne to andele (her vist for et tosidetalternativ)

H0 : p1 = p2

H1 : p1 6= p2

Fås teststørrelsen:

zobs =p1 − p2√

p(1− p)( 1n1

+ 1n2), hvor p =

x1 + x2n1 + n2

Og for passende store stikprøver:

Brug standardnormalfordelingen igen.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 23 / 46

Page 452: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kondensinterval og hypotesetest for to andele

Eksempel - Kondens interval og hypotese test for 2 andele

Er der forskel paa fordelingen mellem blokke den 16. maj og den 16.april (brug KI)

Er der forskel paa Alternativets steme andel den 16. maj og den 16.april (brug hypotese test)?

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 24 / 46

Page 453: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 25 / 46

Page 454: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Hypotesetest for ere andele

Sammenligning af c andele

I nogle tilfælde kan man være interesseret i at vurdere om to eller erebinomialfordlinger har den samme parameter p, dvs. man er interesseret i atteste nul-hypotesen

H0 : p1 = p2 = ... = pc = p

mod en alternativ hypotese at disse andele ikke er ens

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 26 / 46

Page 455: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Hypotesetest for ere andele

Tabel af observerede antal for k stikprøver:

stikprøve 1 stikprøve 2 ... stikprøve c Total

Succes x1 x2 ... xc xFiasko n1 − x1 n2 − x2 ... nc − xc n− xTotal n1 n2 ... nc n

Fælles (gennemsnitlig) estimat:

Under nul-hypotesen fås et estimat for p:

p =x

n

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 27 / 46

Page 456: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Hypotesetest for ere andele

Fælles (gennemsnitlig) estimat:

Under nul-hypotesen fås et estimat for p:

p =x

n

Brug dette fælles estimat i hver gruppe:

såfremt nul-hypotesen gælder, vil vi forvente at den j'te gruppe har e1jsuccesser og e2j askoer, hvor

e1j = nj · p =nj · xn

e2j = nj(1− p) =nj · (n− x)

n

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 28 / 46

Page 457: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Hypotesetest for ere andele

Generel formel for beregning af forventede værdier i antalstabeller:

eij =(i'th row total) · (j'th column total)

(total)

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 29 / 46

Page 458: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Beregning af teststørrelse - Method 7.20

Teststørrelsen bliver

χ2obs =

2∑i=1

c∑j=1

(oij − eij)2

eij

hvor oij er observeret antal i celle (i, j) og eij er forventet antal i celle (i, j)

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 30 / 46

Page 459: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Find p-værdi eller brug kritisk værdi - Method 7.20

Stikprøvefordeling for test-størrelse:

χ2-fordeling med (c− 1) frihedsgrader

Kritisk værdi metode

Såfremt χ2obs > χ2

α(c− 1) forkastes nul-hypotesen

Rule of thumb for validity of the test:

Alle forventede værdier eij ≥ 5.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 31 / 46

Page 460: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest for ere andele

Eksempel

Er fordelingen mellem blokke ens i de opgivne meningsmålinger?

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 32 / 46

Page 461: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Analyse af antalstabeller

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 33 / 46

Page 462: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Analyse af antalstabeller

Analyse af antalstabeller

En 3× 3 tabel - 3 stikprøver, 3-kategori udfald

4 uger før 2 uger før 1 uge før

Kandidat I 79 91 93Kandidat II 84 66 60ved ikke 37 43 47

n1 = 200 n2 = 200 n3 = 200

Er stemmefordelingen ens?

H0 : pi1 = pi2 = pi3, i = 1, 2, 3.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 34 / 46

Page 463: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Analyse af antalstabeller

Analyse af antalstabeller

En 3× 3 tabel - 1 stikprøve, to stk. 3-kategori variable:

dårlig middel god

dårlig 23 60 29middel 28 79 60god 9 49 63

Er der uafhængighed mellem inddelingskriterier?

H0 : pij = pi·p·j

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 35 / 46

Page 464: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Analyse af antalstabeller

Beregning af teststørrelse uanset type af tabel

I en antalstable med r rækker og c søjler, fås teststørrelsen

χ2obs =

r∑i=1

c∑j=1

(oij − eij)2

eij

hvor oij er observeret antal i celle (i, j) og eij er forventet antal i celle (i, j)

Generel formel for beregning af forventede værdier i antalstabeller:

eij =(i'th row total) · (j'th column total)

(total)

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 36 / 46

Page 465: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Analyse af antalstabeller

Find p-værdi eller brug kritisk værdi - Method 7.22

Stikprøvefordeling for test-størrelse:

χ2-fordeling med (r − 1)(c− 1) frihedsgrader

Kritisk værdi metode

Såfremt χ2obs > χ2

α med (r−1)(c−1) frihedsgrader forkastes nul-hypotesen

Rule of thumb for validity of the test:

Alle forventede værdier eij ≥ 5.

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 37 / 46

Page 466: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Analyse af antalstabeller

Eksempel

Er der en tidslig udvikling i menningsmålingerne?

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 38 / 46

Page 467: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 39 / 46

Page 468: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

R: prop.test - een andel

# TESTING THE PROBABILITY = 0.5 WITH A TWO-SIDED ALTERNATIVE

# WE HAVE OBSERVED 518 OUT OF 1154

# WITHOUT CONTINUITY CORRECTIONS

prop.test(518, 1154, p = 0.5, correct = FALSE)

##

## 1-sample proportions test without continuity correction

##

## data: 518 out of 1154, null probability 0.5

## X-squared = 12.1, df = 1, p-value = 0.00051

## alternative hypothesis: true p is not equal to 0.5

## 95 percent confidence interval:

## 0.42039 0.47769

## sample estimates:

## p

## 0.44887

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 40 / 46

Page 469: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

R: prop.test - to andele#READING THE TABLE INTO R

pill.study<-matrix(c(23, 34, 35, 132), ncol = 2, byrow = TRUE)

colnames(pill.study) <- c("Blood Clot", "No Clot")

rownames(pill.study) <- c("Pill", "No pill")

# TESTING THAT THE PROBABILITIES FOR THE TWO GROUPS ARE EQUAL

prop.test(pill.study, correct = FALSE)

##

## 2-sample test for equality of proportions without continuity

## correction

##

## data: pill.study

## X-squared = 8.33, df = 1, p-value = 0.0039

## alternative hypothesis: two.sided

## 95 percent confidence interval:

## 0.052395 0.335461

## sample estimates:

## prop 1 prop 2

## 0.40351 0.20958

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 41 / 46

Page 470: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

R: chisq.test - to andele

# CHI2 TEST FOR TESTING THE PROBABILITIES FOR THE TWO GROUPS ARE EQUAL

chisq.test(pill.study, correct = FALSE)

##

## Pearson's Chi-squared test

##

## data: pill.study

## X-squared = 8.33, df = 1, p-value = 0.0039

#IF WE WANT THE EXPECTED NUMBERS SAVE THE TEST IN AN OBJECT

chi <- chisq.test(pill.study, correct = FALSE)

#THE EXPECTED VALUES

chi$expected

## Blood Clot No Clot

## Pill 14.759 42.241

## No pill 43.241 123.759

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 42 / 46

Page 471: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

R: chisq.test - antalstabeller

#READING THE TABLE INTO R

poll <-matrix(c(79, 91, 93, 84, 66, 60, 37, 43, 47), ncol = 3, byrow = TRUE)

colnames(poll) <- c("4 weeks", "2 weeks", "1 week")

rownames(poll) <- c("Cand1", "Cand2", "Undecided")

#COLUMN PERCENTAGES

colpercent<-prop.table(poll, 2)

colpercent

## 4 weeks 2 weeks 1 week

## Cand1 0.395 0.455 0.465

## Cand2 0.420 0.330 0.300

## Undecided 0.185 0.215 0.235

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 43 / 46

Page 472: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

R: chisq.test - antalstabeller

# Plotting percentages

par(mar=c(5,4,4.1,2)+0.1)

barplot(t(colpercent), beside = TRUE, col = 2:4, las = 1,

ylab = "Percent each week", xlab = "Candidate",

main = "Distribution of Votes")

legend( legend = colnames(poll), fill = 2:4,"topright", cex = 0.5)

par(mar=c(5,4,4,2)+0.1)

Cand1 Cand2 Undecided

Distribution of Votes

Candidate

Per

cent

eac

h w

eek

0.0

0.1

0.2

0.3

0.4 4 weeks2 weeks1 week

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 44 / 46

Page 473: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

R: chisq.test - antalstabeller

#TESTING SAME DISTRIBUTION IN THE THREE POPULATIONS

chi <- chisq.test(poll, correct = FALSE)

chi

##

## Pearson's Chi-squared test

##

## data: poll

## X-squared = 6.96, df = 4, p-value = 0.14

#EXPECTED VALUES

chi$expected

## 4 weeks 2 weeks 1 week

## Cand1 87.667 87.667 87.667

## Cand2 70.000 70.000 70.000

## Undecided 42.333 42.333 42.333

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 45 / 46

Page 474: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

R

Oversigt

1 Intro

2 Kondensinterval for én andel

Bestemmelse af stikprøvestørrelse

3 Hypotesetest for én andel

4 Kondensinterval og hypotesetest for to andele

5 Hypotesetest for ere andele

6 Analyse af antalstabeller

7 R

Jan K. Møller ([email protected]) 02403, Forelæsning 10 Juni 2018 46 / 46

Page 475: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 11: Envejs variansanalyse, ANOVA

Jan Kloppenborg Møller

DTU Compute, Dynamiske Systemer

Bygning 303B, Rum 007

Danmarks Tekniske Universitet

2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 1 / 32

Page 476: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 2 / 32

Page 477: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

F-fordelingen

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 3 / 32

Page 478: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

F-fordelingen

F -fordelingen

Hvis Q1 ∼ χ2(n1) og Q2 ∼ χ2(n2), og Q1 og Q2 er uafhængige så følger

F =Q1/n1Q2/n2

(1)

en F -fordeling med n1 og n2 frihedsgrader.

Tæthedsfunktionen for en F -fordeling er givet ved

fF (x) =

(n1n2

)n12x

n12−1

B(n12 ,

n22

) (1 + n1

n2x)n1+n2

2

; x ≥ 0 (2)

hvor

B(ν1, ν2) =Γ(ν1)Γ(ν2)

Γ(ν1 + ν2)(3)

er Beta-funktionen.Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 4 / 32

Page 479: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

F-fordelingen

F-fordelingen som stikpøvefordeling

Lad X1, . . . , Xn1 være i.i.d. N(µ1, σ21) og lad Y1, . . . , Yn2 være i.i.d.

N(µ2, σ22) så gælder at

F =S21/σ

21

S22/σ

22

∼ F (n1 − 1, n2 − 1) (4)

hvor S21 og S2

2 er stikprøve variansen for X hhv. Y .

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 5 / 32

Page 480: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

F-fordelingen

Eksempel

Lad X1, . . . , X10 være i.i.d. N(µ1, σ2) og lad Y1, . . . , Y10 være i.i.d.

N(µ2, σ2) nd

P (S21/S

22 > 2) (5)

hvor S21 og S2

2 er stikprøve variansen for X hhv. Y .

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 6 / 32

Page 481: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 7 / 32

Page 482: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

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,

n1 = n2 = 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

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 8 / 32

Page 483: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

The pooled two-sample t-test statistic

Beregning af den poolede teststørrelse (Metode 3.63 og 3.64)

When considering the null hypothesis about the dierence between the

means of two independent samples:

δ = µ2 − µ1

H0 : δ = δ0

the pooled two-sample t-test statistic is

tobs =(x1 − x2)− δ0√s2p/n1 + s2p/n2

With s2p =(n1−1)s21+(n2−1)s22

n1+n2−2 .

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 9 / 32

Page 484: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Sammenvægtet (Pooled) variance set up

Assume that X1 ∼ N(µ1, σ) and X2 ∼ N(µ2, σ). Then the pooled

two-sample statistic seen as a random variable (Theorem 3.54, Example

2.85 og Exercise 2.16):

T =(X1 − X2)− δ0√S2p/n1 + S2

p/n2(6)

follows, under the null hypothesis and under the assumption that σ21 = σ22,a t-distribution with n1 + n2 − 2 degrees of freedom if the two population

distributions are normal.

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 10 / 32

Page 485: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Sammenvægtet (Pooled) variance set up

Atag at X1 ∼ N(µ, σ) and X2 ∼ N(µ, σ), og n1 = n2 = n. Hvad er

fordelingen af

T 2 =(X1 − X2)

2

S2p/n+ S2

p/n(7)

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 11 / 32

Page 486: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Envejs variansanalyse - eksempel

Gruppe A Gruppe B Gruppe C

2.8 5.5 5.8

3.6 6.3 8.3

3.4 6.1 6.9

2.3 5.7 6.1

Er der forskel (i middel) på grupperne A, B og C?

Variansanalyse (ANOVA) kan anvendes til analysen såfremt observationerne

i hver gruppe kan antages at være normalfordelte.

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 12 / 32

Page 487: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro

Envejs variansanalyse - eksempel

## Observationer

y <- c(2.8, 3.6, 3.4, 2.3,

5.5, 6.3, 6.1, 5.7,

5.8, 8.3, 6.9, 6.1)

## Grupper (behandlinger)

treatm <- factor(c(1, 1, 1, 1,

2, 2, 2, 2,

3, 3, 3, 3))

## Plot

par(mfrow=c(1,2))

plot(as.numeric(treatm), y, xlab="Treatment", ylab="y")

##

plot(treatm, y, xlab="Treatment", ylab="y")

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 13 / 32

Page 488: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model og hypotese

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 14 / 32

Page 489: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model og hypotese

Envejs variansanalyse, model

Opstil en model

Yij = µ+ αi + εij

hvor det antages, at

εij ∼ N(0, σ2)

µ er samlet middelværdi

αi angiver eekt af gruppe (behandling) i

j tæller målinger i grupperne, fra 1 til ni i hver gruppe

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 15 / 32

Page 490: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model og hypotese

Envejs variansanalyse, hypotese

Vi vil nu sammenligne (ere end to) middelværdier µ+ αi i modellen

Yij = µ+ αi + εij , εij ∼ N(0, σ2)

hvor∑niαi = 0.

µ = y, αi = yi − y

dvs. vi kan specicere hypotesen:

H0 : αi = 0 for alle i

H1 : αi 6= 0 for mindst et i

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 16 / 32

Page 491: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model og hypotese

Treatment

1 2 3

µ1

µ

µ2

µ3

α1

α2

α3

y1,j

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 17 / 32

Page 492: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 18 / 32

Page 493: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Envejs variansanalyse, opspaltning og ANOVA tabellen

Med modellen

Yij = µ+ αi + εij , εij ∼ N(0, σ2)

kan den totale variation i data opspaltes:

SST = SS (Tr) + SSE

'Envejs' hentyder til, at der kun er én faktor i forsøget, på i alt knivauer

Metoden kaldes variansanalyse, fordi testningen foregår ved at

sammenligne varianser

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 19 / 32

Page 494: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Formler for kvadratafvigelsessummer

Kvadratafvigelsessum ("den totale varians")

SST =

k∑i=1

ni∑j=1

(yij − y)2

Kvadratafvigelsessum af residualer ("Varians tilbage efter model")

SSE =

k∑i=1

ni∑j=1

(yij − yi)2

Kvadratafvigelsessum af behandling ("Varians forklaret af model")

SS(Tr) =

k∑i=1

ni(yi − y)2

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 20 / 32

Page 495: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 21 / 32

Page 496: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Envejs variansanalyse, F-test

Vi har altså:

SST = SS (Tr) + SSE

og kan nde teststørrelsen:

F =SS (Tr)/(k − 1)

SSE/(n− k)

hvork er antal nivauer af faktoren

n er antal observationer

Signikansniveau α vælges og teststørrelsen F beregnes

Teststørrelsen sammenlignes med en fraktil (percentile) i F fordelingen

F ∼ F (k − 1, n− k)

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 22 / 32

Page 497: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Variansanalysetabel

Variations- Friheds- Kvadrat- Gns. kvadratafv. Test- p-kilde grader afvig. sum sum størrelse F værdiSource of Deg. of Sums of Mean sum of Test- p-variation freedom squares squares statistic F value

Behandling k − 1 SS(Tr) MS(Tr) =SS(Tr)k−1

Fobs =MS(Tr)MSE

P (F > Fobs)

Residual n− k SSE MSE = SSEn−k

Total n− 1 SST

anova(lm(y ~ treatm))

## Analysis of Variance Table

##

## Response: y

## Df Sum Sq Mean Sq F value Pr(>F)

## treatm 2 30.8 15.40 26.7 0.00017 ***

## Residuals 9 5.2 0.58

## ---

## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 23 / 32

Page 498: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Post hoc sammenligninger

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 24 / 32

Page 499: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Post hoc sammenligninger

Post hoc kondensinterval

En enkelt forudplanlagt sammenligning af forskelle på behandling i ogj ndes ved

yi − yj ± t1−α/2

√MSE

(1

ni+

1

nj

)hvor t1−α/2 er fra t-fordelingen med n− k frihedsgrader.

Læg mærke til færre frihedsgrader, da der er estimeret ere parametre

i beregningen af MSE = SSE/(n− k) = s2p (i.e. pooled varians

estimat)

Hvis alle M = k(k − 1)/2 kombinationer af parvise

kondensintervaller udregnes brug formlen M gange, men hver gang

med αBonferroni = α/M

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 25 / 32

Page 500: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Post hoc sammenligninger

Post hoc parvis hypotesetest

In enkelt forudplanlagt hypotesetest på α signikansniveau om forskel

af behandling i og j

H0 : µi = µj , H1 : µi 6= µj

udføres ved

tobs =yi − yj√

MSE(

1ni

+ 1nj

) (8)

og

p− value = 2P (t > |tobs|)hvor t-fordelingen med n− k frihedsgrader anvendes

Hvis alle M = k(k − 1)/2 kombinationer af hypotesetests, bruges det

korrigerede signikans niveau αBonferroni = α/M

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 26 / 32

Page 501: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model kontrol

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 27 / 32

Page 502: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model kontrol

Varians homogenitet

Se på box-plot om spredning ser meget forskellig ud for hver gruppe

## Box plot

plot(treatm,y)

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 28 / 32

Page 503: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model kontrol

Normalfordelingsantagelse

Se på qq-normal plot

## qq-normal plot af residualer

fit1 <- lm(y ~ treatm)

qqnorm(fit1$residuals)

qqline(fit1$residuals)

## Eller med et Wally plot

require(MESS)

qqwrap <- function(x, y, ...) qqnorm(y, main="",...);

qqline(y)

## Kan vi se et afvigende qq-norm plot?

wallyplot(fit1$residuals, FUN = qqwrap)

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 29 / 32

Page 504: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord eksempel

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 30 / 32

Page 505: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord eksempel

Eksempel 1 (Skive fjord)

Et af vandmiljøplanernes hovedmål var at reducere kvælstoftilførslen.

Undersøg om der er sket en reduktion i løbet af de 4 perioder deneret ved

vandmiljøplanerne. Betragt indledningsvis kun tilførslen i September måned.

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 31 / 32

Page 506: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Skive fjord eksempel

Oversigt

1 F-fordelingen

2 Intro

3 Model og hypotese

4 Beregning - variationsopspaltning og ANOVA tabellen

5 Hypotesetest (F-test)

6 Post hoc sammenligninger

7 Model kontrol

8 Skive fjord eksempel

Jan K. Møller ([email protected]) 02403, Forelæsning 11 Juni 2018 32 / 32

Page 507: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til Matematisk Statistik

Forelæsning 12: Tovejs variansanalyse, ANOVA

Jan Kloppenborg Møller

DTU Compute, Dynamiske SystemerBygning 303B, Rum 007Danmarks Tekniske Universitet2800 Lyngby Danmark

e-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 1 / 38

Page 508: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 2 / 38

Page 509: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 3 / 38

Page 510: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

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å eekten af de to midler er angivet):

Stikprøve, n = 10:person A B D = B −A

1 +0.7 +1.9 +1.22 -1.6 +0.8 +2.43 -0.2 +1.1 +1.34 -1.2 +0.1 +1.35 -1.0 -0.1 +0.96 +3.4 +4.4 +1.07 +3.7 +5.5 +1.88 +0.8 +1.6 +0.89 0.0 +4.6 +4.610 +2.0 +3.4 +1.4

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 4 / 38

Page 511: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

Parret setup og analyse = one-sample analyse

dif=x2-x1

t.test(dif)

##

## One Sample t-test

##

## data: dif

## t = 4.67, df = 9, p-value = 0.0012

## alternative hypothesis: true mean is not equal to 0

## 95 percent confidence interval:

## 0.86133 2.47867

## sample estimates:

## mean of x

## 1.67

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 5 / 38

Page 512: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

Parret setup og analyse = one-sample analyse

##

## Paired t-test

##

## data: x2 and x1

## t = 4.67, df = 9, p-value = 0.0012

## alternative hypothesis: true difference in means is not equal to 0

## 95 percent confidence interval:

## 0.86133 2.47867

## sample estimates:

## mean of the differences

## 1.67

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 6 / 38

Page 513: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

Tovejs variansanalyse - eksempel

Samme data som for envejs, dog ved vi nu at forsøget var inddelt i

blokkeGruppe A Gruppe B Gruppe C

Blok 1 2.8 5.5 5.8

Blok 2 3.6 6.3 8.3

Blok 3 3.4 6.1 6.9

Blok 4 2.3 5.7 6.1

dvs. tre grupper på re blokke

el. tre behandlinger på re personer

el. tre afgrøder på re marker (deraf blokke)el. lign.

Envejs vs. tovejs ANOVA

Completely randomized design vs. Randomized block design

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 7 / 38

Page 514: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

Tovejs variansanalyse - eksempel

Samme data som for envejs, dog ved vi nu at forsøget var udført på

re blokke (personer)

Behandling A Behandling B Behandling C

Blok 1 2.8 5.5 5.8

Blok 2 3.6 6.3 8.3

Blok 3 3.4 6.1 6.9

Blok 4 2.3 5.7 6.1

Besvar: Er der signikant forskel (i middel) på grupperne A, B og C?

Variansanalyse (ANOVA) kan anvendes til analysen såfremt

observationerne i hver gruppe kan antages at være normalfordelte (dog

med mange samples dækker CLT)

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 8 / 38

Page 515: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Intro eksempel

## Observationer

y <- c(2.8, 3.6, 3.4, 2.3,5.5, 6.3, 6.1, 5.7,5.8, 8.3, 6.9, 6.1)

## Behandlinger (grupper, afgrøder)

treatm <- factor(c(1, 1, 1, 1,2, 2, 2, 2,3, 3, 3, 3))

## Blokke (personer, marker)

block <- factor(c(1, 2, 3, 4,1, 2, 3, 4,1, 2, 3, 4))

## Til formler senere

(k <- length(unique(treatm)))(l <- length(unique(block)))

## Plots

par(mfrow=c(1,2))## Plot histogrammer inddelt ved behandlinger

plot(treatm, y, xlab="Treatments", ylab="y")## Plot histogrammer inddelt ved blokke

plot(block, y, xlab="Blocks", ylab="y")

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 9 / 38

Page 516: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 10 / 38

Page 517: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model

Tovejs variansanalyse, model

Opstil en model

Yij = µ+ αi + βj + εij , εij ∼ N(0, σ2)

hvor afvigelsen

εij ∼ N(0, σ2) og i.i.d.

µ er middelværdi for alle målingerαi angiver eekt for behandling iβj angiver niveau for blok ider er k behandlinger og l blokke

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 11 / 38

Page 518: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model

Estimater af parametrene i modellen

Vi kan beregne estimater af parametrene (µ og αi, og βj)

µ =y =1

k · l

k∑i=1

l∑j=1

yij

αi =

1

l

l∑j=1

yij

− µβj =

(1

k

k∑i=1

yij

)− µ

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 12 / 38

Page 519: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 13 / 38

Page 520: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Tovejs variansanalyse, opspaltning og ANOVA tabellen

Med modellen

Yij = µ+ αi + βj + εij , εij ∼ N(0, σ2)

kan den totale variation i data opspaltes:

SST = SS (Tr) + SS (Bl) + SSE

'Tovejs' hentyder til, at der er to faktorer i forsøget

Metoden kaldes variansanalyse, fordi testningen foregår ved at

sammenligne varianser

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 14 / 38

Page 521: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Formler for kvadratafvigelsessummer

Kvadratafvigelsessum ("den totale varians") (samme som for envejs)

SST =

k∑i=1

l∑j=1

(yij − µ)2

Kvadratafvigelsessum for behandling ("Varians forklaret af

behandlingdel af modellen")

SS(Tr) = l ·k∑i=1

α2i

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 15 / 38

Page 522: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Beregning - variationsopspaltning og ANOVA tabellen

Formler for kvadratafvigelsessummer

Kvadratafvigelsessum for blokke (personer) ("Varians forklaret af

blokdel af modellen")

SS(Bl) = k ·l∑

j=1

β2j

Kvadratafvigelsessum af residualer ("Varians tilbage efter model")

SSE =

k∑i=1

l∑j=1

(yij − αi − βj − µ)2

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 16 / 38

Page 523: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 17 / 38

Page 524: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Tovejs ANOVA: hypotese om forskellig eekt af behandling

Vi vil nu sammenligne (ere end to) middelværdier µ+ αi i modellen

Yij = µ+ αi + βj + εij , εij ∼ N(0, σ2)

Opstil hypotesen

H0,T r : αi = 0 for alle i

H1,T r : αi 6= 0 for mindst et i

Under H0,T r følger

FTr =SS(Tr)/(k − 1)

SSE/((k − 1)(l − 1))

en F-distribution med k − 1 og (k − 1)(l − 1) frihedsgrader

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 18 / 38

Page 525: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Tovejs ANOVA: hypotese om forskelligt niveau for personer(blokke)

Vi vil nu sammenligne (ere end to) middelværdier µ+ βi i modellen

Yij = µ+ αi + βj + εij , εij ∼ N(0, σ2)

Opstil hypotesen

H0,Bl : βi = 0 for alle i

H1,Bl : βi 6= 0 for mindst et i

Under H0,Bl følger

FBl =SS(Bl)/(l − 1)

SSE/((k − 1)(l − 1))

en F-distribution med l − 1 og (k − 1)(l − 1) frihedsgrader

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 19 / 38

Page 526: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

F-fordeling og hypotese for behandlinger

## Husk, dette er under H0 (altså vi regner som om H0 er sand):

## Sekvens til plot

xseq <- seq(0, 10, by=0.1)

## Plot F fordelingens tæthedsfunktion

plot(xseq, df(xseq, df1=k-1, df2=(k-1)*(l-1)), type="l")

## Kritisk værdi for signifikans niveau 5 pct.

cr <- qf(0.95, df1=k-1, df2=(k-1)*(l-1))

## Tegn den i plottet

abline(v=cr, col="red")

## Test statistikkens værdi:

## Værdien

(Ftr <- (SSTr/(k-1)) / (SSE/((k-1)*(l-1))))

## p-værdien er da

(1 - pf(Ftr, df1=k-1, df2=(k-1)*(l-1)))

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 20 / 38

Page 527: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

F-fordeling og hypotese for blokke

## Husk, dette er under H0 (altså vi regner som om H0 er sand):

## Sekvens til plot

xseq <- seq(0, 10, by=0.1)

## Plot F fordelingens tæthedsfunktion

plot(xseq, df(xseq, df1=l-1, df2=(k-1)*(l-1)), type="l")

## Kritisk værdi for signifikans niveau 5 pct.

cr <- qf(0.95, df1=l-1, df2=(k-1)*(l-1))

## Tegn den i plottet

abline(v=cr, col="red")

## Test statistikkens værdi:

## Værdien

(Fbl <- (SSBl/(l-1)) / (SSE/((k-1)*(l-1))))

## p-værdien er da

(1 - pf(Fbl, df1=l-1, df2=(k-1)*(l-1)))

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 21 / 38

Page 528: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Hypotesetest (F-test)

Variansanalysetabel

Variations- Friheds- Kvadrat- Gns. kvadratafv. Test- p-kilde grader afvi. sum sum størrelse F værdiSource of Deg. of Sums of Mean sum of Test- p-variation freedom squares squares statistic F value

Behandling k − 1 SS(Tr) MS(Tr) =SS(Tr)k−1

FTr =MS(Tr)MSE

P (F > FTr)

Block l − 1 SS(Bl) MS(Bl) =SS(Bl)l−1

FBl =MS(Bl)MSE

P (F > FBl)

Residual (k − 1)(l − 1) SSE MSE = SSE(k−1)(l−1)

Total n− 1 SST

anova(lm(y ~ treatm + block))

## Analysis of Variance Table

##

## Response: y

## Df Sum Sq Mean Sq F value Pr(>F)

## treatm 2 30.79 15.40 74.40 5.8e-05 ***

## block 3 3.95 1.32 6.37 0.027 *

## Residuals 6 1.24 0.21

## ---

## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 22 / 38

Page 529: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Post hoc sammenligninger

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 23 / 38

Page 530: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Post hoc sammenligninger

Post hoc kondensinterval

Som ved envejs, skift (n− k) frihedsgrader ud med (k − 1)(l − 1) (og

brug MSE fra tovejs).

Gøres med enten behandlinger eller blokke

En enkelt forudplanlagt sammenligning af forskelle på behandling i ogj ndes ved

yi − yj ± t1−α/2

√MSE

(1

ni+

1

nj

)hvor t1−α/2 er fra t-fordelingen med (k − 1)(l − 1) frihedsgrader.

Hvis alle kombinationer af parvise kondensintervaller brug formlen Mgange, men med αBonferroni = α/M

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 24 / 38

Page 531: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Post hoc sammenligninger

Post hoc parvis hypotesetest

In enkelt forudplanlagt hypotesetest på α signikansniveau om forskel

af behandling i og j

H0 : µi = µj , H1 : µi 6= µj

udføres ved

tobs =yi − yj√

MSE(

1ni

+ 1nj

) (1)

og

p− value = 2P (t > |tobs|)hvor t-fordelingen med (k − 1)(l − 1) frihedsgrader anvendes

Hvis alle M = k(k − 1)/2 kombinationer af hypotesetests: korrigeret

signikans niveau αBonferroni = α/M

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 25 / 38

Page 532: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model kontrol

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 26 / 38

Page 533: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model kontrol

Varians homogenitet

Se på box-plot om spredning af residualer ser ud til at afhænge af gruppen

## Gem fittet

fit <- lm(y ~ treatm + block)

## Box plot

par(mfrow=c(1,2))

plot(treatm, fit$residuals, y, xlab="Treatment")

## Box plot

plot(block, fit$residuals, xlab="Block")

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 27 / 38

Page 534: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Model kontrol

Normalfordelingsantagelse

Se på qq-normal plot

## qq-normal plot af residualer

qqnorm(fit$residuals)

qqline(fit$residuals)

## Eller med et Wally plot

require(MESS)

qqwrap <- function(x, y, ...) qqnorm(y, main="",...);

qqline(y)

## Kan vi se et afvigende qq-norm plot?

wallyplot(fit$residuals, FUN = qqwrap)

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 28 / 38

Page 535: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Eksempel: Skive Fjord

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 29 / 38

Page 536: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Eksempel: Skive Fjord

Eksempel: Skive Fjord

Undersøg om der er forskel på vandtemperaturen i forskellige år

Undersøg om der er forskel på algekoncentrationen i forskellige år

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 30 / 38

Page 537: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 31 / 38

Page 538: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

The general linear model - intro

The classical GLM leads to a unique way of describing the variations

of experiments with a continuous variable.

The classical GLM's include

Regression analysisAnalysis of variance - ANOVAAnalysis of covariance - ANCOVA

The residuals are assumed to follow a multivariate normal distribution

in the classical GLM.

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 32 / 38

Page 539: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

The general linear model - intro

Classical GLM's are naturally studied in the framework of the

multivariate normal distribution.

We will consider the set of n observations as a sample from a

n-dimensional normal distribution.

Under the normal distribution model, maximum-likelihood estimation

of mean value parameters may be interpreted geometrically as

projection on an appropriate subspace.

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 33 / 38

Page 540: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

General Linear Model

A general linear model is:

Y ∼ Nn(Xβ, σ2I)

Example (Two-way ANOVA):

B1 B2 B3

A1 y11 y12 y13A2 y21 y22 y23

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 34 / 38

Page 541: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

Two way ANOVA (the model):

yij = µ+ αi + βj + εij , εij ∼ i.i.d. N(0, σ2), i = 1, 2, j = 1, 2, 3.

An expanded view of this model is:

y11 = µ + α1 + β1 + ε11y21 = µ + α2 + β1 + ε21y12 = µ + α1 + β2 + ε12y22 = µ + α2 + β2 + ε22y13 = µ + α1 + β3 + ε13y23 = µ + α2 + β3 + ε23

The exact same in matrix notation (though not identiable):y11y21y12y22y13y23

︸ ︷︷ ︸

y

=

1 1 0 1 0 01 0 1 1 0 01 1 0 0 1 01 0 1 0 1 01 1 0 0 0 11 0 1 0 0 1

︸ ︷︷ ︸

X

µα1α2β1β2β3

︸ ︷︷ ︸

β

+

ε11ε21ε12ε22ε13ε23

︸ ︷︷ ︸

ε

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 35 / 38

Page 542: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

The default in R would bey11y21y12y22y13y23

︸ ︷︷ ︸

y

=

1 0 0 01 1 0 01 0 1 01 1 1 01 0 0 11 1 0 1

︸ ︷︷ ︸

X

µα2β2β3

︸ ︷︷ ︸

β

+

ε11ε21ε12ε22ε13ε23

︸ ︷︷ ︸

ε

y is the vector of all observations

X is known as the design matrix

β is the vector of parameters

ε is a vector of independent N(0, σ2) measurement noiseThe vector ε is said to follow a multivariate normal distribution

Mean vector 0Covariance matrix σ2IWritten as: ε ∼ N(0, σ2I)

y = Xβ + ε species the model, and everything can be calculated

from y and X.

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 36 / 38

Page 543: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

Construction of the design matrix

In a general linear model (with both factors and covariates), it is

surprisingly easy to construct the design matrix X.

For each factor: Add one column for each level, with ones in the rows

where the corresponding observation is from that level, and zeros

otherwise.

For each covariate: Add one column with the measurements of the

covariate.

Remove linear dependencies (if necessary)

Example: linear regression:

yi = α+ β · xi + ε

In matrix notation:

y =

1 x11 x2. .. .1 xn

(αβ

)+ ε

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 37 / 38

Page 544: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Den generelle lineære model

Oversigt

1 Intro eksempel

2 Model

3 Beregning - variationsopspaltning og ANOVA tabellen

4 Hypotesetest (F-test)

5 Post hoc sammenligninger

6 Model kontrol

7 Eksempel: Skive Fjord

8 Den generelle lineære model

Jan K. Møller ([email protected]) 02403, Forelæsning 12 Juni 2018 38 / 38

Page 545: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Kursus 02403 Introduktion til matematisk statistik

Forelæsning 13: Et overblik over kursets indhold

Jan Kloppenborg Møller

DTU Compute, Dynamiske systemerBuilding 303B, Room 007Danish Technical University2800 Lyngby Denmarke-mail: [email protected]

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 1 / 28

Page 546: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 2 / 28

Page 547: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 1: Simple plots og deskriptive statistikker

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 3 / 28

Page 548: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 1: Simple plots og deskriptive statistikker

eNote 1: Simple plots og deskriptive statistik

Teknikker til at se på data! (deskriptiv statistik)

Opsummerende statistikkerGennemsnittet: x

Empirisk standard afvigelse: s

Empirisk varians: s2

Median, øvre- og nedre kvartiler, fraktiler, korrelationer

Simple plotsScatter plot (xy plot)Histogram (empirisk tæthed)Kumulativ fordeling (empirisk fordeling)Boxplots, søjlediagram, cirkeldiagram (lagkagediagram)

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 4 / 28

Page 549: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote2: Fordelinger

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 5 / 28

Page 550: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote2: Fordelinger

eNote2: Diskrete fordelinger

Grundlæggende koncepter:Stokastisk variabel (udfaldet af et endnu ikke udført eksperiment)

Tæthedsfunktion: f(x) = P (X = x) (pdf)

Fordelingsfunktion: F (x) = P (X ≤ x) (cdf)

Middelværdi: µ = E(X)

Standard afvigelse: σ

Varians: σ2

Specikke fordelinger:Binomial (Kast med een mønt)

Hypergeometrisk (trækning uden tilbagelægning)

Poisson (antal hændelser i interval)

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 6 / 28

Page 551: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote2: Fordelinger

eNote 2: Kontinuerte fordelinger

Grundlæggende koncepter:Tæthedsfunktion: f(x) (pdf)Fordelingsfunktion: F (x) = P (X ≤ x) (cdf)Middelværdi (µ) og varians (σ2)Regneregler for stokastiske variabler

Specikke fordelinger:NormalLog-NormalUniformExponential

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 7 / 28

Page 552: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 2+4: Funktioner af stokastiske variable

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 8 / 28

Page 553: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 2+4: Funktioner af stokastiske variable

eNote 2+4:Funktioner af stokastiske variable

Grundlæggende koncepter:Error propagation (V (f(X1, .., Xn)) - TaylorSimulering: Fordelings/tæthedsfunktion for Y = f(X1, .., Xn)

Samplings fordelinger:X1, .., Xn iid N(µ, σ2)Normal (X når σ2 kendt)χ2 -

∑X2i eller S2

t - standardliseret (med observeret standardafvigelse) gennemsnitF - Forholdet mellem χ2 fordelinger (S2

y/S2x)

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 9 / 28

Page 554: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 3: One and two sample

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 10 / 28

Page 555: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 3: One and two sample

eNote 3: Kondensintervaller for én gruppe/stikprøve

Grundlæggende koncepterEstimation

Signikans niveau α

Kondensintervaller (fanger rigtige værdi 1− α af gangene)

Population og tilfældig stikprøve

Stikprøvefordelinger (t og χ2)

Centrale grænseværdisætning

Specikke metoder, én gruppe/stikprøve:Kondensintervaller for middelværdi (t-fordeling) og varians (χ2

fordeling)Forsøgsplanlægning: beregn stikprøvestørrelsen n for den ønskedepræcision

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 11 / 28

Page 556: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 3: One and two sample

eNote 3: Hypotese tests for én gruppe/stikprøve

Grundlæggende koncepter:

Hypoteser

p-værdi (sandsynlighed for teststørrelsen eller mere ekstremt, hvis H0

er sand, e.g. P (T > tobs))

Type I fejl: (i virkeligheden ingen eekt, men H0 afvises)P (Type I) = α

Type II fejl: (i virkeligheden eekt, men H0 afvises ikke)P (Type II) = β

Testens styrke er 1− β

Specikke metoder, én gruppe:t-test for middelværdiniveauStikprøvestørrelse for ønsket styrkeNormal qq-plot

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 12 / 28

Page 557: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 3: One and two sample

eNote 3: Statistik for to grupper/stikprøver

Specikke metoder, to grupper:

Test og kondensintervaller for forskel i middelværdi (t-test)

Forsøgsplanlægning: Beregn sample størrelsen for den ønskede styrke

Specikke metoder, to PARREDE grupper:"Tag dierencen for hver måling" ⇒ "statistik for én gruppe"

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 13 / 28

Page 558: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 4: Statistik ved simulation

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 14 / 28

Page 559: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 4: Statistik ved simulation

eNote 4: Statistik ved simulation

Introduktion til simulering(Beregn statistik mange gange)

Fejlforplantning (error propagation rules)(F.eks. igennem ikke-lineær funktion)

Bootstrapping:Parametrisk (Simuler mange udfald af stokastisk var.)Ikke-parametrisk (Træk direkte fra data)Kondensintervaller (og derfor også hypotesetest)

Specikke setups:Èn gruppe/stikprøve og to grupper/stikprøver dataMiddelværdier (µs) og/eller andre features (θs)

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 15 / 28

Page 560: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 5-6: Lineær regressions analyse

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 16 / 28

Page 561: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 5-6: Lineær regressions analyse

eNote 5: Simpel lineær regressions analyse

To variable: x og y

Beregn mindstekvadraters estimat af rette linje

Inferens med simpel lineær regressionsmodelStatistisk model: Yi = β0 + β1xi + εiY = Xβ + εEstimation af kondensintervaller og tests for β0 og β1Kondensintervaller for linjen (95% gange ligger linjen indenfor)Prædiktionsintervaller for punkter (95% af nye punkter ligger indenfor)

ρ, r og R2

ρ er korrelationen (= signβ1R) beskriver graden af lineær

sammenhæng mellem x og yR2 er andelen af den totale variation som er forklaret af modellenAfvises H0 : β1 = 0 så afvises også H0 : ρ = 0

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 17 / 28

Page 562: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 5-6: Lineær regressions analyse

eNote 6: Multipel lineær regressions analyse

Flere variabler: y, x1, x2, . . .(y afhængig/respons var. og x'er er forklarende/uafhængige var.)

Mindstekvadraters rette plan (et plan da der er >2 dimensioner)

Inferens for en multipel lineær regressionmodelStatistisk model: Yi = β0 + β1x1,i + β2x2,i + . . .+ εi

Y = Xβ + ε

Estimation af kondensintervaller og tests for β'er

Kondensintervaller for modellen (For det forventede plan)

Prædiktionsintervaller for nye punkter

R2 er andelen af den totale variationen som er forklaretaf modellen

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 18 / 28

Page 563: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 7: Inferens for andele

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 19 / 28

Page 564: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 7: Inferens for andele

eNote 7: Inferens for andele

Specikke metoder, én, to og k > 2 grupperBinær/kategorisk respons

Estimation og kondensintervaller for andeleMetoder til store stikprøver vs. til små stikprøver

Hypoteser for én andel (np ≥ 15 og (1− p)n ≥ 15)

Hypoteser for to andele

Analyse af antalstabeller (χ2-test) (Alle forventedeantal > 5)

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 20 / 28

Page 565: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 8: Variansanalyse ( ANOVA)

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 21 / 28

Page 566: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 8: Variansanalyse ( ANOVA)

eNote 8: Envejs variansanalyse (envejs ANOVA)

k UAFHÆNGIGE grupper

Specikke metoder, envejs variansanalyse:Test der sammenligner middelværdien af grupperne

ANOVA-tabel: SST = SS(Tr) + SSE

F -test

Post hoc test(s): parvise t-test med/uden Bonferroni korrektion

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 22 / 28

Page 567: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

eNote 8: Variansanalyse ( ANOVA)

eNote 8: Tovejs variansanalyse (tovejs ANOVA)

Blokdesign giver to faktorer

ANOVA-tabel: SST = SS(Tr) + SS(Bl) + SSESST , SS(Tr) og SS(Bl) beregnes som ved envejs ANOVA

SSE = SST − SS(Tr)− SS(Bl)

F -test

Post hoc test: parvise t-test med/uden Bonferronikorrektion

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 23 / 28

Page 568: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Some further perspectives

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 24 / 28

Page 569: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Some further perspectives

Some further perspectives

Likelihood theory (estimations teknik)

General Linear Models (GLM) - generalisering afmultiple linear regression og variansanalyse

Generalized Linear Models - GLM men andre fordelingerend den Gaussiske

Korrelations strukturer

Stokastiske dynamiske systemer

og meget mere ...

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 25 / 28

Page 570: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Evaluering

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 26 / 28

Page 571: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Evaluering

Evaluering

Husk evaluering!

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 27 / 28

Page 572: Course 02403: Introduktion til matematisk statistik ...uniguld.dk › wp-content › guld › DTU › Statistik › ... · Praktisk Information Oversigt 1 Praktisk Information 2 Introduction

Evaluering

Overview

1 eNote 1: Simple plots og deskriptive statistikker

2 eNote2: Fordelinger

3 eNote 2+4: Funktioner af stokastiske variable

4 eNote 3: One and two sample

5 eNote 4: Statistik ved simulation

6 eNote 5-6: Lineær regressions analyse

7 eNote 7: Inferens for andele

8 eNote 8: Variansanalyse ( ANOVA)

9 Some further perspectives

10 Evaluering

Jan K. Møller ([email protected]) 02403, Forelæsning 13 Juni 2018 28 / 28