[R] Factors attribute format
rkevinburton at charter.net
rkevinburton at charter.net
Mon Mar 22 20:00:03 CET 2010
Thanks to Marc Schultz I found the documentation on the "factors" attribute under ?term.object. It stats:
factors: A matrix of variables by terms showing which variables appear
in which terms. The entries are 0 if the variable does not
occur in the term, 1 if it does occur and should be coded by
contrasts, and 2 if it occurs and should be coded via dummy
variables for all levels (as when an intercept or lower-order
term is missing). If there are no terms other than an
intercept and offsets, this is ‘numeric(0)’.
So now this brings up another question. It seems that the attriute is a two dimentional array. When I print it out in 'R'
Fitting the formula prestige ~ income + education I get:
income education
prestige 0 0
income 1 0
education 0 1
This matrix says to me that 'income' occurs in the term 'income' etc. So it seems that this matrix will always be a diagonal matrix with an added row of zeros containing the response term. If the formula is such that the response is a function of one or more of the dependent variables then of course it will be something other that a row of zeros. So far OK?
My problem in understanding comes with using a formula that contains R factors. I am using the following (from the TSA package) for an example:
l <- lm(tempdub ~ season(tempdub))
attr(l$terms, "factors")
season(tempdub)
tempdub 0
season(tempdub) 1
The function 'season' produces a factor (in this case with 12 levels, one for each month). But the factor attribute still has a '1' and not a '2' indicating that the variable should be coded as a dummy variable (factor).
Please help my misunderstanding.
Thank you.
Kevin Burton
More information about the R-help
mailing list