Skip to content

Commit

Permalink
deviance actually returns deviance;
Browse files Browse the repository at this point in the history
update NEWS; adjust hatvalues for S3 compatibility
  • Loading branch information
bbolker committed Jul 21, 2014
1 parent 9e1b3ef commit 5ac6f57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 6 additions & 3 deletions R/lmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ coef.merMod <- coefMer
##' @importFrom stats deviance
##' @S3method deviance merMod
deviance.merMod <- function(object, REML = NULL, ...) {
if (isGLMM(object)) {
return(sum(residuals(object,type="deviance")^2))
}
if (isREML(object) && is.null(REML)) {
warning("deviance() is deprecated for REML fits; use REMLcrit for the REML criterion or deviance(.,REML=FALSE) for deviance calculated at the REML fit")
return(devCritFun(object, REML=TRUE))
Expand Down Expand Up @@ -1338,10 +1341,10 @@ residuals.glmResp <- function(object, type = c("deviance", "pearson",
}

## influence values (new feature); not yet exported
hatvalues.merMod <- function(object, ...) {
hatvalues.merMod <- function(model, ...) {
## prior weights, W ^ {1/2} :
sqrtW <- Diagonal(x = sqrt(weights(object, type = "prior")))
with(getME(object, c("L", "Lambdat", "Zt", "RX", "X", "RZX")), {
sqrtW <- Diagonal(x = sqrt(weights(model, type = "prior")))
with(getME(model, c("L", "Lambdat", "Zt", "RX", "X", "RZX")), {
## CL:= right factor of the random-effects component of the hat matrix (64)
CL <- solve(L, solve(L, Lambdat %*% Zt %*% sqrtW,
system = "P"), system = "L")
Expand Down
22 changes: 22 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
\name{NEWS}
\title{lme4 News}
\encoding{UTF-8}
\section{CHANGES IN VERSION 1.1-8}{
\subsection{NEW FEATURES}{
\itemize{
\item \code{getME} gains a \code{"Tlist"} option
(returns a vector of template matrices from which the blocks of
\code{Lambda} are generated)
\item \code{hatvalues} method returns the diagonal of the hat matrix

}
}
\subsection{USER-VISIBLE CHANGES}{
\itemize{
\item \code{deviance()} now returns the deviance, rather than half the
negative log-likelihood, for GLMMs (there is no difference for
LMMs)
\item convergence warning and diagnostic test issues are now
reported in \code{print} and \code{summary} methods

}
}
}

\section{CHANGES IN VERSION 1.1-7}{
\subsection{NEW FEATURES}{
\itemize{
Expand Down
3 changes: 2 additions & 1 deletion inst/tests/test-glmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ test_that("glmer", {
expect_equal(c(VarCorr(gm1)[[1]]), 0.41245527438386, tolerance=6e-4)
### expect_that(family(gm1), equals(binomial()))
### ?? binomial() has an 'initialize' component ... and the order is different
expect_equal(deviance(gm1), 184.052674598026, tolerance=1e-5)
expect_equal(deviance(gm1), 73.47428, tolerance=1e-5)
## was -2L = 184.05267459802
expect_equal(sigma(gm1), 1)
expect_equal(extractAIC(gm1), c(5, 194.052674598026), tolerance=1e-5)

Expand Down

0 comments on commit 5ac6f57

Please sign in to comment.