Mutiple linear regression
Résumé de section
-
-
In R, contrasts are used to handle categorical variables (factors) in models like linear regression. Categorical variables need to be encoded numerically so they can be included in models, and contrasts define how the levels of a factor are represented as numeric values.
When you fit a model in R with a categorical predictor (factor), R automatically creates dummy variables to represent the different levels of the factor. The type of contrast determines how these dummy variables are encoded and how comparisons between factor levels are made in the model.This R script demonstrates various ways of encoding categorical variables and fitting linear models using the
lm()function. It also shows how to manipulate factor levels and contrasts when building regression models.