# Statistical Inference
Inferential Statistics allow us to make generalizations about the population from the samples. This process of sampling introduces errors as this is never a perfect representation of the underlying data. The statistics thus computed are supposed to be an estimate of the true population parameters. It allows you to form a distribution of the population from the sampled data by accounting for the errors in the sampling,, thereby allowing you to make predictions about data that is not yet seen or sampled
## 1-sample t-test
Hypothesis test for mean (comparing the sample to expected population mean $\mu_0$)
- Suppose we know mean BMI some years ago in US was 25.3.
- Suppose we take 25 samples and find 27.8 mean SD=6
- Has it increased from past?
Null Hypothesis -> mean hasn't changed
Alt Hypothesis -> mean has increased
We assume Null hypothesis is true and see if we can find evidence against it
[[Probability Theory#Sampling Distribution|Sampling Distribution]] assuming null hypothesis is true
![[Pasted image 20211210230034.png]]
### t-statistic
$\mu_0$ is hypothesized value
$t_{STAT}=\frac{\bar{X}-\mu_0}{\frac{s}{\sqrt{n}}}$
Assuming:
1. Simple random sample
2. independent observations
3. large sample size or population is distributed
If Null hypothesis is true probability of getting $\bar{x}$ is 1.9%. -> either null hypothesis is true but we got some rare data. Or null hypothesis is not true
Because p-value $\alpha$ is small (<5%) we have evidence to reject null hypothesis
Statistical significance does not mean scientific significance.
## 2-sided test vs 2-sided test
- One sided test only tests if $\mu_{new} >\mu_0$
- two sided tests also tests for $\mu_{new} \ne\mu_0$
![[Pasted image 20211210231700.png]]
2-sided test has a larger value (2 times) than 1-sided and is more conservative
Look at American statistics guidance on p-value
## Hypothesis test vs confidence interval
two-sided hypothesis test $\alpha$ = 0.05
confidence interval 95%
### Hypothesis test
$H_0$ : $\mu$ = $\mu_0$ , $H_A$ : $\mu$ $\ne$ $\mu_0$ ,
$t_{STAT}=\frac{\bar{X}-\mu_0}{\frac{S}{\sqrt{n}}}$
what is p-value in relation with $\alpha$
$\mu_0$ is a point of reference (mean of the sample/population before giving the drug if you are testing for effectiveness of a drug.)
### Confidence interval
$\bar{X}\pm t_{n-1}^{conf}\frac{S}{\sqrt{n}}$
$\bar{X}$ is the point of reference.
P-value and confidence interval are going to agree as long as $\alpha$ is 0.05 and confidence interval is 95%
- its two ways of saying the same thing
| | $H_0$ True | $H_A$ True |
| ----------------- | ----------------------- | ---------------------------------- |
| Fail To Reject $H_0$ | True Neg. (Specificity | False Neg. (Type II $\beta$) |
| Reject $H_0$ | False Pos. (Type I $\alpha$) | True Pos. Sensitivity (Power ($1-\beta$))|
- Typically we choose $\alpha$
- $\beta$ and hence power depends on
- $\alpha$
- $n$ sample size
- $(\mu_A - \mu_0)$ the difference we are trying to detect
$\alpha$ - Probability of rejecting $H_0$ when $H_0$ is True.
$\beta$ - Probability of failing to rejecting $H_0$ when $H_A$ is True.
Power - Probability of rejecting $H_0$ when $H_A$ is True.
## Bivariate analysis
Studying influence of X on Y
X- independent variable/predictor/explanatory variable/ covariate
Y - dependent variable/ outcome/ response
## Parametric vs Non-parametric Statistics
Parametric statistics is based on an assumption about the distribution of population (like Normal, Binomial, etc.). Non parametric statistics are not based on assumptions
### Categorical X Numerical Y
- box plots, t-test, anova, wilcox
- How many groups
- Paired Independent
- Paired/Dependent group (before/after; left/right; twins, etc.) i.e its the same person or people are matched. So idea is person in group A is analog to person in group B
- Independent group (smokers/non smokers; male/female) i.e they are different people independent
| | 2 Paired | 3+ Paired | 2 Independent | 3+ Independent |
| -------------- | -------------------- | ----------------------- | ------------------------------------------ | --------------- |
| Parametric | Paired t-test | repeated measures anova | [[2-Sample T-test]] | One-way Anova |
| Non Parametric | Wilcoxon signed rank | Friedman's test | Wilcoxon rank-sum aka. Mann-Whitney u test | Krauskal Wallis |
### Paired t-test
Paired t-test is a parametric approach used to compare means of two paired groups (Before/After treatment)
Example:
![[Pasted image 20211212205400.png]]
#### Hypothesis
$H_0$ : $\mu_A$ = $\mu_B$ ; $\mu_A-\mu_B=0$
$H_A$ : $\mu_A$ $\ne$ $\mu_B$ , $\mu_A-\mu_B<0$
Take difference between each pair and do an [[#1-sample t-test]]
### Wilcoxon Signed Rank test
Non parametreic alternative to paired-t test. If you have a small sample size and cannot assume the mean is normally distributed (or if you want to test median change instead of mean) this method is better
- Non-parametric approaches are lower power - i.e. less likely to reject null hypothesis compared to parametric approach. However make fewer assumptions
#### Sign test
too simple to be useful
$H_0$: $Median_{DIFF}=0$
$H_A$ : $Median_{DIFF}<0$
Just looks at sign. eg. 8 individuals had decrease and 3 individuals have increase. What is the pobability of this occuring when the median should be 0. Use binomial distribution. Sign test does not considere magnitude of change. Hence we need wilcoxon ranked sign test
#### Ranked sign test
- 8 individuals had decrease and 3 had increase (sign test)
- sum of ranks should be equally distribution (33 for each i.e sum of all numbers ) but sum of ranks with decrease is 56.5 and sum of increases is 9.5
- P-value - probabilty (sum of decreases >= 5.4 if expected =33)
[[2-Sample T-test]]
[[ANOVA]]
[[Pearson's Chi-Square Test of Independence]] - Can be used to test for independence between two variables (X and Y) that are both categorical/factors
- Categorical X Categorical Y
1. bar plots; [[Pearson's Chi-Square Test of Independence]], fishers
5. Numerical X Numerical Y
1. [[Simple Linear Regression]]; pearson/spearman correlation
## Multivariate Analysis