2024-11-14
t = \(\frac{difference\, between\, two\, means}{standard\, error\, of\, the\, difference}\)
t = \(\frac{\bar{y}_A-\bar{y}_B}{S.E.D}\)
Lecture 3 explains the standard error of the mean (an estimate of how far the sample mean is likely to be from the population mean)
For two independent variables, the variance of a difference is the sum of the separate variances
\(S.E.M =\sqrt{\frac{s^2}{n}}\)
\(S.E.D =\sqrt{\frac{s_A^2}{n_A}+\frac{s_B^2}{n_B}}\)
t = \(\frac{\bar{y}_A-\bar{y}_B}{\sqrt{\frac{s_A^2}{n_A}+\frac{s_B^2}{n_B}}}\)
library(SMPracticals)#Data is in this package
t.test(formula = height ~ type, # Formula
data = darwin) # Dataframe containing the variables
Welch Two Sample t-test
data: height by type
t = 2.4371, df = 22.164, p-value = 0.02328
alternative hypothesis: true difference in means between group Cross and group Self is not equal to 0
95 percent confidence interval:
0.3909566 4.8423767
sample estimates:
mean in group Cross mean in group Self
20.19167 17.57500
Outcrossed plants (mean +/- 95% confidence intervals: 20.19(0.39)) are larger than selfed plants (17.58 (4.48)) (t-test: t = 2.4371, df =22.164, p = 0.02328)
wilcox.test(formula = len ~ supp, # Formula
data = ToothGrowth, exact=FALSE) # Dataframe containing the variables
Wilcoxon rank sum test with continuity correction
data: len by supp
W = 575.5, p-value = 0.06449
alternative hypothesis: true location shift is not equal to 0
There is no significant difference between supplement types on their effect on tooth growth (Wilcoxon Rank-Sum Test: W= 575.5, n = 60, p = 0.06449)
Pearson's product-moment correlation
data: babies$gestation and babies$bwt
t = 15.609, df = 1221, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.3600303 0.4535398
sample estimates:
cor
0.407854
The length of gestation correlates with a baby’s weight (pearson: r = 0.408, t = 15.609, df =1221, p < 0.0001 )
Spearman's rank correlation rho
data: babies$gestation and babies$bwt
S = 181438572, p-value < 2.2e-16
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.4048838
The length of gestation correlates with a baby’s weight (spearman: rho = 0.405, n = 1223, p < 0.0001 )
Blue.eyes | Brown.eyes | Row.totals | |
---|---|---|---|
Fair hair | 38 | 11 | 49 |
Dark hair | 14 | 51 | 65 |
Column totals | 52 | 62 | 114 |
Pearson's Chi-squared test with Yates' continuity correction
data: count
X-squared = 33.112, df = 1, p-value = 8.7e-09
Hair colour is associated with eye colour (\(\chi^2\) = 33.112, d.f. = 1, p = \(8.7 \times 10^{-9}\))
Are men and women different heights?
Is height correlated with weight?
Is hair colour associated with eye colour
These are examples of almost any biological question. Can you think of one that doesn’t fit above? At a simple level, there isn’t anything you can’t ask with the tools you have
Two samples