Basic Statistics
Let’s review some basic statistical concepts and tools.
Sample Mean
Definition 1 (Sample Mean)
The sample mean is defined as,
where is the -th observation in the sample.
If we’re drawing from a population, the population mean is denoted by .
In R, we can calculate the sample mean using the mean() function.
x <- 1:10> mean(x)[1] 5.5
> sum(x)/lengt(x)[1] 5.5If we assume the components of the data vector are independent and identically distributed, the sample mean is an unbiased estimator of the population mean.
Sample Median
The sample median of is the middle value of the ordered data set.
Let the sorted data be denoted by . Then,
The sample median is simply median() in R.
The median is a special kind of quantile, which we will talk about later.
Important to note is that the median and mean can differ significantly, especially when the data is skewed.
The median is insensitive to a few unusually large or unusually small observations, this is called robustness.
Sample Variance
Definition 2 (Sample Variance)
The sample variance is defined as,
where is the sample mean.
The sample variance is an unbiased estimator of the population variance.
This will give us an overall sense of the variation in the data, as the name suggests. NB: Remember that, the unit of the variance is squared, so it’s not directly interpretable.
In R, we can calculate the sample variance using the var() function.
Sample Standard Deviation
The sample standard deviation is the square root of the sample variance,
Unlike the variance, the standard deviation is in the same unit as the data, so it’s more interpretable.
In R, we can calculate the sample standard deviation using the sd() function.
If we’re drawing from a population, the population standard deviation is defined as,
Sample Quantile
For , the -th quantile for the sample is the data at position in the sorted data.
Wehn this is not an integer, a weighted average is used.
This value essentially splits the data so that (roughly) is smaller and is larger. The median is the quantile.
The -th quantile is also called the -th percentile.
For a population, the -th quantile for a distribution is defined as , if is strictly increasing so that the inverse exists. Otherwise the definition is a little bit more complicated.
In R, we can calculate the quantiles using the quantile() function.
quantile(x, 0.25) # 25th percentilequantile(x, (0.25, 0.75)) # 25th and 75th percentilesQuantiles VS. Proportions
For a data vector we can ask two related but inverse questions.
What proportion of the data is less than or equal to a specified value? Or for a specified proporation, what value has this proportion of the data less than or equal?
The latter question is answered by the quantile function.
The inter-quantile range (IQR)
We are interested in the range of the middle 50% of the data, this would be the distance between the 75 percentile and the 25 percentile. Thus, the IQR is a single number.
In R we can calculate the IQR using the IQR() function.
Detecting Outliers
An outlier is an observation that is significantly different from other observations in the data set.
A rule of thumb is:
An observation is an outlier if it is more than from the closest quartile.
Also a good rule to remember is:
An outlier is said to be extreme if it is more than from the closest quartile.
Correlation
Definition 3 (Pearson Correlation Coefficient)
The pearson correlation coefficient of two data vectors and is defined as,
The value of is between -1 and 1, where 1 indicates a perfect positive linear relationship, -1 indicates a perfect negative linear relationship, and 0 indicates no linear relationship.
Definition 4 (Population Correlation Coefficient)
For a population, when , the population correlation coefficient is defined as,
In R, we can calculate the correlation coefficient using the cor() function.
NB: This is the pearson correlation coefficient, there are other types of correlation coefficients.
Properties of the Correlation Coefficient
- The vale of does not depend on the unit of measurement for each variable.
- The value of does not depend on which of the two variables are labeled , i.e. it is symmetric.
- The value of is between -1 and 1.
- The correlation coefficient is:
- -1 only when all the points lie on a line with a negative slope.
- 1 only when all the points lie on a line with a positive slope.
- The value of is a measure of the extent to which and are linearly related.
Modes and Skew
A mode of a distribution is a peak, or a local maximum, in its density.
It is a visual effect and has no rigorous mathematical definition.
A data set can be characterized by its number of modes. A unimodal distribution has a single mode (e.g Normal distribution), a bimodal distribution has two modes, and so on.
The tail of a distribution are the very large and very small values of the distribution (NB: This is not the best definition, but it will do for now).
A distribution is called long-tailed (or heavy-tailed) if the data set contains values far from the main body of the distribution.
A distribution is skewed if one tail is significantly heavier or longer than the other. Good to remember is that the antonym (opposite) of skew is symmetry.
A distribution with longer left tail is called left-skewed or negatively skewed.
Some good rules of thumb:
-
When a distribution is skewed positively (to the right) the mean is larger than the median.
-
When a distribution is skewed negatively (to the left) the mean is smaller than the median.
-
When a distribution is symmetric, the mean and median are equal.
Distributions
Let’s review some basic distributions.
Gamma Distribution
Definition 5 (Gamma Distribution)
A random variable is said to be gamma distributed with parameters , denoted as , if its PDF is given by,
The gamma function is given by,
One important property of is that .
For integer values of , .
When , the density becomes,
we get the exponential distribution. Thus, .
With this, if is an integer, can be written as sum of i.i.d random variables.
is called the shape parameter and is called the rate parameter.
The mean and variance of a gamma distribution are given by,
In R, we can generate random variables from a gamma distribution using the rgamma() function.
Beta Distribution
Definition 6 (Beta Distribution)
A random variable is said to have a beta distribution if its density is given by,
Where is the beta function,
so that integrates to 1.
The mean and variance of a beta distribution are given by,
In R, we can generate random variables from a beta distribution using the rbeta() function.
Chi-Squared Distribution
The or distribution is a special case of the gamma distribution, with and .
The integer is the parameter of the distribution and sometimes called the degree of freedom of the distribution. If , then and .
If , then .
Property:
If and are independent with and distributions, then .
In R, we can generate random variables from a chi-squared distribution using the rchisq() function.
Student’s t-Distribution
We use this t-distribution for CI (confidence intervals) and hypothesis testing. Which we will cover in the next part.
Densitity,
Mean and variance,
If , , and and are independant, then .
is the parameter of the t-distribution and is called the degree of freedom.
A special case is the , it is also called cauchy distribution.
Density for Cauchy,
In R, we can generate random variables from a t-distribution using the rt() function.
For cauchy, we can use the rcauchy() function.