[R] Fw: nested linear model; with common intercept

From: ken knoblauch <knoblauch_at_lyon.inserm.fr>
Date: Fri 13 Oct 2006 - 12:30:52 GMT


I f I understand you correctly, I don't think that your model is doing what you think it is.
Look at the model.matrix. Consider a toy example:

 > x <- 1:10
 > y <- factor(letters[1:2])
 > dd <- expand.grid(x, y)
 > dd$resp <- rnorm(20)

  model.matrix(~Var2/Var1+1, dd)
    (Intercept) Var2b Var2a:Var1 Var2b:Var1
1            1     0          1          0
2            1     0          2          0
3            1     0          3          0
4            1     0          4          0
5            1     0          5          0
6            1     0          6          0
7            1     0          7          0
8            1     0          8          0
9            1     0          9          0
10           1     0         10          0
11           1     1          0          1
12           1     1          0          2
13           1     1          0          3
14           1     1          0          4
15           1     1          0          5
16           1     1          0          6
17           1     1          0          7
18           1     1          0          8
19           1     1          0          9
20           1     1          0         10
attr(,"assign")
[1] 0 1 2 2
attr(,"contrasts")
attr(,"contrasts")$Var2
[1] "contr.treatment"

Do you want something more like the following?

model.matrix(~Var2:Var1, dd)

    (Intercept) Var2a:Var1 Var2b:Var1

1            1          1          0
2            1          2          0
3            1          3          0
4            1          4          0
5            1          5          0
6            1          6          0
7            1          7          0
8            1          8          0
9            1          9          0
10           1         10          0
11           1          0          1
12           1          0          2
13           1          0          3
14           1          0          4
15           1          0          5
16           1          0          6
17           1          0          7
18           1          0          8
19           1          0          9
20           1          0         10

attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$Var2
[1] "contr.treatment"

although, an expert will surely correct me, if I'm in error here....

> Q. Would it be "wrong" to specify a nested model and retain a common
> intercept, e.g.
>
> lm(NH4 ~ Site/TideCode + 1)
>
> I am aware (?) that my Site-coefficients are now calculated relative
> to my reference Site (treatment.contrasts), *but* that my TideCode
> levels now relate to their reference level within Site.
>
> Is that correct?
>
> Thank you in advance for help.
>
> Regards,
> Mark Difford.

-- 
Ken Knoblauch
Inserm U371
Institut Cellule Souche et Cerveau
Département Neurosciences Intégratives
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.lyon.inserm.fr/371/

	[[alternative text/enriched version deleted]]


______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Sat Oct 14 02:50:10 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 13 Oct 2006 - 17:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.