Next, we'll load the data. For this example, we'll use the built-in mtcars dataset:
data(mtcars)
Now, let's preprocess the data. We'll first convert the data to a limma-compatible format, which involves creating a design matrix with the samples (cars) as rows and the features (e.g. cylinders, displacement) as columns:
Here, Species is the response variable (i.e. the variable we want to predict), and ~ . means that we want to include all the other variables as predictors.
Next, we'll preprocess the data by normalizing the values to have zero mean and unit variance. This is important because Limma models are sensitive to the scale of the data:
# normalize data
design <- normalize(design)
Finally, we're ready to train the Limma model:
# train Limma model
model <- limma(design, data = mtcars)
The limma() function takes two arguments: the design matrix (design), and the data frame containing the data (data).
Now, let's take a look at the results:
# print results
print(model)
This will print the summary of the model, including the coefficients, standard errors, and p-values.
Here's the complete code:
# load packages
library(limma)
library(ggplot2)
# load data
data(mtcars)
# create design matrix
design <- model.matrix(Species ~ ., data = mtcars)
# normalize data
design <- normalize(design)
# train Limma model
model <- limma(design, data = mtcars)
# print results
print(model)