Lecture 3: Chi-Square Tests (Continued)
Lecture on Oct 9th, 2020
Chi-Square Tests (Continued)
4. General Goodness-of-Fit Test for One Categorical Variable.
In the first lecture, we learned the general form of Pearson Chi-Square Statistic, and we did some numerical experiment to learn the sampling distribution of the test statistics for HWE test.
The HWE test is a special case of what we call Goodness-of-Fit test, in which we want to see if the data fit the expected frequencies in a $K$ categories. If no parameter to be estimated in computing the Pearson $X^2$, the degrees of freedom is $K-1$. If $l$ parameters need to be estimated using the same data, the degrees of freedom reduces to $K-l-1$.
A useful fact to remember is that the mean of a $X^2$ distribution with $d$ degree of freedoms is $d$.
5. Genetic Association Test
Genetic Association studies have been very popular in last decade. Billions of dollars have been spent and hundreds of thousands individuals have their genome genotyped. They all look for a simple signal. That is, the distribution of genotypes differ among people with different phenotypes.
Consider a study with diabetes. Say we recruited 1000 diabetes patients, and 1500 controls. Assume that they are from the same genetic background, which is very important. If the patients are recruited in US, and controls are recruited in Mexico, then all we would be looking at the genetic difference between two populations. Say a candidate loci is genotyped, and the results can be summarized in the table
$$
\begin{array}{c|ccc}\hline
& AA & Aa & aa\\ \hline
Cases & O_{10} &O_{11} & O_{12}\\
Controls & O_{20} & O_{21} & O_{22} \\ \hline
\end{array}
$$
The null hypothesis here is that the loci has nothing to do with diabetes. Under this hypothesis, we expect that the genotypes has the same distribution in the cases and controls. Therefore, we estimate the proportion of AA to be $\hat{p}_{AA}=(O_{10}+O_{20})/N$, where N=2500 in this example, and the proportion of Aa and aa to be $\hat{p}_{Aa}=(O_{11}+O_{21})/N$ and $\hat{p}_{aa}=(O_{12}+O_{22})/N$.
The expected count of AA, Aa, and aa in the cases are
$E_{10}=1000\hat{p}_{AA}$,
$E_{11}=1000\hat{p}_{Aa}$,
$E_{12}=1000\hat{p}_{aa}$, respectively.
Similarly, the expected count of AA, Aa, and aa in the controls are
$E_{20}=1500\hat{p}_{AA}$,
$E_{21}=1500\hat{p}_{Aa}$,
$E_{22}=1500\hat{p}_{aa}$.
The Pearson $X^2$ can then be obtained using its general form. The degrees of freedom of this test is 2, which can be obtained from the following arguments. First, the original data has 4 total degrees of freedoms, as the row totals are fixed at 1000 and 1500 by study design, if we know the counts of two of three categories, the third is known. Second, we used three estimated parameters in computing $E_{ij}$, but $p_{AA}+p_{Aa}+p_{aa}=1$, so there are only two independent parameters. Therefore, we have $4-2=2$ degree of freedom remained. If you feel that such heuristic argument is hard to understand, you are with good companies. Karl Pearson himself had trouble getting the correct degree of freedoms during his lifetime and had some furious arguments with R. Fisher over this topic. Eventually after his death, his son Egon Pearson did a simulation study (Imagine how laborious it was without computer programs) which showed that Fisher was right. Fortunately, with modern computational power, we can do such simulation in a matter of minutes, and this will be part of your homework.
The table below lists the genotype counts at a particular loci. Under the null hypothesis, we can estimate $p_{AA}$ as $\hat{p}_{AA}=(489+632)/2500=0.4484$, etc. As part of our homework, finish the computation of the Pearson $X^2$ statistic.
$$
\begin{array}{c|ccc}\hline
& AA & Aa & aa\\ \hline
Cases & 489 & 441 & 70\\
Controls & 632 & 670 & 198 \\ \hline
\end{array}
$$
6. Homework
1. Finish computing the Pearson Chi-Square statistic for testing genetic association
2. Do a numerical experiment to generate the sampling distribution of $X^2$ statistics for the association test, but with different genotype frequencies and the sample sizes, to determine if the sampling distribution is approximately $X^2$ regardless of the underlying genotype frequency
Below are some notes and template R-code on the problem.
# Our goal is to simulate Pearson Chi-square statistics for genetic association tests.
# set number of cases and controls
# you can later change it to any other sample size
n1 <- 1000
n2 <- 1500
# We pretend to be God and set-up frequency of genotypes, can be any three numbers adds up to one, for example, c(0.3,0.5,0.2). Later you need to change it to some other numbers.
# change these numbers to something different
p1.geno <- c(0.3,0.5,0.2)
# Under the null hypothesis, the cases and controls have the same genotype distribution
p2.geno <- p1.geno
# Simulate the observed counts from multinomial distributions
# specify the sample size by replacing the ???
O1 <- rmultinom(1,size=??? ,prob=p1.geno)
O2 <- rmultinom(1,size=??? ,prob=p2.geno)
# Now we have simulated data in O1 and O2
# compute the expected genotype counts in Cases and Controls respectively
# first estimate the genotype freq under H0
f.AA.hat <-
f.Aa.hat <-
f.aa.hat <-
# get the expected count
E1 <-
E2 <-
# Compute the Pearson chi-square statistics, the first sum is over the cases, the second of the controls
PChi2 <- sum((O1-E1)^2/E1)+sum((O2-E2)^2/E2)
# Now repeat above 1000 times using a for-loop.
PChi2 <- rep(0,1000)
for(i in 1:1000){
O1 <- rmultinom(1,size=,prob=p1.geno)
O2 <- rmultinom(1,size=,prob=p2.geno)
f.AA.hat <-
f.Aa.hat <-
f.aa.hat <-
E1 <-
E2 <-
PChi2[i] <- sum((O1-E1)^2/E1)+sum((O2-E2)^2/E2)
}
# do a histogram
hist()
# generate a qqplot against a chisq distribution with df=2
qqplot(,)
# add a straight line
abline(0,1)
The HWE test is a special case of what we call Goodness-of-Fit test, in which we want to see if the data fit the expected frequencies in a $K$ categories. If no parameter to be estimated in computing the Pearson $X^2$, the degrees of freedom is $K-1$. If $l$ parameters need to be estimated using the same data, the degrees of freedom reduces to $K-l-1$.
A useful fact to remember is that the mean of a $X^2$ distribution with $d$ degree of freedoms is $d$.
5. Genetic Association Test
Genetic Association studies have been very popular in last decade. Billions of dollars have been spent and hundreds of thousands individuals have their genome genotyped. They all look for a simple signal. That is, the distribution of genotypes differ among people with different phenotypes.
Consider a study with diabetes. Say we recruited 1000 diabetes patients, and 1500 controls. Assume that they are from the same genetic background, which is very important. If the patients are recruited in US, and controls are recruited in Mexico, then all we would be looking at the genetic difference between two populations. Say a candidate loci is genotyped, and the results can be summarized in the table
$$
\begin{array}{c|ccc}\hline
& AA & Aa & aa\\ \hline
Cases & O_{10} &O_{11} & O_{12}\\
Controls & O_{20} & O_{21} & O_{22} \\ \hline
\end{array}
$$
The null hypothesis here is that the loci has nothing to do with diabetes. Under this hypothesis, we expect that the genotypes has the same distribution in the cases and controls. Therefore, we estimate the proportion of AA to be $\hat{p}_{AA}=(O_{10}+O_{20})/N$, where N=2500 in this example, and the proportion of Aa and aa to be $\hat{p}_{Aa}=(O_{11}+O_{21})/N$ and $\hat{p}_{aa}=(O_{12}+O_{22})/N$.
The expected count of AA, Aa, and aa in the cases are
$E_{10}=1000\hat{p}_{AA}$,
$E_{11}=1000\hat{p}_{Aa}$,
$E_{12}=1000\hat{p}_{aa}$, respectively.
Similarly, the expected count of AA, Aa, and aa in the controls are
$E_{20}=1500\hat{p}_{AA}$,
$E_{21}=1500\hat{p}_{Aa}$,
$E_{22}=1500\hat{p}_{aa}$.
The Pearson $X^2$ can then be obtained using its general form. The degrees of freedom of this test is 2, which can be obtained from the following arguments. First, the original data has 4 total degrees of freedoms, as the row totals are fixed at 1000 and 1500 by study design, if we know the counts of two of three categories, the third is known. Second, we used three estimated parameters in computing $E_{ij}$, but $p_{AA}+p_{Aa}+p_{aa}=1$, so there are only two independent parameters. Therefore, we have $4-2=2$ degree of freedom remained. If you feel that such heuristic argument is hard to understand, you are with good companies. Karl Pearson himself had trouble getting the correct degree of freedoms during his lifetime and had some furious arguments with R. Fisher over this topic. Eventually after his death, his son Egon Pearson did a simulation study (Imagine how laborious it was without computer programs) which showed that Fisher was right. Fortunately, with modern computational power, we can do such simulation in a matter of minutes, and this will be part of your homework.
The table below lists the genotype counts at a particular loci. Under the null hypothesis, we can estimate $p_{AA}$ as $\hat{p}_{AA}=(489+632)/2500=0.4484$, etc. As part of our homework, finish the computation of the Pearson $X^2$ statistic.
$$
\begin{array}{c|ccc}\hline
& AA & Aa & aa\\ \hline
Cases & 489 & 441 & 70\\
Controls & 632 & 670 & 198 \\ \hline
\end{array}
$$
6. Homework
1. Finish computing the Pearson Chi-Square statistic for testing genetic association
2. Do a numerical experiment to generate the sampling distribution of $X^2$ statistics for the association test, but with different genotype frequencies and the sample sizes, to determine if the sampling distribution is approximately $X^2$ regardless of the underlying genotype frequency
Below are some notes and template R-code on the problem.
# Our goal is to simulate Pearson Chi-square statistics for genetic association tests.
# set number of cases and controls
# you can later change it to any other sample size
n1 <- 1000
n2 <- 1500
# We pretend to be God and set-up frequency of genotypes, can be any three numbers adds up to one, for example, c(0.3,0.5,0.2). Later you need to change it to some other numbers.
# change these numbers to something different
p1.geno <- c(0.3,0.5,0.2)
# Under the null hypothesis, the cases and controls have the same genotype distribution
p2.geno <- p1.geno
# Simulate the observed counts from multinomial distributions
# specify the sample size by replacing the ???
O1 <- rmultinom(1,size=??? ,prob=p1.geno)
O2 <- rmultinom(1,size=??? ,prob=p2.geno)
# Now we have simulated data in O1 and O2
# compute the expected genotype counts in Cases and Controls respectively
# first estimate the genotype freq under H0
f.AA.hat <-
f.Aa.hat <-
f.aa.hat <-
# get the expected count
E1 <-
E2 <-
# Compute the Pearson chi-square statistics, the first sum is over the cases, the second of the controls
PChi2 <- sum((O1-E1)^2/E1)+sum((O2-E2)^2/E2)
# Now repeat above 1000 times using a for-loop.
PChi2 <- rep(0,1000)
for(i in 1:1000){
O1 <- rmultinom(1,size=,prob=p1.geno)
O2 <- rmultinom(1,size=,prob=p2.geno)
f.AA.hat <-
f.Aa.hat <-
f.aa.hat <-
E1 <-
E2 <-
PChi2[i] <- sum((O1-E1)^2/E1)+sum((O2-E2)^2/E2)
}
# do a histogram
hist()
# generate a qqplot against a chisq distribution with df=2
qqplot(,)
# add a straight line
abline(0,1)
Comments
Post a Comment