lme() does not work with all fixed effects [🇷 for BE/BA]
Dear Helmut,
glm() works in R.
lme() does not work without random effect. Am I doing anything wrong?
If I compared lme(), lm(), and glm(), I got
Summary of mod.lme
Summary of mod.lm
Summary of glm
❝ ... 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.2:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan https://www.pkpd168.com/bear
Download link (updated) -> here
All the best,
-- Yung-jin Lee
bear v2.9.2:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan https://www.pkpd168.com/bear
Download link (updated) -> here
Complete thread:
- Bear vs. Phoenix & SAS Helmut 2015-04-20 17:34 [🇷 for BE/BA]
- R vs. Phoenix & SAS? yjlee168 2015-04-20 19:36
- R vs. Phoenix & SAS? Helmut 2015-04-21 01:02
- lme() does not work with all fixed effectsyjlee168 2015-04-21 23:41
- lme() does not work with all fixed effects Astea 2016-11-04 00:13
- lmer: Method B (PE catched for imbalanced dataset!!!) and Method C mittyri 2016-11-05 17:38
- lmer: Method B (PE catched for imbalanced dataset!!!) and Method C Astea 2016-11-05 19:27
- lmer: Method B is ready for scaling mittyri 2016-11-05 20:01
- lmer: Method B is ready for scaling Astea 2016-11-06 11:50
- lmer: Method B is ready for scaling mittyri 2016-11-07 06:07
- lmer: Method B is ready for scaling Astea 2016-11-06 11:50
- lmer: Method B is ready for scaling mittyri 2016-11-05 20:01
- lmer: Method B (PE catched for imbalanced dataset!!!) and Method C Astea 2016-11-05 19:27
- lmer: Method B (PE catched for imbalanced dataset!!!) and Method C mittyri 2016-11-05 17:38
- lme() does not work with all fixed effects Astea 2016-11-04 00:13
- lme() does not work with all fixed effectsyjlee168 2015-04-21 23:41
- R vs. Phoenix & SAS? Helmut 2015-04-21 01:02
- info for lsmeans yjlee168 2015-04-20 21:34
- info for lsmeans Helmut 2015-04-21 01:15
- once more about R and replicate designes Astea 2016-11-02 23:43
- once more about R and replicate designes VStus 2016-11-06 11:34
- Getting variance components from the lmer output StatR 2017-02-03 13:53
- Getting variance components from the lmer output VStus 2017-02-03 15:47
- Getting variance components from the lmer output StatR 2017-02-03 17:12
- Getting variance components d_labes 2017-02-07 11:16
- Getting variance components StatR 2017-02-07 11:36
- Getting variance components StatR 2017-02-08 08:41
- Getting variance components d_labes 2017-02-08 10:13
- Getting variance components StatR 2017-02-08 10:19
- Data structure Helmut 2017-02-08 10:33
- Data structure StatR 2017-02-08 10:49
- Getting variance components d_labes 2017-02-08 10:13
- Getting variance components d_labes 2017-02-07 11:16
- Getting variance components from the lmer output StatR 2017-02-03 17:12
- Getting variance components from the lmer output VStus 2017-02-03 15:47
- Getting variance components from the lmer output StatR 2017-02-03 13:53
- once more about R and replicate designes VStus 2016-11-06 11:34
- once more about R and replicate designes Astea 2016-11-02 23:43
- info for lsmeans Helmut 2015-04-21 01:15
- R vs. Phoenix & SAS? yjlee168 2015-04-20 19:36