glm
How to succinctly write a formula with many variables from a data frame?
There is a special identifier that one can use in a formula to mean all the variables, it is the . identifier. y <- c(1,4,6) d <- data.frame(y = y, x1 = c(4,-1,3), x2 = c(3,9,8), x3 = c(4,-4,-2)) mod <- lm(y ~ ., data = d) You can also do things like this, to … Read more
How to debug “contrasts can be applied only to factors with 2 or more levels” error?
Introduction What a “contrasts error” is has been well explained: you have a factor that only has one level (or less). But in reality this simple fact can be easily obscured because the data that are actually used for model fitting can be very different from what you’ve passed in. This happens when you have … Read more