Hello:
My question is whether it’s possible to compute lsmeans defined in this SAS algorithm if the design matrix is not in GLM form. In particular, in R, if one feeds that design to model.matrix(), then Reference coding is used, so A will occupy 2 columns, B will occupy 1 column, A*B will occupy 2 columns, and C will take 1 column.
The meaning of columns in GLM and Ref coding is quite different. For instance, if we have just one factor with two levels, A1 and A2, then in GLM format the intercept corresponds to the response averaged over A1 and A2, but in Ref the intercept corresponds to response at A1.
Apparently, the column space of GLM and Ref is the same, so I wonder if there is a way to represent each GLM column as a linear combination of Ref columns. In that case, one could take the LSM vector defined in GLM terms and apply it to a model fitted in Ref coding. Likewise, a contrast vector can be set as a difference of two LSM vectors and then estimated in Ref coding.
I know there are some R packages, like "contrast" that can take a fitted model in Ref coding and a contrast or lsmeans specification in string format, like "LSM(A1, B1)" or "A1 vs A2". However, here I am interested in a more specific solution that assumes we have already implemented the SAS algorithm for LSM vector. I am looking for a GLM->Ref "adapter" of sorts.
Thanks,
James
... View more