Skip to content

Commit

Permalink
update examples vignette (LRT for random effects)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Oct 12, 2015
1 parent 6c19bad commit b1f454b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 61 deletions.
59 changes: 0 additions & 59 deletions R/maybe.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions vignettes/examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
```
```

[^1]: See, e.g., Pinheiro, J.C., Bates D.M. (2000) _Mixed-Effects Models in S and S-PLUS_, Springer, New York (p84).

0 comments on commit b1f454b

Please sign in to comment.