[R] nested structure for Ancova

Richard M. Heiberger rmh at temple.edu
Sun Mar 12 19:31:20 CET 2017

```I think you need either

mod4 <- lm( y ~ -1 + area / (month*group), data=two)

mod5 <- lm( y ~ area / (month*group), data=two)

With either of those,  area:month and area:group and Residuals add up.

On Sun, Mar 12, 2017 at 10:39 li li <hannah.hlx at gmail.com> wrote:

> Hi All,
>   I have a dataset which contains 4 variables: area, group, time, y,
> Area is a factor that has two levels A and B, group is a factor that is
> nested within area. There are four groups within each area.
> y is the response variable, and time refers to different days.
>
>   Below is the how data looks like.
>
>   First, I fit separate ancova for each area (area A and B), For each area,
> I obtained different regression lines for each group within that area.
>
>   mod1 <- lm(y ~ month * group, data=two[two\$area=="A"]
>
>   mod2 <- lm(y ~ month * group, data=two[two\$area=="B"]
>
>  I want to fit the model at one time by using the nested structure
>
>  mod3 <-  lm(y ~ -1+ month * (area/group), data=two)
>
> I get different results using mod 3 from using mod1 and mod2.
>
>   Can someone give some suggestion on this.  How can I specify the model in
> R to simultaneously fit the model to get the same results as from mod1 and
> mod2.
>
> Thanks  very much!
>     Hanna
>
> > head(two[two\$area=="A",])   group time         y area
> 79     1    3 -1.394327    A
> 80     1    6 -1.435485    A
> 81     1    9 -1.406497    A
> 82     1   12 -1.265848    A
> 83     1    0 -1.316768    A
> 84     1    6 -1.431292    A> head(two[two\$area=="B",])  group time
>      y area
> 1     1    0 -2.145581    B
> 2     1    0 -1.910543    B
> 3     1    0 -2.128632    B
> 4     1    3 -2.079442    B
> 5     1    3 -2.273026    B
> 6     1    6 -2.312635    B
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help