From 31fd7412f46c9715962763d435cb0060ea420752 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Mon, 4 Nov 2019 17:21:04 +0100 Subject: Include fixed parameters in model names in lrtest --- NEWS.md | 4 +++- R/confint.mkinfit.R | 8 ++++---- R/lrtest.mkinfit.R | 18 ++++++++++++++---- docs/news/index.html | 5 +++-- docs/reference/confint.mkinfit.html | 20 ++++++++++---------- docs/reference/lrtest.mkinfit.html | 30 ++++++++++++++++++++++++------ man/confint.mkinfit.Rd | 8 ++++---- man/lrtest.mkinfit.Rd | 8 ++++++-- 8 files changed, 68 insertions(+), 33 deletions(-) diff --git a/NEWS.md b/NEWS.md index b9d58a27..cfb9fa96 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # mkin 0.9.49.8 (unreleased) -- 'confint.mkinfit': Make the quadratic approximation the default, as the likelihood profiling takes too much time for any with more than three parameters +- 'lrtest.mkinfit': Improve naming of the compared fits in the case of fixed parameters + +- 'confint.mkinfit': Make the quadratic approximation the default, as the likelihood profiling takes a lot of time, especially if the fit has more than three parameters # mkin 0.9.49.7 (2019-11-01) diff --git a/R/confint.mkinfit.R b/R/confint.mkinfit.R index 84183808..78dda95d 100644 --- a/R/confint.mkinfit.R +++ b/R/confint.mkinfit.R @@ -4,10 +4,10 @@ #' the curvature of the likelihood function at the maximum likelihood parameter #' estimates. #' The alternative method 'profile' is based on the profile likelihood for each -#' parameter. The method uses two nested optimisations and can take a very long -#' time, even if parallelized by specifying 'cores' on unixoid platforms. The -#' speed of the method could likely be improved by using the method of Venzon -#' and Moolgavkar (1988). +#' parameter. The 'profile' method uses two nested optimisations and can take a +#' very long time, even if parallelized by specifying 'cores' on unixoid +#' platforms. The speed of the method could likely be improved by using the +#' method of Venzon and Moolgavkar (1988). #' #' @param object An \code{\link{mkinfit}} object #' @param parm A vector of names of the parameters which are to be given diff --git a/R/lrtest.mkinfit.R b/R/lrtest.mkinfit.R index 60b6c46a..a5689830 100644 --- a/R/lrtest.mkinfit.R +++ b/R/lrtest.mkinfit.R @@ -30,17 +30,27 @@ lmtest::lrtest #' dfop_fit <- mkinfit("DFOP", test_data, quiet = TRUE) #' lrtest(dfop_fit, sfo_fit) #' lrtest(sfo_fit, dfop_fit) -#' +#' #' # The following two examples are commented out as they fail during #' # generation of the static help pages by pkgdown -#' # lrtest(dfop_fit, error_model = "tc") -#' # lrtest(dfop_fit, fixed_parms = c(k2 = 0)) +#' #lrtest(dfop_fit, error_model = "tc") +#' #lrtest(dfop_fit, fixed_parms = c(k2 = 0)) +#' +#' # However, this equivalent syntax works for static help pages +#' lrtest(dfop_fit, update(dfop_fit, error_model = "tc")) +#' lrtest(dfop_fit, update(dfop_fit, fixed_parms = c(k2 = 0))) #' } #' @export lrtest.mkinfit <- function(object, object_2 = NULL, ...) { name_function <- function(x) { - paste(x$mkinmod$name, "with error model", x$err_mod) + object_name <- paste(x$mkinmod$name, "with error model", x$err_mod) + if (length(x$bparms.fixed) > 0) { + object_name <- paste(object_name, + "and fixed parameter(s)", + paste(names(x$bparms.fixed), collapse = ", ")) + } + return(object_name) } if (is.null(object_2)) { diff --git a/docs/news/index.html b/docs/news/index.html index baddfc96..5aef06f9 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -134,12 +134,13 @@ mkin 0.9.49.8 (unreleased) Unreleased

-mkin 0.9.49.7 (2019-11-01) Unreleased +mkin 0.9.49.7 (2019-11-01) 2019-11-02

# S3 method for mkinfit
@@ -254,13 +254,13 @@ On Windows machines, cores > 1 is currently not supported.

use_of_ff = "max", quiet = TRUE) f_d_1 <- mkinfit(SFO_SFO, subset(FOCUS_2006_D, value != 0), quiet = TRUE) system.time(ci_profile <- confint(f_d_1, method = "profile", cores = 1, quiet = TRUE))
#> User System verstrichen -#> 51.341 0.000 51.370
# Using more cores does not save much time here, as parent_0 takes up most of the time +#> 51.058 0.000 51.088
# Using more cores does not save much time here, as parent_0 takes up most of the time # If we additionally exclude parent_0 (the confidence of which is often of # minor interest), we get a nice performance improvement from about 50 # seconds to about 12 seconds if we use at least four cores system.time(ci_profile_no_parent_0 <- confint(f_d_1, method = "profile", c("k_parent_sink", "k_parent_m1", "k_m1_sink", "sigma"), cores = n_cores))
#> Profiling the likelihood
#> User System verstrichen -#> 0.001 0.007 11.432
ci_profile
#> 2.5% 97.5% +#> 0.005 0.004 11.349
ci_profile
#> 2.5% 97.5% #> parent_0 96.456003650 1.027703e+02 #> k_parent_sink 0.040762501 5.549764e-02 #> k_parent_m1 0.046786482 5.500879e-02 diff --git a/docs/reference/lrtest.mkinfit.html b/docs/reference/lrtest.mkinfit.html index fae471fc..1d82eb74 100644 --- a/docs/reference/lrtest.mkinfit.html +++ b/docs/reference/lrtest.mkinfit.html @@ -73,7 +73,7 @@ and can be expressed by fixing the parameters of the other." /> mkin - 0.9.49.6 + 0.9.49.8
@@ -196,11 +196,29 @@ lower number of fitted parameters (null hypothesis).

#> 2 3 -63.954 -2 43.002 4.594e-10 *** #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
-# The following two examples are commented out as they fail during -# generation of the static help pages by pkgdown -# lrtest(dfop_fit, error_model = "tc") -# lrtest(dfop_fit, fixed_parms = c(k2 = 0)) -# } +# The following two examples are commented out as they fail during +# generation of the static help pages by pkgdown +#lrtest(dfop_fit, error_model = "tc") +#lrtest(dfop_fit, fixed_parms = c(k2 = 0)) + +# However, this equivalent syntax works for static help pages +lrtest(dfop_fit, update(dfop_fit, error_model = "tc"))
#> Likelihood ratio test +#> +#> Model 1: DFOP with error model tc +#> Model 2: DFOP with error model const +#> #Df LogLik Df Chisq Pr(>Chisq) +#> 1 6 -34.587 +#> 2 5 -42.453 -1 15.731 7.302e-05 *** +#> --- +#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
lrtest(dfop_fit, update(dfop_fit, fixed_parms = c(k2 = 0)))
#> Likelihood ratio test +#> +#> Model 1: DFOP with error model const +#> Model 2: DFOP with error model const and fixed parameter(s) k2 +#> #Df LogLik Df Chisq Pr(>Chisq) +#> 1 5 -42.453 +#> 2 4 -57.340 -1 29.776 4.851e-08 *** +#> --- +#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# }