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

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Mar 14 20:40:57 CET 2008



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



More information about the R-help mailing list