+ refresher in inferential statistics [email protected] stats
TRANSCRIPT
![Page 1: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/1.jpg)
+
Refresher in inferential [email protected]
http://www.psy.ed.ac.uk/events/research_seminars/psychstats
![Page 3: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/3.jpg)
+Our basic question…
Did something occur?
Importantly, did what we predicted would occur, transpire?, i.e., is the world as we predicted?
Why does this require statistics?
![Page 4: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/4.jpg)
+Is Breastfeeding good for Baby’s brains?
![Page 5: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/5.jpg)
The association between breastfeeding and IQ is moderated by a genetic polymorphism (rs174575) in the FADS2 gene
Caspi A et al. PNAS 2007;104:18860-18865
©2007 by National Academy of Sciences
![Page 6: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/6.jpg)
+Overview
Hypothesis testing p-values Type I vs. Type II errors Power Correlation Fisher’s exact test T-test Linear regression Non-parametric statistics (mostly for you to
go over in your own time)
![Page 7: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/7.jpg)
+Hypothesis testing
1.Propose a null and an experimental hypothesis.
Mistakes here may make the experiment un-analysable
2.Consider the assumptions of the test: Are they met?
Statistical independence of observations
Distributions of the observations.
Student's t distribution, normal distribution etc.
3.Compute the relevant test statistic.
1.Student’s t-test-> t ; ANOVA F; Chi2
4.Compute likelihood of the test-statistic:
1.Does it exceed your chosen threshold?
2.Either reject (or fail to reject) the null hypothesis
![Page 8: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/8.jpg)
+What mistakes can we make?
“The World”
Yes No
Your Decision
Yes correct detection
false positive
No false negative correct rejection
![Page 9: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/9.jpg)
+Starting to make inferences…the Binomial
Toss a coin
![Page 10: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/10.jpg)
+Dropping lots of coins...
Pachinko
![Page 11: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/11.jpg)
+Normal compared to Binomial
n = 6
p = .5
![Page 12: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/12.jpg)
+Distributions
normal (µ, ∂) binomial (p, n)
![Page 13: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/13.jpg)
+Distributions
Poisson (lambda) Power
Accidents in a period of time; Publication rates
![Page 14: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/14.jpg)
+Testing what distribution you have
![Page 15: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/15.jpg)
+Why are things normal?
![Page 16: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/16.jpg)
+Central limit theorem
The mean of a large number of independent random variables is distributed approximately normally.
![Page 17: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/17.jpg)
+Hypothesis testing
Making statistical decisions using experimental data.
Need to form a null hypothesis
(we can reject, but not confirm hypotheses)
A result is “significant” if it is unlikely to have occurred by chance.
Ronald Fisher “We may discover whether a second sample is or is not significantly different from the first”.
![Page 18: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/18.jpg)
+What mistakes can we make?
“The World”
Yes No
Your Decision
Yes correct detection
false positive
No false negative correct rejection
![Page 19: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/19.jpg)
+Error
Type-I error: False Alarm, a bogus effect reject the null hypothesis when it is really
true Much of published science is Type-I error
(Ioannides, 2008)
Type-II error: Miss a real effect Fail to reject our null hypothesis when it is
false Many small projects have this problem
Type-III error: :-) lazy, incompetent, or willful ignorance of the
truth
![Page 20: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/20.jpg)
+p-values
Almost any difference (a count, a difference in means, a difference in variances) can be found with some probability, irrespective of the true situation.
All we can do is to set a threshold likelihood for deciding that an event occurred by chance.
p=.05 = 1 time in 20, the result would be as large by chance when the null hypothesis is true.
![Page 21: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/21.jpg)
+Type I vs. Type II errors
Type I: False positive Likelihood of type 1 = α p=.05 = setting α to .05
Type II: False negative Likelihood of type 2 = β Power = 1-β
World
Yes No
You
Yes Correct detection(power)
Type I (α)
No Type II (β) Correct rejection
![Page 22: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/22.jpg)
+P-values
p-value is the likelihood of mean differences as large or larger than those observed in the data occurring by chance
p-value criteria (alpha ) allow us a binary answer to our questions
Questions – is a smaller p-value:
“More” significant?
Indicate a “Bigger” effect? (if so when?)
and how could we measure” effect”?
![Page 23: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/23.jpg)
+Compare these two statements
It’s ‘significant’, but how big is the effect?
I can see it’s big: but what is the p-value?
![Page 24: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/24.jpg)
+Confidence Intervals
Range of values within a given likelihood threshold (for instance 95%)
Closely related to p-values. p = 1-CI i.e., if p<.05, 95% CI will not include 0 (no difference) Would you rather have a CI or a p-value? Why?
What is an effect size?
![Page 25: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/25.jpg)
+P and CI
You can’t go from p to CI!
You can go from CI to p At a p=.05, 95%CIs will overlap less than 25% At p= .01, the 95% CI bars just touch
![Page 26: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/26.jpg)
+Units of a Confidence Interval
Unlike p, CIs are given in the units of the DV Cumming and Finch (2005) BMI in people on a low carb diet might be19-23 kg/m2
Cumming, G. and Finch S.(2005). Inference by eye: confidence intervals and how to read pictures of data. American Psychologist. 60:170-80. PMID: 15740449
![Page 27: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/27.jpg)
+Standard Errors and Standard Deviations
SE is (typically) the standard error of the mean The precision with which we have estimated the population
mean based on our sample Computationally, it is ∂/sqrt(n)
A 95% confidence interval is ± 1.96 SE
![Page 28: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/28.jpg)
+Example: coin toss
Random sample of 100 coin tosses, of a coin believed to be fair
We observed number of 45 heads, and 55 tails: Is the coin fair?
![Page 29: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/29.jpg)
+Binomial test
binom.test(x=45, n=100, p=.5, alternative="two.sided”)
number of successes = 45, number of trials = 100
p-value = 0.3682
alternative hypothesis: true probability of success != 0.5
95 percent confidence interval: 0.3503 0.5527
sample estimates: probability of success: 0.45
![Page 30: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/30.jpg)
+Categorical Data
Fisher’s Exact Test
Categorical data resulting from classifying objects in one of two ways
Tests significance of the observed "contingency" of the two outcomes. Fisher, R. A. (1922). On the interpretation of χ2 from
contingency tables, and the calculation of P. Journal of the Royal Statistical Society, 85(1), 87-94.
![Page 31: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/31.jpg)
+The Lady Drinking Tea
Question: Does Tea taste better if the milk is added to the tea, or vice versa?
Null Hypothesis: The drinker cannot tell
Subjects: Ms Bristol
Experiment: 8 "trials" (cups): 4 in each way, in random order
DV: Milk versus Milk second discrimination
Enter data into 2 x 2 contingency table
![Page 32: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/32.jpg)
+Fisher Contingency Table
A = c(1, 1, 1, 0, 1, 0, 0, 0) # vector of guesses
B = c(1, 1, 1, 1, 0, 0, 0, 0) # vector of Teas
guessTable <- table(A,B) # contingency table
labels = list(Guess = c("Milk", "Tea"), Truth = c("Milk", "Tea")) # make labels
dimnames(guessTable)= labels # add label
fisher.test(guessTable, alternative = "greater") # test
GuessMilk Tea
TruthMilk 3 1
Tea 1 3
![Page 33: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/33.jpg)
+Can she tell?
Fisher's Exact Test for Count Data
p-value = 0.24 # association could not be established
Alternative hypothesis: true odds ratio is greater than 1
95% confidence interval: 0.313 – Inf
Sample odds ratio: 6.40
![Page 34: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/34.jpg)
+What if we have two continuous variables?
Are they related
Q: If you have continuous depression scores and cut-off scores, which is more powerful?
![Page 35: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/35.jpg)
+Correlation of two continuous variables: Pearson’s r
All variables continuous
Pearson
![Page 36: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/36.jpg)
+Correlation: what are the maximum and minimum correlations?
![Page 37: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/37.jpg)
+Power (1-β)
Probability that a test will correctly reject the null hypothesis.
Complement of the false negative rate, β False negative = missing a real effect 1-β = p (correctly reject a false null hypothesis)
![Page 38: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/38.jpg)
+Power and how to get it
Probability of rejecting the null hypothesis when it is false
Whence comes power?
![Page 39: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/39.jpg)
+Power applied to a correlation
Samples of n=30 from a population in which two normal traits correlate 0.3
r=0.3
xy = mvrnorm (n=30, mu=rep(0,2), Sigma= matrix(c(1,r,r,1) ,nrow=2, ncol=2));
xy = data.frame(xy);
names(xy) <- c("x", "y");
qplot(x, y, data = xy, geom = c("point" , "smooth"), method=lm)
![Page 40: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/40.jpg)
+Power of a correlation test
library(pwr)
pwr.r.test(n = 30, r = .3, sig.level = 0.05)
n = 30
r = 0.3
sig.level = 0.05
power = 0.359
alternative = two.sided
![Page 41: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/41.jpg)
+Power: r = .3
![Page 42: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/42.jpg)
+ t-test
When we wish to compare means in a sample, we must estimate the standard deviation from the sample
Student's t-distribution is the distribution of small samples from normally varying populations
![Page 43: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/43.jpg)
+t-distribution function
t is defined as the ratio:
Z/sqrt(V/v) Z is normally distributed with expected value 0 and
variance 1; V has a chi-square distribution with ν degrees of
freedom;
![Page 44: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/44.jpg)
+Normal and t-distributions
Normal is in blue
Green = t with df = 1
Red = t with df = 3 (far right = df increasing to 30)
![Page 45: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/45.jpg)
+Power of t-test
power.t.test(n=15, delta=.5)
Two-sample t test power calculation
n = 15 ; delta = 0.5 ; sd = 1; sig.level = 0.05
power = 0.26
alternative = two.sided
NOTE: n is number in *each* group
![Page 46: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/46.jpg)
+Linear regression
![Page 47: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/47.jpg)
+Linear regression
fit = lm(y ~ x1 + x2 + x3, data=mydata)
summary(fit) # show results
anova(fit) # anova table
coefficients(fit) # model coefficients
confint(fit, level=0.95) # CIs for model parameters
fitted(fit) # predicted values
residuals(fit) # residuals
influence(fit) # regression diagnostics
![Page 49: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/49.jpg)
+Bootstrapping: Kurtosis differences
kurtosisDiff <- function(x, y, B = 1000){
kx <- replicate(B, kurtosi(sample(x, replace = TRUE)))
ky <- replicate(B, kurtosi(sample(y, replace = TRUE)))
return(kx - ky)
}
kurtDiff <- kurtosisDiff(x, y, B = 10000); mean(kurtDiff > 0) # p= 0.205 NS
![Page 50: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/50.jpg)
+Parametric Statistics 1
Assume data are drawn from samples with a certain distribution (usually normal)
Compute the likelihood that groups are related/unrelated or same/different given that underlying model
t-test, Pearson’s correlation, ANOVA…
![Page 51: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/51.jpg)
+Parametric Statistics 2
Assumptions of Parametric statistics1. Observations are independent
2. Your data are normally distributed
3. Variances are equal across groups Can be modified to cope with unequal ∂2
![Page 52: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/52.jpg)
+Non-parametric Statistics?
Non-parametric statistics do not assume any underlying distribution
They compute the likelihood that your groups are the same or different by comparing the ranks of subjects across the range of scores.
![Page 53: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/53.jpg)
+Non-parametric Statistics
Assumptions of non-parametric statistics1. Observations are independent
![Page 54: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/54.jpg)
+Non-parametric Statistics?
Non-parametric statistics do not assume any underlying distribution
Estimating or modeling this distribution reduces their power to detect effects…
So don’t use them unless you have to
![Page 55: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/55.jpg)
+Why use a Non-parametric Statistic?
Very small samples Leads to Type-1 (false alarm) errors
Outliers more often lead to spurious Type-1 (false alarm) errors in parametric statistics. Nonparametric statistics reduce data to an
ordinal rank, which reduces the impact or leverage of outliers.
![Page 56: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/56.jpg)
+Non-parametric Choices
Data type?
χ2
discrete
Question?
continuous
Number of groups?
Spearman’s Rank
association
Different central value
Mann-Whitney UWilcoxon’s Rank Sums
Kruskal-Wallis test
two-groups
more than 2
Brown-Forsythe
Difference in ∂2
![Page 57: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/57.jpg)
+Non-parametric Choices
Data type?
χ2
discrete
Question?
continuous
Number of groups?
Spearman’s Rank
Like a Pearson’s R
Mann-Whitney UWilcoxon’s Rank Sums
Kruskal-Wallis test
two-groups
more than 2 Like ANOVA
Like Student’s t
No alternative
Different central value
Brown-Forsythe
Difference in ∂2
Like F-test
association
![Page 58: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/58.jpg)
+Binomial test
binom.test(45, 100, .5, alternative="two.sided”)
number of successes = 45, number of trials = 100,
p-value = 0.3682
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval: 0.350 0.5527
Sample estimates: probability of success 0.45
binom.test(51,235,(1/6),alternative="greater")
![Page 59: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/59.jpg)
+Spearman Rank test (ρ (rho))
Named after Charles Spearman,
Non-parametric measure of correlation Assesses how well an arbitrary monotonic function
describes the relationship between two variables,
Does not require the relationship be linear
Does not require interval measurement
![Page 60: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/60.jpg)
+Spearman Rank (ρ rho)
d = difference in rank of a given pair n = number of pairs
Alternative test = Kendall's Tau (Kendall's τ)
![Page 61: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/61.jpg)
+Mann-Whitney U
AKA: “Wilcoxon rank-sum test Mann & Whitney, 1947; Wilcoxon, 1945
Non-parametric test for difference in the medians of two independent samples Assumptions:
Samples are independent Observations can be ranked (ordinal or better)
![Page 62: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/62.jpg)
+Mann-Whitney U
U tests the difference in the medians of two independent samples
n1 = number of obs in sample 1
n2 = number of obs in sample 2
R = sum of ranks of the lower-ranked sample
![Page 63: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/63.jpg)
+Mann-Whitney U or t?
Should you use it over the t-test? Yes if you have a very small sample (<20)
(central limit assumptions not met) If your data are really ordinal Otherwise, probably not.
It is less prone to type-I error (spurious significance) due to outliers.
But does not in fact handle comparisons of samples whose variances differ very well (Use unequal variance t-test with rank data)
![Page 64: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/64.jpg)
+Wilcoxon signed-rank test (related samples)
Same idea as Mann-U, generalized to matched samples
Equivalent to non-independent sample t-test
![Page 65: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/65.jpg)
+Kruskall-Wallis
Non-parametric one-way analysis of variance by ranks (named after William Kruskal and W. Allen Wallis)
tests equality of medians across groups.
It is an extension of the Mann-Whitney U test to 3 or more groups.
Does not assume a normal population,
Assumes population variances among groups are equal.
![Page 66: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/66.jpg)
+Aesop: Mann-Whitney U Example
Suppose that Aesop is dissatisfied with his classic experiment in which one tortoise was found to beat one hare in a race.
He decides to carry out a significance test to discover whether the results could be extended to tortoises and hares in general…
![Page 67: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/67.jpg)
+Aesop 2: Mann-Whitney U
He collects a sample of 6 tortoises and 6 hares, and makes them all run his race. The order in which they reach the finishing post (their rank order) is as follows:
tort = c(1, 7, 8, 9, 10,11)
hare = c(2, 3, 4, 5, 6, 12) Original tortoise still goes at warp speed,
original hare is still lazy, but the others run truer to stereotype.
![Page 68: + Refresher in inferential statistics Tim.bates@ed.ac.uk stats](https://reader035.vdocument.in/reader035/viewer/2022062304/56649e0d5503460f94af6fcd/html5/thumbnails/68.jpg)
+Aesop 3: Mann-Whitney U
wilcox.test(tort, hare)
Wilcoxon = W = 25, p-value = 0.31 Tortoises and hares do not differ tort = c(1, 7, 8, 9, 10,11) (n2 = 6)
hare = c(2, 3, 4, 5, 6, 12) (n1 = 6, R1 =32)