StatQuest: GLMs Pt.3 – Design Matrix Examples in R

## In this example, we show how to do a t-test and regression at the same 
## time...
Type <- factor(c(
  rep("Control", times=4),
  rep("Mutant", times=4)))
Weight <- c(2.4, 3.5, 4.4, 4.9, 1.7, 2.8, 3.2, 3.9)
Size <- c(1.9, 3, 2.9, 3.7, 2.8, 3.3, 3.9, 4.8)
model.matrix(~Type+Weight)

model <- lm(Size~Type + Weight)
summary(model)

## In this example we show that the p-value in the bottom
## right hand corner (the overall p-value) isn't the one we
## want.
Lab <- factor(c(
  rep("A", times=6),
  rep("B", times=6)))
Type <- factor(c(
  rep("Control", times=3),
  rep("Mutant", times=3),
  rep("Control", times=3),
  rep("Mutant", times=3)))
Expression <-c(
  1.7, 2, 2.2,
  3.1, 3.6, 3.9,
  0.9, 1.2, 1.9,
  1.8, 2.2, 2.9)
model.matrix(~Lab+Type)

batch.lm <- lm(Expression ~ Lab + Type)
summary(batch.lm)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s