diff --git a/R/maybe.R b/R/maybe.R index 1e7a2af..e4ee45c 100644 --- a/R/maybe.R +++ b/R/maybe.R @@ -64,65 +64,6 @@ maybe <- function(f) { } } -maybe2 <- function(f) { - - cfw <- "(converted from warning)" - - function(...) { - - opts <- options(warn=2) - on.exit(options(opts)) - - returnValue <- NULL - warningValue <- NULL - warningTag <- NULL - errorValue <- NULL - errorTag <- NULL - - returnValue <- tryCatch( - - withCallingHandlers(eval.parent(f(...)), - - error=function(e) { - - if(str_detect(e$message, cfw)) { - - # get rid of conversions junk - msg <- e$message - msg <- substring(msg, 24+str_locate(msg, cfw)[1,1]) - msg <- str_trim(msg) - - warningValue <<- append(warningValue, msg) - wtag <- if(is.null(e$tag)) "" else e$tag - warningTag <<- append(warningTag, wtag) - message(msg) - print(computeRestarts()) - invokeRestart("muffleWarning") - - } else { - - errorValue <<- e$message - errorTag <<- if(is.null(e$tag)) "" else e$tag - return(NULL) - } - } - ) - ) - - rval <- list() - class(rval) <- "Maybe" - - rval["value"] <- list(returnValue) # nb returnValue might be NULL - rval["warning"] <- list(warningValue) - rval["warningtag"] <- list(warningTag) - rval["error"] <- list(errorValue) - rval["errortag"] <- list(errorTag) - - return(rval) - } -} - - list2maybe <- function(x) { rval <- list() diff --git a/vignettes/examples.Rmd b/vignettes/examples.Rmd index eb298b4..64d7cd9 100644 --- a/vignettes/examples.Rmd +++ b/vignettes/examples.Rmd @@ -136,7 +136,7 @@ fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy) doTest(fm1, compare( ~ Days + (1 | Subject))) ``` -The LRT is fast but only approximate. You can also use `compare` with a slower but more accurate parametric bootstrap test from the `pbkrtest` package. +The LRT is fast but only approximate. In fact, when testing random effects, the test is conservative[^1] because the null hypothesis is at a boundary of the parameter space. This means that you will underestimate power if you use the LRT. For more accurate results you can use `compare` with a parametric bootstrap test from the `pbkrtest` package. These can be quite slow, so you may want to use the LRT to exploring designs, and then double check with the parametric bootstrap. ```{r, eval=FALSE} doTest(fm1, compare( ~ Days + (1 | Subject), "pb")) @@ -146,4 +146,6 @@ Note that the shortcut `rcompare` saves you from retyping the fixed effect speci ```{r, eval=FALSE} doTest(fm1, rcompare( ~ (1 | Subject), "pb")) -``` \ No newline at end of file +``` + +[^1]: See, e.g., Pinheiro, J.C., Bates D.M. (2000) _Mixed-Effects Models in S and S-PLUS_, Springer, New York (p84). \ No newline at end of file