M. Drew LaMar
February 3 and 5, 2016
“While nothing is more uncertain than a single life, nothing is more certain than the average duration of a thousand lives.”
- Elizur Wright
Definition:The
frequency distribution of a variable is the number of occurrences of all values of that variable in the data.
Definition:The
relative frequency distribution of a variable is the fraction of occurrences of all values of that variable in the dataor population .
Question:What type of plot represents the frequency (relative frequency) distribution for a discrete variable?
Answer:Bar plot
Definition: A
bar plot uses the height of rectangular bars to display the frequency distribution (or relative frequency distribution) of a categorical variable.
Death by tiger
Question: What type of plot represents the frequency distribution for a continuous variable?
Answer: Histogram
Definition: A
histogram for a frequency distribution uses theheight of rectangular bars to display the frequency distribution of a numerical variable.
Definition: A
histogram for a relative frequency distribution uses thearea of rectangular bars to display the frequency distribution of a numerical variable.
Question: What’s the explanatory and response variable?
Answer: Neither
Load and show the data:
salmonSizeData <- read.csv(url("http://whitlockschluter.zoology.ubc.ca/wp-content/data/chapter02/chap02f2_5SalmonBodySize.csv"))
head(salmonSizeData)
year sex oceanAgeYears lengthMm massKg
1 1996 FALSE 3 513 3.090
2 1996 FALSE 3 513 2.909
3 1996 FALSE 3 525 3.056
4 1996 FALSE 3 501 2.690
5 1996 FALSE 3 513 2.876
6 1996 FALSE 3 501 2.978
Plot in a histogram:
histObj <- hist(salmonSizeData$massKg, right = FALSE, breaks = seq(1,4,by=0.5), col = "firebrick")
Question: What would the height of the second bar from the left be for a relative frequency distribution? (note: current height is 136)
Question: What would the height of the second bar from the left be for a relative frequency distribution, given that we have 228 fish?
hist(salmonSizeData$massKg, right = FALSE, breaks = seq(1,4,by=0.5), col = "firebrick", freq=FALSE)
\[ Area = Proportion \]
\[ Area = Height \times width \]
\[ Proportion = Height \times 0.5 \]
\[ 136/228 = Height \times 0.5 \]
\[ Height = 2\times 136/228 \]
\[ Height = 1.1929825 \]
Question: What happens with smaller bin width (say width of 0.1)?
hist(salmonSizeData$massKg, right = FALSE, breaks = seq(1,4,by=0.1), col = "firebrick", freq=FALSE)
Definition: The
population mean \( \mu \) is the sum of all the observations in the population divided by \( N \), the number of observations in the population (assuming it is finite - for now).
\[ \mu = \frac{1}{N}\sum_{i=1}^{N}Y_{i}\, \]
Definition: The
sample mean \( \overline{Y} \) is the sum of all the observations in the sample divided by \( n \), the number of sample observations.
\[ \overline{Y} = \frac{1}{n}\sum_{i=1}^{n}Y_{i}\, \]
Question: Is the population mean \( \mu \) a parameter or an estimate? What about the sample mean?
Note that every observation has equal weight (i.e. \( \frac{1}{n} \)), so any outliers can strongly affect the mean. It is a very democratic statistic - equal representation!
Definition: The
population median is the middle measurement of the set of all observations in the population (again, assume population finite for now).
Definition: The
sample median is the middle measurement of the set of all observations in the sample.
How do you compute the median? W&S version:
Look at special cases of \( n=3 \) and \( n=4 \)!!!
The median is the middle measurement of the distibution (different colors represent the two halves of the distribution). The mean is the center of gravity, the point at which the frequency distribution would be balanced (if observations had weight).
Note: The mean and median have the same units as the variable!!!
Definition: The
population variance \( \sigma^{2} \) is the average of the squared deviations of all observations from the population mean, and assuming a finite population, we have
\[ \sigma^{2} = \frac{1}{N}\sum_{i=1}^{N}(Y_{i}-\mu)^2 \]
Definition: The
sample variance \( s^{2} \) is the average of the squared deviations from the sample mean,
\[ s^{2} = \frac{1}{n-1}\sum_{i=1}^{n}(Y_{i}-\overline{Y})^2 \]
Question: Why \( n-1 \)??
Answer: Needed to be unbiased estimate!!
Definition: The
population standard deviation \( \sigma \) is the square root of population variance
\[ \sigma = \sqrt{\sigma^{2}} \]
Definition: The
sample standard deviation \( s \) is the square root of the sample variance,
\[ s = \sqrt{s^{2}} \]
Note #1: \( s \) is in general a biased estimator of \( \sigma \). The bias gets smaller as the sample size gets larger.
Note #2: \( s \) and \( \sigma \) have the same units as the random variable!!!
Note #3: If the frequency distribution is bell shaped, then about two-thirds (67%) of the observations will lie within one standard deviation of the mean, and 95% of the observations will lie within two standard deviations of the mean.
Note #3: If the frequency distribution is bell shaped, then about two-thirds (67%) of the observations will lie within one standard deviation of the mean, and 95% of the observations will lie within two standard deviations of the mean.
Definition: The
interquartile range \( IQR \) is the difference between the third and first quartiles of the data. It is the span of the middle 50% of the data.
Spiders with huge pedipalps, copulatory organs that make up about 10% of a male's mass.
\( ^{*} \) If whisker extends past the max or min of data, then the whisker will be the max or min of the data
Heuristic #1: The locate (mean and median) and spread (interquartile range and standard deviation) give similar information
when the frequency distribution is symmetric and unimodal (i.e. bell shaped).
Heuristic #2: The mean and standard deviation become less informative
when the distribution is strongly skewed or there there are extreme observations.
Since in biology many times the standard deviation scales with the mean, it can be more informative to look at the coefficient of variation.
Definition: The
coefficient of variation (CV) calculates the standard deviation as a percentage of the mean: \[ CV = \frac{s}{\bar{Y}}\times 100\% \]
In other words, the CV answers the question “How much variation is there relative to the mean?”
Make sure you read the book for the following discussions
Question: Why is this important to know?
My point here is that you are responsible for all book material, even if we don't cover it in lecture!
Measures | R commands |
---|---|
\( \overline{Y} \) | mean |
\( s^2 \) | var |
\( s \) | sd |
\( IQR \) | IQR \( ^* \) |
Multiple | summary |
\( ^* \) Note that IQR
has different algorithms. To match the algorithm in W&S, you should use IQR(___, type=2)
. There are different algorithms as there are different ways to calculate quantiles. (for curious souls, see ?quantiles
). For the HW, either version is acceptable. Default type in R is type=7
.
Measures | R commands |
---|---|
\( \overline{Y} \) | mean |
\( s^2 \) | var |
\( s \) | sd |
\( IQR \) | IQR |
Multiple | summary |
summary(mydata)
breadth
Min. : 1.00
1st Qu.: 3.00
Median : 8.00
Mean :11.88
3rd Qu.:17.00
Max. :62.00
IQR
would be \( 17-3 = 14 \).