Skip to content

Commit

Permalink
fix merMod + confint + profile
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Jan 20, 2019
1 parent 54cc795 commit fbe9597
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/lme4_tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ tidy.merMod <- function(x, effects = c("ran_pars", "fixed"),
stop("unknown effect type ", miss)
}

if (conf.int && conf.method == "profile" && !is.null(profile)) {
p <- profile
} else {
p <- x
}

ret_list <- list()
if ("fixed" %in% effects) {
# return tidied fixed effects
Expand All @@ -162,12 +168,6 @@ tidy.merMod <- function(x, effects = c("ran_pars", "fixed"),
print(coef(ss))
}

if (conf.int && conf.method == "profile" && !is.null(profile)) {
p <- profile
} else {
p <- x
}

## need to save rownames before dplyr (mutate(), bind_cols())
## destroys them ...
ret <- tibblify(ret)
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-lme4.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ test_that("tidy respects conf.level", {
expect_equal(tmpf(0.5),244.831,tolerance=1e-4)
})

test_that("effects='ran_pars' + conf.int works", {
tt <- tidy(lmm0, effects="ran_pars", conf.int=TRUE, conf.method="profile",
quiet=TRUE)[c("conf.low","conf.high")]
tt0 <- structure(list(conf.low = c(26.007120448854, 27.8138472081303
), conf.high = c(52.9359835296834, 34.591049857869)), row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame"))
tt0 <- structure(list(conf.low = c(26.00712, 27.81384),
conf.high = c(52.9359, 34.59104)),
row.names = c(NA, -2L),
class = c("tbl_df", "tbl", "data.frame"))
## ??? why do I need as.data.frame??
## otherwise [1] "Rows in x but not y: 2, 1. Rows in y but not x: 2, 1. "
expect_equal(as.data.frame(tt0), as.data.frame(tt),
tolerance=1e-5)

})

## KEEP THIS LAST to avoid screwing up S3 methods stack
if (require(lmerTest, quietly = TRUE)) {
context("lmerTest")
test_that("lmerTest results include p-values", {
Expand Down

0 comments on commit fbe9597

Please sign in to comment.