Re: [R] Lme does not work without a random effect (UNCLASSIFIED)

From: Simon Blomberg <s.blomberg1_at_uq.edu.au>
Date: Sat, 15 Mar 2008 17:31:45 +1000

There's a trick with this: you need to make sure you are using anova.lme rather than anova.lm. So if in this example you do

anova(fit0, fit)

you will get an error.

Simon.

Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician
Faculty of Biological and Chemical Sciences The University of Queensland
St. Lucia Queensland 4072
Australia
T: +61 7 3365 2506
email: S.Blomberg1_at_uq.edu.au

Policies:
1. I will NOT analyse your data for you. 2. Your deadline is your problem.

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.

-----Original Message-----
From: r-help-bounces_at_r-project.org on behalf of Sundar Dorai-Raj Sent: Sat 15/03/2008 5:40 AM
To: Park, Kyong H Mr ECBC
Cc: 'r-help_at_r-project.org'
Subject: Re: [R] Lme does not work without a random effect (UNCLASSIFIED)  

Park, Kyong H Mr ECBC said the following on 3/14/2008 12:25 PM:
> Classification: UNCLASSIFIED
> Caveats: NONE
>
> Dear R users,
>
> I'm interested in finding a random effect of the Block in the data shown
> below, but 'lme' does not work without the random effect. I'm not sure how
> to group the data without continuous value which is shown in the error
> message at the bottom line. If I use 'aov' with Error(Block), is there a
> test method comparing between with and without the Block random effect. I'm
> using R 2.4.1.
>
> Appreciate your help.
>
> Kyong
>
> LCU ST1 SURF Block
> 1 6.71 A N 1
> 2 6.97 A Y 1
> 3 6.77 B N 1
> 4 6.90 B Y 1
> 5 6.63 C N 1
> 6 6.94 C Y 1
> 7 6.79 D N 1
> 8 6.93 D Y 1
> 9 6.23 A N 2
> 10 6.83 A Y 2
> 11 6.61 B N 2
> 12 6.86 B Y 2
> 13 6.51 C N 2
> 14 6.90 C Y 2
> 15 5.90 D N 2
> 16 6.97 D Y 2
>
> A result with the random effect:
>
> Anal1<-lme(LCU~ST1*SURF,random=~1|Block,data=data1)

>> summary(Anal1)

> Linear mixed-effects model fit by REML
> Data: data1
> AIC BIC logLik
> 25.38958 26.18399 -2.694789
>
> Random effects:
> Formula: ~1 | Block
> (Intercept) Residual
> StdDev: 0.1421141 0.218483
>
> Fixed effects: LCU ~ ST1 * SURF
> Value Std.Error DF t-value p-value
> (Intercept) 6.470 0.1842977 7 35.10625 0.0000
> ST1B 0.220 0.2184830 7 1.00694 0.3475
> ST1C 0.100 0.2184830 7 0.45770 0.6610
> ST1D -0.125 0.2184830 7 -0.57213 0.5851
> SURFY 0.430 0.2184830 7 1.96812 0.0897
> ST1B:SURFY -0.240 0.3089816 7 -0.77675 0.4627
> ST1C:SURFY -0.080 0.3089816 7 -0.25892 0.8031
> ST1D:SURFY 0.175 0.3089816 7 0.56638 0.5888
>
> Without the random effect:
>
> Anal2<-lme(LCU~ST1*SURF,data=data1)
> Error in getGroups.data.frame(dataMix, groups) :
> Invalid formula for groups
> Classification: UNCLASSIFIED
> Caveats: NONE
>
>

Use "lm" to fit the model without random effect and use anova to compare:

z <- read.table(con <- textConnection("     LCU ST1 SURF Block
1  6.71   A    N     1
2  6.97   A    Y     1
3  6.77   B    N     1
4  6.90   B    Y     1
5  6.63   C    N     1
6  6.94   C    Y     1
7  6.79   D    N     1
8  6.93   D    Y     1
9  6.23   A    N     2
10 6.83   A    Y     2
11 6.61   B    N     2
12 6.86   B    Y     2
13 6.51   C    N     2
14 6.90   C    Y     2
15 5.90   D    N     2
16 6.97   D    Y     2"), header = TRUE)
close(con)

library(nlme)
fit <- lme(LCU~ST1*SURF,random=~1|Block,data=z) fit0 <- lm(LCU~ST1*SURF,data=z)
anova(fit, fit0)

HTH, --sundar



R-help_at_r-project.org 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.

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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 15 Mar 2008 - 07:38:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 15 Mar 2008 - 10:30:22 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.

list of date sections of archive