If we run the three following codes:
n <- 250
df <- rbind(
data.frame(cat=1, x=rnorm(n, 0), y=rnorm(n, 1)),
data.frame(cat=2, x=rnorm(n, 0), y=rnorm(n, 0)),
data.frame(cat=3, x=rnorm(n, 0), y=rnorm(n, 0))
)
df$cat <- as.factor(df$cat)
df$cat <- relevel(df$cat, ref = "1")
summary(lm(y ~ cat, df))
It will say here that intercept, cat2 and cat3 are statistically significant in trying to predict y. But doesn't indicate that cat=2 and cat=3 are actually redundant.
n <- 250
df <- rbind(
data.frame(cat=1, x=rnorm(n, 0), y=rnorm(n, 1)),
data.frame(cat=2, x=rnorm(n, 0), y=rnorm(n, 0)),
data.frame(cat=3, x=rnorm(n, 0), y=rnorm(n, 0))
)
df$cat <- as.factor(df$cat)
df$cat <- relevel(df$cat, ref = "2")
summary(lm(y ~ cat, df))
Here only cat1 is significant.
n <- 250
df <- rbind(
data.frame(cat=1, x=rnorm(n, 0), y=rnorm(n, 1)),
data.frame(cat=2, x=rnorm(n, 0), y=rnorm(n, 0)),
data.frame(cat=3, x=rnorm(n, 0), y=rnorm(n, 0))
)
df$cat <- as.factor(df$cat)
df$cat <- relevel(df$cat, ref = "3")
summary(lm(y ~ cat, df))
Same here (which makes sense).
Do we have to run several times the linear model to see that cat2 and cat3 don't need to be both used to predict y? What if only the intercept is significant, what does that mean? I'm not able to reproduce a case where that happens and it happens in my dataset. Does that mean we don't need any of the 3 categorical variables to predict y? Why wouldn't be all p values not significant in that case?