Skip to content
Prev 247082 / 398503 Next

A question on dummy variable

On Tue, Jan 11, 2011 at 3:18 PM, Christofer Bogaso
<bogaso.christofer at gmail.com> wrote:
The contrasts of your dummy1 matrix are contr.SAS contrasts in R.
(The default contrasts in R are contr.treatment which are the same as
contr.SAS except contr.SAS uses the last level as the base whereas
treatment contrasts use the first level as the base.)

   options(contrasts = c("contr.SAS", "contr.poly"))
   f <- gl(4, 1, 16)
   M <- model.matrix( ~ f )
   all( M[, -1] == dummy1) # TRUE

Centered contrasts are ones which have been centered -- i.e. the mean
of each column has been subtracted from that column.  This is
equivalent to saying that the column sums are zero.

The means of the three columns of dummy1 are c(1/4, 1/4, 1/4) so if we
subtract 1/4 from dummy1 we get a centered contrasts matrix. That is
precisely what you did to get dummy3.  We can check that dummy3 is
centered:

   colSums(dummy3) # 0 0 0

dummy2 is just a scaled version of dummy3.  In fact dummy2 equals
dummy3 / .75 so its not fundamentally different.  Its columns still
sum to zero so its still centered.

   all( dummy2 == dummy3 / .75) # TRUE
   colSums(dummy2) # 0 0 0 except for floating point error