### Eclipse Workspace Patch 1.0 #P pedigreemm Index: R/AllClass.R =================================================================== --- R/AllClass.R (revision 127) +++ R/AllClass.R (working copy) @@ -23,5 +23,4 @@ TRUE }) -setClass("pedigreemm", representation = list(relfac = "list"), - contains = "mer") +setClass("pedigreemm", representation = list(relfac = "list", ans = "merMod", call = "call")) Index: R/pedigree.R =================================================================== --- R/pedigree.R (revision 127) +++ R/pedigree.R (working copy) @@ -163,7 +163,8 @@ { mc <- match.call() lmerc <- mc # create a call to lmer - lmerc[[1]] <- as.name("lmer") + l... = list(...) + if (!is.null(l...$family)) lmerc[[1]] <- as.name("glmer") else lmerc[[1]] <- as.name("lmer") lmerc$pedigree <- NULL if (!length(pedigree)) # call lmer instead @@ -172,25 +173,35 @@ stopifnot(is.list(pedigree), # check the pedigree argument length(names(pedigree)) == length(pedigree), all(sapply(pedigree, is, class2 = "pedigree"))) - + lmerc$doFit <- FALSE # call lmer without pedigree and with doFit = FALSE - lmf <- eval(lmerc, parent.frame()) + lmf <- eval(lmerc, parent.frame()) - relfac <- pedigree # copy the pedigree list for relfactor pnms <- names(pedigree) - stopifnot(all(pnms %in% names(lmf$FL$fl))) - asgn <- attr(lmf$FL$fl, "assign") + stopifnot(all(pnms %in% names(lmf$reTrms$flist))) + asgn <- attr(lmf$reTrms$flist, "assign") + bigZt <- lmf$rho$pp$Zt for (i in seq_along(pedigree)) { - tn <- which(match(pnms[i], names(lmf$FL$fl)) == asgn) + tn <- which(match(pnms[i], names(lmf$reTrms$flist)) == asgn) if (length(tn) > 1) stop("a pedigree factor must be associated with only one r.e. term") - Zt <- lmf$FL$trms[[tn]]$Zt - relfac[[i]] <- relfactor(pedigree[[i]], rownames(Zt)) - lmf$FL$trms[[tn]]$Zt <- lmf$FL$trms[[tn]]$A <- relfac[[i]] %*% Zt + assg = (lmf$reTrms$Gp[tn] + 1):lmf$reTrms$Gp[tn+1] + Zt <- bigZt[assg, ] + relfac[[i]] <- relfactor(pedigree[[i]], rownames(Zt)) + #lmf$FL$trms[[tn]]$Zt <- lmf$FL$trms[[tn]]$A <- relfac[[i]] %*% Zt + bigZt[assg, ] <- relfac[[i]] %*% Zt } - ans <- do.call(if (!is.null(lmf$glmFit)) lme4:::glmer_finalize else lme4:::lmer_finalize, lmf) - ans <- new("pedigreemm", relfac = relfac, ans) + lmf$reTrms$Zt <- bigZt + lmf$rho$pp <- do.call(merPredD$new, c(lmf$reTrms[c("Zt","theta","Lambdat","Lind")], n=nrow(lmf$rho$pp$X), list(X=lmf$rho$pp$X))) + if (is(lmf$rho$resp, "lmerResp")) + { + ans <- lme4:::lmer_finalize(lmf$rho, lmf$optimizer, lmf$devfun, lmf$reTrms, lmf$control, lmf$fr, lmf$mc, lmf$verbose) + } else { + ans <- lme4:::glmer_finalize(lmf$rho, lmf$optimizer, lmf$devfun, lmf$reTrms, lmf$control, lmf$fr, lmf$mc, lmf$nAGQ, lmf$verbose) + } + #ans <- do.call(if (is(lmf$rho$resp, "lmerResp")) lme4:::lmer_finalize else lme4:::glmer_finalize, lmf) + ans <- new("pedigreemm", relfac = relfac, ans = ans) ans@call <- match.call() ans } @@ -203,7 +214,8 @@ { mc <- match.call() lmerc <- mc # create a call to lmer - lmerc[[1]] <- as.name("lmer") + l... = list(...) + if (!is.null(l...$family)) lmerc[[1]] <- as.name("glmer") else lmerc[[1]] <- as.name("lmer") lmerc$pre <- NULL if (!length(pre)) # call lmer instead @@ -212,22 +224,39 @@ stopifnot(is.list(pre), # check the pre argument length(names(pre)) == length(pre), all(sapply(pre, is, class2 = "Matrix"))) - - lmerc$doFit <- FALSE # call lmer without pre and with doFit = FALSE - lmf <- eval(lmerc, parent.frame()) - + lmerc$doFit <- FALSE # call lmer without pedigree and with doFit = FALSE + lmf <- eval(lmerc, parent.frame()) + pnms <- names(pre) - stopifnot(all(pnms %in% names(lmf$FL$fl))) - asgn <- attr(lmf$FL$fl, "assign") + stopifnot(all(pnms %in% names(lmf$reTrms$flist))) + asgn <- attr(lmf$reTrms$flist, "assign") + bigZt <- lmf$rho$pp$Zt for (i in seq_along(pre)) { - tn <- which(match(pnms[i], names(lmf$FL$fl)) == asgn) + tn <- which(match(pnms[i], names(lmf$reTrms$flist)) == asgn) if (length(tn) > 1) stop("a pre factor must be associated with only one r.e. term") - Zt <- lmf$FL$trms[[tn]]$Zt - lmf$FL$trms[[tn]]$Zt <- lmf$FL$trms[[tn]]$A <- pre[[i]] %*% Zt - } - do.call(if (!is.null(lmf$glmFit)) lme4:::glmer_finalize else lme4:::lmer_finalize, lmf) + assg = rownames(bigZt) %in% levels(lmf$reTrms$flist[[tn]]) + Zt <- bigZt[assg, ] + relfac[[i]] <- relfactor(pedigree[[i]], rownames(Zt)) + #lmf$FL$trms[[tn]]$Zt <- lmf$FL$trms[[tn]]$A <- pre[[i]] %*% Zt + bigZt[assg, ] <- pre[[i]] %*% Zt + } + lmf$reTrms$Zt <- bigZt + lmf$rho$pp <- do.call(merPredD$new, c(lmf$reTrms[c("Zt","theta","Lambdat","Lind")], n=nrow(lmf$rho$pp$X), list(X=lmf$rho$pp$X))) + #do.call(if (is(lmf$rho$resp, "lmerResp")) lme4:::lmer_finalize else lme4:::glmer_finalize, lmf) + if (is(lmf$rho$resp, "lmerResp")) + { + ans <- lme4:::lmer_finalize(lmf$rho, lmf$optimizer, lmf$devfun, lmf$reTrms, lmf$control, lmf$fr, lmf$mc, lmf$verbose) + } else { + ans <- lme4:::glmer_finalize(lmf$rho, lmf$optimizer, lmf$devfun, lmf$reTrms, lmf$control, lmf$fr, lmf$mc, lmf$nAGQ, lmf$verbose) + } + return(ans) +} + +summary.pedigreemm <- function(object, ...) +{ + return(summary(object@ans)) } setMethod("ranef", signature(object = "pedigreemm"),