Next, let's load the data. For this example, we'll use the breast cancer dataset from the limma package, which contains gene expression data for 20 breast cancer samples:
data(breast_cancer)
Now, let's preprocess the data. We'll remove genes that are present in less than 5 samples, as these genes may not be reliable. We'll also transform the data using the variance stabilizing transformation (VST) to stabilize the variance of the data:
# Preprocess the data
break_down <- breast_cancer[which(breast_cancer$n_samples > 5), ]
break_down_vst <- vst(break_down[, -1], col = "VST")
Now, let's train the Limma model. We'll fit a linear model to the data, with the response variable being the expression of the gene of interest, and the predictor variables being the clinical variables (age, tumor size, etc.). We'll also include batch effects to account for differences in sample processing:
# Fit the Limma model
model <- limma::Limma(
expression = break_down_vst[, "expression"],
response = "expression",
predictor = c("age", "tumor_size", "tumor_grade"),
batch = c("batch"),
method = "MM"
)
# Fit the model using the limma function
results <- limma::fit(model)
Now, let's plot the results to see if the gene of interest is differentially expressed between the different groups. We'll use the volcanoPlot() function from the limma package to plot the results:
# Plot the results
volcanoPlot(results$coef, results$p.value, col = c("red", "blue"))
This will create a volcano plot showing the fold change vs. the log10 of the p-value for each gene. Gen