Model matrix for linear model with multiple contrasts I don't fully understand the concept of a model.matrix. Assume I have the following experimental design:
   Outcome
s1      t1
s2      t1
s3      nc
s4      nc
s5      t2
s6      t2
s7      ex
s8      ex

Each row corresponds to a sample and the outcome is either normal control (nc), treatment 1 (t1), treatment 2 (t1), or the sample should be excluded from the analysis (ex). I would like to compare nc vs t1 and nc vs t2.
What is the correct model.matrix for this data and how can I generate it using R?
The experimental design can be created using data.frame(Outcome = c("t1","t1","nc","nc","t2","t2","ex","ex"), row.names = paste0("s",1:8))
 A: I think you are asking what does model.matrix do to allow us to compare different groups. 
In most (all?) linear models, the way we compare categorical variables is to add dummy variables (i.e. values that are just 0 or 1) that represent whether that subject belongs to that given group. Then, if we want to know the difference between subjects of group X and the baseline group, the covariate associated with group X will represent this difference. 
You can see the creation of these dummy variables very easily from the code you've written: 
myData <- data.frame(Outcome = c("t1","t1","nc","nc","t2","t2","ex","ex"), 
row.names = paste0("s",1:8))
model.matrix(~Outcome, data = myData)
Note that model.matrix automatically makes our dummy variables for us, so the output is immediately ready to be plugged into some sort of algorithm that accepts only numeric values. 
A: As Cliff mentions in their answer, the model matrix allows a comparison between different groups. Given my initial question, the model matrix for this experiment is:
myData <- data.frame(Outcome = c("t1","t1","nc","nc","t2","t2","ex","ex"), 
row.names = paste0("s",1:8))
mm <- model.matrix(~0 + Outcome, myData)

mm
   Outcomeex Outcomenc Outcomet1 Outcomet2
s1         0         0         1         0
s2         0         0         1         0
s3         0         1         0         0
s4         0         1         0         0
s5         0         0         0         1
s6         0         0         0         1
s7         1         0         0         0
s8         1         0         0         0

Unlike Cliff's answer, this will produce a model.matrix without an intercept. The contrast matrix associated with this experiment should be:
           Contrasts
Levels      Outcomet1 - Outcomenc Outcomet2 - Outcomenc
  Outcomeex                     0                     0
  Outcomenc                    -1                    -1
  Outcomet1                     1                     0
  Outcomet2                     0                     1

