From 96c8558842e2494f42c0e148fb8d8f422000ecde Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 3 Nov 2020 16:07:59 +0100 Subject: Do not test residuals per default, improve nlme.mmkin Do not give starting values for random effects in nlme.mmkin. --- R/mkinfit.R | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'R/mkinfit.R') diff --git a/R/mkinfit.R b/R/mkinfit.R index 65dd5d75..1b1bb73d 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -148,6 +148,7 @@ if(getRversion() >= '2.15.1') utils::globalVariables(c("name", "time", "value")) #' the error model parameters in IRLS fits. #' @param reweight.max.iter Maximum number of iterations in IRLS fits. #' @param trace_parms Should a trace of the parameter values be listed? +#' @param test_residuals Should the residuals be tested for normal distribution? #' @param \dots Further arguments that will be passed on to #' [deSolve::ode()]. #' @importFrom stats nlminb aggregate dist shapiro.test @@ -254,6 +255,7 @@ mkinfit <- function(mkinmod, observed, error_model_algorithm = c("auto", "d_3", "direct", "twostep", "threestep", "fourstep", "IRLS", "OLS"), reweight.tol = 1e-8, reweight.max.iter = 10, trace_parms = FALSE, + test_residuals = FALSE, ...) { call <- match.call() @@ -933,12 +935,14 @@ mkinfit <- function(mkinmod, observed, # Assign the class here so method dispatch works for residuals class(fit) <- c("mkinfit") - # Check for normal distribution of residuals - fit$shapiro.p <- shapiro.test(residuals(fit, standardized = TRUE))$p.value - if (fit$shapiro.p < 0.05) { - shapiro_warning <- paste("Shapiro-Wilk test for standardized residuals: p = ", signif(fit$shapiro.p, 3)) - warning(shapiro_warning) - summary_warnings <- c(summary_warnings, S = shapiro_warning) + if (test_residuals) { + # Check for normal distribution of residuals + fit$shapiro.p <- shapiro.test(residuals(fit, standardized = TRUE))$p.value + if (fit$shapiro.p < 0.05) { + shapiro_warning <- paste("Shapiro-Wilk test for standardized residuals: p = ", signif(fit$shapiro.p, 3)) + warning(shapiro_warning) + summary_warnings <- c(summary_warnings, S = shapiro_warning) + } } fit$summary_warnings <- summary_warnings -- cgit v1.2.1