lme() does not work with all fixed effects [🇷 for BE/BA]

posted by yjlee168 Homepage – Kaohsiung, Taiwan, 2015-04-22 01:41 (3264 d 05:40 ago) – Posting: # 14730
Views: 23,441

Dear Helmut,

❝ ... The Q&A specifically mentions SAS’ Proc GLM, not Proc Mixed.


glm() works in R.

❝ In lme() it should be possible to specify all effects fixed. Actually the random effect(s) are optional. If is doesn’t work, lm() should do.


lme() does not work without random effect. Am I doing anything wrong?

> require(nlme)
Loading required package: nlme
> cnames<-c("subj","drug","seq", "prd","Cmax", "AUC0t", "AUC0INF","lnCmax","lnAUC0t","lnAUC0INF")
> TotalData<-read.csv(file="SingleRep_stat_demo.csv",header=TRUE,row.names=NULL,col.names=cnames, sep=",",dec=".")
> mod.lme<-lme(log(Cmax) ~ subj + seq +  prd + drug, data=TotalData, method="REML")

Error in getGroups.data.frame(dataMix, groups) :
  invalid formula for groups


If I compared lme(), lm(), and glm(), I got
> mod.lme<-lme(log(Cmax) ~ seq +  prd + drug, random=~drug -1|subj, data=TotalData, method="REML")  ###lme in bear
> mod.lm<-lm(log(Cmax) ~ subj + seq +  prd + drug, data=TotalData)    ## lm()
> mod.glm<-glm(log(Cmax) ~ subj + seq +  prd + drug, data=TotalData)  ## glm()
> AIC(mod.lme, mod.lm)

        df       AIC
mod.lme  6 -49.88309
mod.lm   6 -70.88094
Warning message:
In AIC.default(mod.lme, mod.lm) :
  models are not all fitted to the same number of observations

> AIC(mod.lme, mod.glm)
        df       AIC
mod.lme  6 -49.88309
mod.lm   6 -70.88094
Warning message:
In AIC.default(mod.lme, mod.lm) :
  models are not all fitted to the same number of observations


Summary of mod.lme
Linear mixed-effects model fit by REML
 Data: TotalData
        AIC       BIC   logLik
  -49.88309 -38.17563 30.94155

Random effects:
 Formula: ~drug - 1 | subj
              drug  Residual
StdDev: 0.04344759 0.1041244

Fixed effects: log(Cmax) ~ seq + prd + drug
                Value  Std.Error DF  t-value p-value
(Intercept)  7.314670 0.08349877 40 87.60213  0.0000
seq         -0.025701 0.04252039 12 -0.60445  0.5568
prd          0.016233 0.01244525 40  1.30438  0.1996
drug         0.046554 0.03015388 40  1.54387  0.1305
 Correlation:
     (Intr) seq    prd   
seq  -0.764             
prd  -0.373  0.000       
drug -0.461  0.000  0.000

Standardized Within-Group Residuals:
       Min         Q1        Med         Q3        Max
-2.8081617 -0.6114645  0.1380420  0.5476292  1.8620918

Number of Observations: 56
Number of Groups: 14

Summary of mod.lm
Call:
lm(formula = log(Cmax) ~ subj + seq + prd + drug, data = TotalData)

Residuals:
     Min       1Q   Median       3Q      Max
-0.29483 -0.07058  0.01211  0.07004  0.23080

Coefficients:
             Estimate Std. Error t value Pr(>|t|)   
(Intercept)  7.353905   0.087149  84.383   <2e-16 ***
subj        -0.007061   0.004041  -1.747   0.0866 . 
seq         -0.016555   0.032583  -0.508   0.6136   
prd          0.016233   0.014459   1.123   0.2668   
drug         0.046554   0.032332   1.440   0.1560   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.121 on 51 degrees of freedom
Multiple R-squared:  0.1126,    Adjusted R-squared:  0.04302
F-statistic: 1.618 on 4 and 51 DF,  p-value: 0.184

Summary of glm
Call:
glm(formula = log(Cmax) ~ subj + seq + prd + drug, data = TotalData)

Deviance Residuals:
     Min        1Q    Median        3Q       Max 
-0.29483  -0.07058   0.01211   0.07004   0.23080 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)   
(Intercept)  7.353905   0.087149  84.383   <2e-16 ***
subj        -0.007061   0.004041  -1.747   0.0866 . 
seq         -0.016555   0.032583  -0.508   0.6136   
prd          0.016233   0.014459   1.123   0.2668   
drug         0.046554   0.032332   1.440   0.1560   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 0.01463458)

    Null deviance: 0.84108  on 55  degrees of freedom
Residual deviance: 0.74636  on 51  degrees of freedom
AIC: -70.881

Number of Fisher Scoring iterations: 2

> AIC(mod.lm, mod.glm)
        df       AIC
mod.lm   6 -70.88094
mod.glm  6 -70.88094

All the best,
-- Yung-jin Lee
bear v2.9.1:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan https://www.pkpd168.com/bear
Download link (updated) -> here

Complete thread:

UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,636 registered users;
90 visitors (0 registered, 90 guests [including 5 identified bots]).
Forum time: 06:21 CET (Europe/Vienna)

With four parameters I can fit an elephant,
and with five I can make him wiggle his trunk.    John von Neumann

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5