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....@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@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.