[R] two cols in a data frame are the same factor

Michael Dewey info at aghmed.fsnet.co.uk
Wed Mar 19 18:57:58 CET 2008


At 09:11 18/03/2008, Andres Legarra wrote:
>Dear all,
>I have a data set (QTL detection) where I have two cols of factors in
>the data frame that correspond logically (in my model) to the same
>factor. In fact these are haplotype classes.
>Another real-life example would be family gas consumption as a
>function of car company (e.g. Ford, GM, and Honda) (assuming 2 cars by
>family).

Unless I completely misunderstand this it looks like you have the 
dataset in wide format when you really wanted it in long format (to 
use the terminology of ?reshape). Then you would fit a model allowing 
for the clustering by family.


>An artificial example follows:
>set.seed(1234)
>L3 <- LETTERS[1:3]
>(d <- data.frame( y=rnorm(10), fac=sample(L3, 10,
>repl=TRUE),fac1=sample(L3,10,repl=T)))
>
>  lm(y ~ fac+fac1,data=d)
>
>and I get:
>
>Coefficients:
>(Intercept)         facB         facC        fac1B        fac1C
>      0.3612      -0.9359      -0.2004      -2.1376      -0.5438
>
>However, to respect my model, I need to constrain effects in fac and
>fac1 to be the same, i.e. facB=fac1B and facC=fac1C. There are
>logically just 4 unknowns (average,A,B,C).
>With continuous covariates one might do y ~ I(cov1+cov2), but this is
>not the case.
>
>Is there any trick to do that?
>Thanks,
>
>Andres Legarra
>INRA-SAGA
>Toulouse, France

Michael Dewey
http://www.aghmed.fsnet.co.uk



More information about the R-help mailing list