From 7ac328748988b70024bce4289eac1dc25804cfd2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Aug 2015 17:40:04 +1200 Subject: [PATCH 1/3] lrtest for factor covariates --- R/testLibrary.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/testLibrary.R b/R/testLibrary.R index 8c20836..2a3cb1d 100644 --- a/R/testLibrary.R +++ b/R/testLibrary.R @@ -102,7 +102,7 @@ fixeddesc <- function(text, xname) { function(fit, sim) { # test used - rval <- if(text=="default") defaultdesc(fit) else text + rval <- if(text=="default") defaultdesc(fit, xname) else text # effect size fe <- maybe(fixef)(sim)$value @@ -122,6 +122,8 @@ fixeddesc <- function(text, xname) { # glmer - ztest defaulttest <- function(fit, xname) { + if(is.factor(getData(fit)[[xname]])) return(lrtest(fit, xname)) + switch(class(fit)[1], lm = ttest(fit, xname), @@ -132,7 +134,9 @@ defaulttest <- function(fit, xname) { ) } -defaultdesc <- function(fit) { +defaultdesc <- function(fit, xname) { + + if(is.factor(getData(fit)[[xname]])) return("Likelihood ratio") switch(class(fit)[1], From d61dbcfbda33f844c6f859f58861551f98d714a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Aug 2015 17:40:34 +1200 Subject: [PATCH 2/3] attempt workaround for uncatchable warnings --- R/maybe.R | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/R/maybe.R b/R/maybe.R index e4ee45c..1e7a2af 100644 --- a/R/maybe.R +++ b/R/maybe.R @@ -64,6 +64,65 @@ 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() From 0e05d3772ea5d3e91be15d317b5bd88df5ca8d17 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Oct 2015 12:52:29 +1300 Subject: [PATCH 3/3] Use @frame and $model for getData --- R/getData.R | 9 ++++++++- tests/testthat/{helper_options.R => test_aaa.R} | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) rename tests/testthat/{helper_options.R => test_aaa.R} (82%) diff --git a/R/getData.R b/R/getData.R index df92e91..27468ae 100644 --- a/R/getData.R +++ b/R/getData.R @@ -34,7 +34,14 @@ getData <- function(object) { if(!is.null(newData)) return(newData) # - # 2nd choice: Use the `data` argument + # 2nd choice: @frame for merMod, $model for lm. + # + + if(is(object, "merMod")) return(object@frame) + if(is(object, "lm")) return(object$model) + + # + # 3rd choice: Use the `data` argument # dataName <- as.character(getCall(object)$data) diff --git a/tests/testthat/helper_options.R b/tests/testthat/test_aaa.R similarity index 82% rename from tests/testthat/helper_options.R rename to tests/testthat/test_aaa.R index ce368ff..9bd0dad 100644 --- a/tests/testthat/helper_options.R +++ b/tests/testthat/test_aaa.R @@ -11,4 +11,4 @@ helperopts <- simrOptions(nsim=test.nsim, progress=test.progress) # Useful to have an example model. # -fm1 <- lmer(y ~ x + (1|g), data=example) +fm1 <- lmer(y ~ x + (1|g), data=simdata)