Lecture 2

September 30, 2026

Slides

Jupyter Notebook


HW2 (Due on Friday Oct 2nd)

In an epigenome-wide survey of normal bronchial cells brushed and primary-cultured from 54 donors, we investigated if average cytosine methylation was associated with history of  smoking. (https://pubmed.ncbi.nlm.nih.gov/39980243/)

In this data set, you will find the global average methylation level, smoking status (0: never smoker, 1: former smoker, 2: current smoker), age, sex (-1: Female, 1: Male), cancer status (0: no cancer, 1: had cancer), and COPD status (0: No, 1: Yes). 

Investigate:
1. If global methylation level is associated with smoking status
2. If global methylation level is associated with age among never smokers
Note that you must justify that your choice of statistical test is appropriate.  


Take home messages

1. Earn your right for modeling

2. All models are wrong, some are useful

3. principle of least Squared Estimate

4. decomposition of the total variation and $R^2$

5. multiple testing and publication bias


We would like to achieve two things in this lecture, understand the basic concept of regression and learn how to fit a regression model using R. The two goals are very much intertwined, as the ability to visualizing data is indispensable in understanding the concept and properly applying regression model.


Data Visualization and Regression Model


One should never fit a regression model without visualizing the data first. Regression, in nutshell, models relationship between two or more variables. I still remember in my high school and college physics class, I was asked to take some measurements and mark them down on a grid sheet, then draw a line through those dots to get the relationship between two variables. Such practice is centuries old and proven, works out well without any mathematical formulae being involved. Although the lines drawn by different person will differ slightly but they will never be too far off from each other, and from any true relationship between two variables. On the other hand, if one blindly fits a straight line through a cloud of points that are clearly bent as in the figure below, no matter how accurate his computation is, his model (the straight line) does not fit the data properly.


Speaking of statistical models, I would rather describe them as proper or improper rather than right or wrong. As a matter of fact, except for the simplest problems, more often than not,  given the same dataset, two very experienced statisticians will give two different models, both could be proper and useful. As George E. P. Box, a prominent statistician who happens to be a son in law of Ronald Fisher, said:

"All models are wrong, but some are useful".


"Regression"


The term "*regression*" originates from a study on the relation between height between fathers and sons (again as I said, modern statistics has a lot to do with genetics), by Sir Francis Galton (1822–1911), cousin of Charles Darwin.  Karl Pearson is the most famous disciple of Galton. (The English scientific community must be rather small back then). From a data set of 1078 pairs of fathers and sons, which we will take a look in a short while, he obtained a model as


$$ \text{son’s height (in inches)} = 33.89 + 0.514 \text{ father’s height (in inches)}$$


So, if a father is 72 inches tall, using the model, the son's height is 70.898, not quite as tall of the father. If a father is 66 inches tall, the son's height is 67.814, not quite as short. Galton observed that taller fathers tend to have taller sons, and shorter fathers tend t have shorter sons, but the sons' heights tend to be closer to the average, he called this "regression towards the mean". The term regression, was somehow evolved in the statistical literature to describe general modeling of two or more variables, which goes way beyond the simple linear relationship between two continuous variables.


Galton observed that taller fathers tend to have taller sons, and shorter fathers tend t have shorter sons, but the sons' heights tend to be closer to the average, he called this "regression towards the mean". The term regression, however, goes way beyond the simple linear relationship between two continuous variables, and evolved in the statistical literature to describe any models that involves a response (outcome) $\mathbf{Y}$, a set of explanatory variables (independent variable, predictors) $\mathbf{X}$, and some error terms. Note that a response $\mathbf{Y}$ can also be multi-dimensional, and the models are called *multivariate regression* in statistical literatures.


$$ \mathbf{Y} = f(\mathbf{X},\epsilon) $$



Least Square Estimate


You can see that the father's and son's height does not really fall on a straight line but rather spread around the line. This is pretty much within our expectation, even sons of the same parents rarely have the same height, let along sons of different fathers with the same height. The prediction based on this simple straight line model is indeed the average height of sons given his father's height, without consideration or knowing other important factors such as mother's height, etc. In general, one should never expect to predict such things perfectly as it involves so many environmental factors, many of which cannot be measured accurately if they can be measured at all. If you are a college basketball fan as I am, you know what match madness is all about and how unpredictable those games are. Life is full of unknown and randomness. And for a properly stated statistical model, there should always be a *random component*. *A statistical model can only predict within the limit of the available data, and one should not ask more than what the data provides. No fancy models can compensate for the lack of information*.



Now we come back to the example of predicting son's height using father's height. In a regression model, we distinguish the variable that is used for prediction (in this example, father's height) and the variable that we want to predict (son's height). The latter is often called response, the former is called predictors, or explanatory variables if the emphasis of the model is not for prediction. Other terms used to describe these two types of variables are independent and dependent variables. A general form of a linear regression model can be written as

$$ y_i = \beta_0 + \beta_1 x_i + \epsilon_i, $$

where $y_i$ is the response at the $i$th observation, $x_i$ is the predictor at the $i$th observation, and $\epsilon_i$ is a random term, represents the part of $y_i$ that cannot be explained(or determined) by the straight line model $y=\beta_0+\beta_1x$. In our example, the $i$th observation refers to the $i$th father-son pair. Explicitly, the model only described the observed data. Implicitly, the model applies to subjects that are not observed yet, so that we can use it for prediction.


For each son, we have a prediction from the model, and we can get a difference between the observed height of son and the prediction, we can this difference a residual, note that residuals can be positive or negative. The size of the residual reflects how well the model fits the data. If we decide to stick with a simple straight line model, (as per *Occam's razor*, simpler is better unless there is enough reason to go more complicated), we would like to find a straight line (that is, values of the slope and the intercept) that result in the smallest residuals. In practice, the most popular way is to minimize the *residual sum squared* (RSS) $\sum (y_i - \hat{y}_i)^2$, where $\hat{y}_i= b_0 + b_1 x_i$ is the prediction based on the model, and $b_0$ and $b_1$ that minimizes this quantity is call least square fit or least square estimate. Other reasonable criteria could be the sum of absolute value of the residuals, $\sum |y_i - \hat{y}_i|$, and the maximum absolute value of the residuals $\max{|y_i-\hat{y}_i|}$. The least square fit is more popular because it is mathematically more tractable, and a closed form formulae can be obtained for $b_0$ and $b_1$. To use the latter two criteria, only a numerical solution is available.


RSS, the residual sum squared can be interpreted as the proportion of total variation of the response y (TSS) $\sum (y_i-\bar{y})^2$ that is not explained by the model. Hence, $R^2 = 1-RSS/TSS$ can be interpreted as the proportion of total variation that is explained by the model, and is commonly used to quantify how good a model fits the data. The mean squared residuals (MSE) $= RSS/(n-p)$ estimates of the variance of the random error term $\epsilon$ in the regression model, where $n$ is the number of observations, and $p=2$ is the number of parameters (aka $\beta_0$ and $\beta_1$ of the model).



One-Way ANOVA


We already learned about the decomposition of total variance into two components. in the context of linear regression. The total variation in the response is decomposed into two parts, variation explained by the straight line, and the variation not explained, aka, those of the residuals.


The same technique can be applied to many other situations and is called Analysis of Variance (ANOVA). As a matter of fact, most people would relate ANOVA to the analysis of comparing means of several groups, in which the total variation is decomposed into two parts: within-group variation and between group variation, in a very similar fashion as we did for the linear model, only more understandable.


Consider the following example. There are five groups of mice (presumably assigned randomly), each was given a different drug, and lymphocyte counts were measured after. We want to know if those drugs are equally effective?  That is, in the language of statistical inference, we want to test a null hypothesis that the different drugs have the same effect on lymphocyte count, and in the most mathematically rigorous terms, we can write the null hypothesis as

$$H_0: \mu_1 = \mu_2 = \mu_3 = \mu_4 = \mu_5,$$

where $\mu_i$ is the mean lymphocytes count of each group. Here you can imagine that $\mu_i$ is the average lymphocyte counts for all imaginary mice that could've given the ith drug.


The purpose of hypothesis testing is to quantify the evidence against the null hypothesis in data. And as you have all experienced already in this class, this is done through test statistics. For each test statistic, we acquire a pattern (so-called reference distribution) under the null hypothesis, either through mathematical derivation or by computer simulation. And you can compare your observed test statistic (from the data) to this distribution to see whether it falls into unlikely places, with the unlikelihood measured by the P-value.


It might sound challenging to come up with a test statistic for a hypothesis testing problem, but it is actually not the case. In fact,  anyone with good common sense can come up with some reasonable ones, and usually there are ways to get a P-value through permutation test, which requires no mathematical derivation of distributions for the test statistics. We will talk about permutation test later.


Follow the ANOVA technique we used in linear regression model, we will decompose the total variation in the following way: $$ \sum_{i,j} (y_{ij}-\bar{y})^2 = \sum_{i,j} (\bar{y}_i - \bar{y})^2 + \sum_{i,j} (y_{ij}-\bar{y}_i)^2, $$

where $y_{ij}$ represents the response of the $j$th mouse of the $i$th group, $\bar{y}$ is the overall average, and $\bar{y}_i$ is the average of the $i$th group. If you realize that $\bar{y}_i$ is how you would predict an new response in the $i$th group, and replace $\bar{y}_i$ by $\hat{y}_{ij}$, then this decomposition becomes even more of the same as the one for the linear model. In order to show this similarity, I purposely use $\sum_{i,j}$ instead of a more precise $\sum_{i=1}^{I}\sum_{j=1}^{n_i}$, in which $I$ is the number of groups, $n_i$ is the number of mice in $i$th group.


If the null hypothesis is true, we expect the difference between groups (the first team on the right side) to be small, compare to the variations within the groups (the second term). But for such comparison to be fair, these two components need to be adjusted by the number of mouse and the number of groups. As we saw before, all such computation can be displayed in a nice table but we can let R handle all the dirty work.



Multiple Comparison or Multiple Testing

You must have wondered, why do we want to go through this exercise by looking at all 5 groups together. Can't we simply compare two groups at a time with a t-test.


The answer is, yes you can, but not without complications. The trouble is, when you do many comparisons, you increase the chance of Type I error. This is the danger of multiple comparison or multiple testing.


Imagine that there are 10000 labs perform some dumb experiment, say investigating if the mouse will live longer if the lab tech brushes his/her teeth more often. Just by chance, we expect that 100 out of 10000 labs will get a P-value less than 0.01, and 10 out of 10000 labs will get a P-value less than 0.001. And some luck lab might get a P-value of 0.0001, and they can publish a paper on there highly statistically significant results. And this is sometimes referred to as "publication bias" as all negative results do not get published, and many of published "positive" results achieved statistical significance simply by luck.


A side note on publication bias:

*A very important consequence of multiple testing is publication bias, because historically and still up to today, publishing negative finding is much more difficult than "positive" findings, based on a single P-value.  Imagine 100 labs around the globe worked on the similar studies, 5 got published because their Pvals are below 0.05, and none from the other 95 was ever published. To make things even worse, if someone decides to do a meta-analysis on the five publications and get even "stronger" statistical evidence. Therefore, in general, meta-analysis is NOT valid unless it includes ALL similar studies within its scope.*



To combat multiple comparisons and control the overall Type I error, we need to set a more stringent threshold for P-values. A simple and general solution is Bonferroni correction, which sets the threshold of each of 10000 test at  α/10000 , where  α  is your targeted overall Type I error rate. The Bonferroni correction is often too stringent as it assumes that all the tests are independent. Therefore, more specific adjustment are often developed for different problems to control the Type I error without overkilling.



Comments

Popular posts from this blog

Final Exam

Syllabus