```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(edgeR)
library(limma)
library(Glimma)
library(gplots)
library(org.Mm.eg.db)
load("../Robjects/preprocessing.Rdata")
```

```{r prepareData}
# Specify a design matrix with an intercept term
design <- model.matrix(~ CellType + Status, data = sampleinfo)
colnames(design)[1] <- "Intercept"
# estimate dispersion
dgeObj <- estimateCommonDisp(dgeObj)
dgeObj <- estimateGLMTrendedDisp(dgeObj)
dgeObj <- estimateTagwiseDisp(dgeObj)
# Fit the linear model
fit <- glmFit(dgeObj, design)
# luminal vs basal
lrt.BvsL <- glmLRT(fit, coef=2)
```


> ## Challenge 1 {.challenge}
> Conduct likelihood ratio tests for virgin vs lactate and show the top genes.

```{r solutionChallenge1}
lrt.BvsL <- glmLRT(fit, coef=4)
topTags(lrt.BvsL)
```

> ## Challenge 2 {.challenge}
>
> 1.Fit a model with interaction: What is the rationale to include the interaction (What assumption are you relaxing?)
> 2. Is the number of replicates good enough to include the interaction?
> 3. Is the interaction needed in the model?

**Solution**
```{r solutionChallenge2}
# Solution
design2 <- model.matrix(~ CellType * Status, data = sampleinfo)
fit2 <- glmFit(dgeObj, design2)

head(coef(fit2))

lrt2 <- glmLRT(fit2, coef=5)
topTags(lrt2)

lrt3 <- glmLRT(fit2, coef=6)
topTags(lrt3)
```
