My data is currently in a data frame with 3 columns (y, x, season) where season is a factor ("SPRING","SUMMER","FALL","WINTER")
I fit a linear model
yi = b0 + b.xi + ei ~ N(0,sig^2)
lm(y ~ x)
i want to test this against an extended model of the form
yij = b0 + bj.xij + eij
where j (= 1:4) is the SEASON of the year
Usually i would just create the design matrix, X and then b = inv(X'X).(X'Y)
However i'd like to do this in R using lm()
How can i use lm()
to fit this extended model with the data in its current format? Do i HAVE to transform my data to wide format with 5 columns (y, x1, x2, x3, x4 ) where xj represents the measurements for season j?