A normal distribution versus a Paranormal distribution :)
Timetable first half (tentative)
| Date | Week | Lab | Assignment | Topic |
|---|---|---|---|---|
| 18.7. | 1 | - | - | Introduction, R, Rmarkdown |
| 25.7. | 2 | 1 | - | Hypotheses, variables, variation |
| 1.8. | 3 | 2 | - | Organising data, measuring variation |
| 8.8. | 4 | 3 | - | Distributions, quartiles, quantiles, probabilities |
| 15.8. | 5 | 4 | 1 | Type I and type II error (Assignment 1 due Friday) |
| 22.8. | 6 | 5 | - | The t-test |
Just quickly….on communication:
‘Mathews…we are getting another of those strange ’aw blah es pan yol’ sounds.’
- Remember this slide?
- I sent out a request to fill in this spread sheet… Both on blackboard and FB
- As of today, 61 out of about 300 students had filled it in…
- Are we communicating well? Do you read our messages..?
Midsemester test
Happens on campus!
- Week 7 during labs! Come to YOUR lab stream!
- 1 single sided A4 page (cheat sheet), no electronic devices
- Do not use your laptops, just use the console in RStudio on the desktops provided
- It will take 50 minutes, we will start on time, so be there early
- Please bring your student ID
- The test will be made available online through Canvas
- There will be multiple choice plus some short answer questions
- Content: all that was treated so far (lectures, labs, example questions!)
- No lab report for week 7
Recap week 4
- The standard error
- how it differs from the standard deviation
- when it is used
- The normal distribution
- computing probabilities and quantiles using
pnorm()andqnorm()
- computing probabilities and quantiles using
- Other distributions (poisson, uniform)
- the mean, the median and the mode
- Confidence intervals
What we will learn today
- From calculating probabilities to a statistical test
- Understanding test statistics
- Null and alternative hypotheses
- Understanding and interpreting p-values
- The two types of errors we can commit in a statistical test (type I and type II errors)
- Practice questions for the midsemester test
Remember from last week
In terms of body height, between what limits are 95 % of the male population ?
qnorm(p = .025, mean = 170, sd = 7) [1] 156.2803 qnorm(p = .975, mean = 170, sd = 7) [1] 183.7197
Remember from last week
What is the probability of being taller than 185 cm if you are a man ?
1 - pnorm(q = 185, mean = 170, sd = 7) [1] 0.01606229
OR:
pnorm(q = 185, mean = 170, sd = 7, lower.tail = F) #convert the result to %! [1] 0.01606229
Survey on body height of AUT BIOL501 students
sex = c(F, F, M, M, F, F, F,... bodyheight = c(163, 155, 196, 171, 165,... d1 = data.frame(sex, bodyheight)
mean(d1$bodyheight[d1$sex == 'M']) [1] 176.3333 mean(d1$bodyheight[d1$sex == 'F']) [1] 163.3333 length(d1$bodyheight[d1$sex == 'M']) #what does the function 'length()' do again? [1] 30 length(d1$bodyheight[d1$sex == 'F']) [1] 87
From Wikipedia, we can learn that the average New Zealander is 178 cm (sd = 7, males) and 164 cm (sd = 6, females)
What question can we ask now?
Are BIOL501 students typical New Zealanders?
If we want a more quantitative statement on this question
- We need to know whether our sample is ‘unusual’ or ‘normal’?
- We need to know what ‘unusual’ or ‘normal’ means, so
- we need to quantify what is usual, normal, rare etc.!
- We need a testable hypothesis
So let’s try
Are BIOL501 students typical NZers?
Our hypothesis is:
- BIOL501 students are NOT different from the average New Zealand body height (this is our so-called null hypothesis \(H_0\))
- Because we can stick with this hypothesis or reject it, we need an alternative hypothesis \(H_A\): BIOL501 students ARE different from a typical sample of New Zealanders
- Note that the Null hypothesis is negative, which makes it easier to falsify!
- Also note that we can never accept \(H_0\), we can only fail to reject \(H_0\)
Are BIOL501 students typical NZers?
Now we need a test statistic and knowledge of the distribution we compare against:
Our test statistic is simply the mean of our sample (let’s do it for females to start with):
mean(d1$bodyheight[d1$sex == 'F']) [1] 163.3333
How does that compare with
pop = rnorm(2500000, mean = 164, sd = 6) #why 2500000? mean(pop) [1] 164.0014
Are BIOL501 students typical NZers?
YES!
We can tell by just looking at how we compare to the distribution of NZ female bodyheight. We could conclude that we are typical New Zealanders. More quantitatively…:
Are BIOL501 students typical NZers?
The probability of obtaining a value equal or smaller than the mean we got for our female students when sampling from the NZ population is about 50%:
pnorm(q = mean(d1$bodyheight[d1$sex == 'F']) , mean = 164, sd = 6) [1] 0.4557641
In other words our sample is NOT unusual and hence we cannot reject our null hypothesis!
We are NOT different from a typical sample of New Zealanders
OK, but what if our sample mean had been different, say 160 cm, or 150 cm…?
Are BIOL501 students typical NZers?
pnorm(q = 160, mean = 164, sd = 6) [1] 0.2524925
Is a value that we’d get 25% of the time by chance rare?
Are BIOL501 students typical NZers?
pnorm(q = 150, mean = 164, sd = 6) [1] 0.009815329
Is a value that we’d get 1% of the time by chance rare?
P-values and statistical significance
- Those probabilities (50%, 25%, 1%) are our p-values. They always are to be interpreted as ‘the probability of obtaining such an extreme value by chance’
- We need a threshold to objectively distinguish from ‘rare’ and ‘unusually rare’:
- Normally, we say that if our sample is more extreme than what we would find 5% of the time by chance, then our p-value is significant (in a statistical sense)
- This threshold is also called the \(\alpha\)-threshold
- In a report, we would for instance say (if the mean was 150 cm): ‘The body height of our female students is significantly lower than the New Zealand average (p < 0.05)’ (but see restrictions on next slide…!)
In summary…
- We formulate a null hypothesis (\(H_0\)) and an alternative hypothesis (\(H_A\))
- We obtain a (or several) sample(s)
- We calculate a metric (in our example this was simply the mean). This is our test statistic
- We then compare our test statistic against a random distribution of the same variable with known parameters (e.g. mean and standard deviation)
- If our sample is sufficiently ‘rare’ (i.e. past the \(\alpha\)-threshold), then we consider our test significant, i.e. we reject the null hypothesis and turn to \(H_A\)
Note that this protocol is VERY generic, it will differ slightly depending on what test you are performing. This is not (yet) a proper statistical test, just the general idea behind it.
Type I vs. type II error
In all of this, we can make 2 types of errors!
Type I vs. type II error
- A type I error is when we falsly reject the null hypothesis \(H_0\)
- In plain language, this means that we call something ‘significant’ (e.g. a difference, 2 samples, etc.) while in reality there is no significant difference (or, more generally ‘nothing going on’)
- A type II error is when we falsly fail to reject the null hypothesis \(H_0\)
- In plain language, this means that “we don’t see anything where in reality things (e.g. samples) are different”
Note that the ‘plain language’ definitions are inexact, but hopefully help you to understand the principle of type I/II errors
Type I vs. type II error
Maybe easier to remember…:
That was too much…again please…
OK:
- Two boxes with pieces of paper with numbers written on them
- I tell you those numbers come from a standard normal distribution (this may or may not be true)
- You are to test this:
- State your \(H_0\): ‘The sample is no different from a standard normal distribution’
- You pick a number from each box, write it down, and put it back into the same box
- Compare the number (your test statistic) to a standard normal distribution, is it unusually low/high?
- Stick with your \(H_0\) or reject it and turn to \(H_A\)
- Tell me whether you think box 1/box 2 actually contained numbers that follow a standard normal distribution!
OK…what do we do?
So what was the real story?
So what was the real story?
Example questions
The variance is
- A measure for the spread in a sample
- The sum of squared errors divided by the degrees of freedom
- The squared standard deviation
- Can be calculated using the function
var()in R - All of the above
Example questions
The standard error of the mean
- Is just another way of expressing the spread in a sample
- Is a way of showing how good our estimate of the mean is
- Is the squareroot of the standard deviation
- All of the above
- None of the above
Example questions
Without using R, what is the probability of being taller than 170 if you are a male and we assume that the body height of the male population follows a perfect normal distribution with mean 170?
- Close to 100%
- About 25%
- 50%
- 45%
- It is impossible to calculate this because you don’t indicate the standard deviation
Example questions
Without turning to R, what is the approximate body height that 75% of women are under (shorter than), assuming a population mean of about 160 cm and a standard deviation of about 6?
- About 165 cm
- About 195 cm
- Certainly less than 160 cm
- About 155 cm
- None of the above
Example questions
A histogram of the body heights of the female students in this paper
- Will look rather bell-shaped
- Will look like a normal distribution with a mean around 160
- Will have a mode that is approximately equal to the mean and the median
- Will likely have a standard deviation between 5 and 10
- All of the above is correct
Example questions
Without using R or a calculator, what is the approximate probability to draw a random number larger than 8 from a normal distribution with mean 4 and standard deviation 1?
- About 50%
- About 10%
- Less than 5%
- Very small, less than 1%
Example questions
If you were to show the effect of a binomial variable on a continuous variable, which of the following plots would suit best?
- A histogram
- A box plot
- Such a data set cannot be visualised
- None of the above
Example questions
What is the reason for dividing by \(n-1\) rather than \(n\) when calculating the variance of a sample?
- To avoid division by zero
- To make sure the sum of squared residuals (deviances) is not zero
- To avoid underestimating the variance in small sample sizes
- To make sure the variance has the same units as the original variable
Example questions
To numerically describe Auckland house prices, which set of metrics would you use?
- The mean and the range
- Only the minimum and the maximum
- The median and perhaps the first and third quartile
- The mode and the maximum
- None of the above
Example questions
Which of the following is not adding non-systematic variation?
- If the experimenter becomes tired and starts making random mistakes
- If a cheaper, less accurate machine is bought to analyse the samples
- If patients are by mistake administered too low a dosis of a medication
- If suddenly the experimental subjects are taken from a more heterogeneous population
Example questions
If you were commissioned to estimate the mean size of snapper in the Hauraki Gulf (your population), a good sample to take would be
- 200 snapper from Waiheke island
- 200 snapper taken from random spots around the Hauraki Gulf
- 200 snapper from random places all around New Zealand
- 500 snapper randomly taken from around the Hauraki Gulf
Example questions
If the sample size increases
- So does the standard error
- The standard error remains the same
- The standard error decreases
- The variance increases
- The standard deviation increases
Example questions
Which line of code provides the answer to the question ‘What is the probability of being between 185 and 200 cm tall for a male of a population with mean body height 175 cm and standard deviation of 7?’
pnorm(q = 200, mean = 175, sd = 7) - pnorm(q = 185, mean = 175, sd = 7)pnorm(q = 185, mean = 175, sd = 7) - pnorm(q = 200, mean = 175, sd = 7)pnorm(q = 200, mean = 185, sd = 7) - pnorm(q = 185, mean = 175, sd = 7)pnorm(q = 200, mean = 175, sd = 7) + pnorm(q = 185, mean = 175, sd = 7)- None of the above
Example questions (short answer)
Imagine you are researching the size of great white sharks around New Zealand waters. Assume this variable is normally distributed with mean 3 m and standard deviation 0.5 m.
- Sketch such a distribution, label all axes and indicate the mean and the standard deviation.
- At least how big are the biggest 5% of your population of sharks? Shade this probability in your sketch.
- You realise that in actual fact, great white shark size does not follow a normal distribution. The actual distribution is heavily skewed to the right. Sketch such a distribution and show how your estimate from (2) might have been terribly wrong.
What will we have learnt in Week 5?
- To formulate a null and an alternative hypothesis
- How to conduct a very simple statistical test
- What a test statistic is, an example for this
- What a type I and a type II error is
Sounds like not much, but if you understand this, you’re set!
Glossary Week 5
- test statistic
- null hypothesis \(H_0\)
- alternative hypothesis \(H_A\)
- \(\alpha\)-level
- significance
- type I error
- type II error