[Lme4-commits] r1780 - in pkg: lme4/R lme4/tests lme4.0/R lme4.0/tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jun 26 10:31:56 CEST 2012
Author: bbolker
Date: 2012-06-26 10:31:56 +0200 (Tue, 26 Jun 2012)
New Revision: 1780
Added:
pkg/lme4.0/tests/coefs.R
pkg/lme4/tests/coefs.R
Modified:
pkg/lme4.0/R/lmer.R
pkg/lme4/R/lmer.R
Log:
modify coef() to handle cases where the RE contains terms not included in the FE
Modified: pkg/lme4/R/lmer.R
===================================================================
--- pkg/lme4/R/lmer.R 2012-06-25 10:08:37 UTC (rev 1779)
+++ pkg/lme4/R/lmer.R 2012-06-26 08:31:56 UTC (rev 1780)
@@ -799,6 +799,13 @@
'" ignored')
fef <- data.frame(rbind(fixef(object)), check.names = FALSE)
ref <- ranef(object)
+ ## check for variables in RE but missing from FE, fill in zeros in FE accordingly
+ refnames <- unlist(lapply(ref,colnames))
+ nmiss <- length(missnames <- setdiff(refnames,names(fef)))
+ if (nmiss >0) {
+ fillvars <- setNames(data.frame(rbind(rep(0,nmiss))),missnames)
+ fef <- cbind(fillvars,fef)
+ }
val <- lapply(ref, function(x)
fef[rep.int(1L, nrow(x)),,drop = FALSE])
for (i in seq(a = val)) {
Added: pkg/lme4/tests/coefs.R
===================================================================
--- pkg/lme4/tests/coefs.R (rev 0)
+++ pkg/lme4/tests/coefs.R 2012-06-26 08:31:56 UTC (rev 1780)
@@ -0,0 +1,10 @@
+## test coefficient extraction in the case where RE contain
+## terms that are missing from the FE ...
+set.seed(101)
+d <- data.frame(resp=runif(100),
+ var1=factor(sample(1:5,size=100,replace=TRUE)),
+ var2=runif(100),
+ var3=factor(sample(1:5,size=100,replace=TRUE)))
+library(lme4)
+mix1 <- lmer(resp ~ 0 + var1 + var1:var2 + (1|var3), data=d)
+coef(mix1)
Modified: pkg/lme4.0/R/lmer.R
===================================================================
--- pkg/lme4.0/R/lmer.R 2012-06-25 10:08:37 UTC (rev 1779)
+++ pkg/lme4.0/R/lmer.R 2012-06-26 08:31:56 UTC (rev 1780)
@@ -873,6 +873,13 @@
'" ignored', sep = ''))
fef <- data.frame(rbind(fixef(object)), check.names = FALSE)
ref <- ranef(object)
+ ## check for variables in RE but missing from FE, fill in zeros in FE accordingly
+ refnames <- unlist(lapply(ref,colnames))
+ nmiss <- length(missnames <- setdiff(refnames,names(fef)))
+ if (nmiss >0) {
+ fillvars <- setNames(data.frame(rbind(rep(0,nmiss))),missnames)
+ fef <- cbind(fillvars,fef)
+ }
val <- lapply(ref, function(x) fef[rep(1, nrow(x)),,drop = FALSE])
for (i in seq(a = val)) {
refi <- ref[[i]]
Added: pkg/lme4.0/tests/coefs.R
===================================================================
--- pkg/lme4.0/tests/coefs.R (rev 0)
+++ pkg/lme4.0/tests/coefs.R 2012-06-26 08:31:56 UTC (rev 1780)
@@ -0,0 +1,11 @@
+## test coefficient extraction in the case where RE contain
+## terms that are missing from the FE ...
+set.seed(101)
+d <- data.frame(resp=runif(100),
+ var1=factor(sample(1:5,size=100,replace=TRUE)),
+ var2=runif(100),
+ var3=factor(sample(1:5,size=100,replace=TRUE)))
+library(lme4.0)
+mix1 <- lmer(resp ~ 0 + var1 + var1:var2 + (1|var3), data=d)
+coef(mix1)
+
More information about the Lme4-commits
mailing list