[R] nested structure for Ancova

Michael Dewey lists at dewey.myzen.co.uk
Sun Mar 12 18:27:46 CET 2017


Dear Hannah

You say they are different (mod3 from mod1 and mod2) but in what way are 
the results different?

On 12/03/2017 15:38, li li 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
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list