Sorry this is a bit of silly question but its been bothering me a bit. So suppose I have a dataframe as such and want to compare gender or drug.
df = data.frame (
gender = c("m","m","f","m","m","f"),
drug = c("D1","D2","D1","D2","D1","D2")
)
gender = factor ( df$gender)
drug = factor ( df$drug)
When I create this model however for some reason the last factor always just converges into one column instead of two.
model.matrix(~0 + gender + drug )
> model.matrix(~0 + gender + drug )
genderf genderm drugD2
1 0 1 0
2 0 1 1
3 1 0 0
4 0 1 1
5 0 1 0
6 1 0 1
Why does it do this and how would my contrast look like if I wanted to compare drug D1 and D2 regardless of gender? for example for gender its straighforward and I can just do something like
contrast.matrix <- makeContrasts(
Group = genderf-genderm ,
levels=design
)
thanks!
thanks Gordon, out of curiosity do you know why the model.matrix would deliberatly combine the 3rd coef to one column?