aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorJohannes Ranke <johannes.ranke@jrwb.de>2018-09-14 14:06:57 +0200
committerJohannes Ranke <johannes.ranke@jrwb.de>2018-09-14 14:06:57 +0200
commitd52e522a9abea09fae1189b066e2a2e1dbb9cb34 (patch)
tree0ae81885f134009e883d5e5bda25f6f392cca6be /R
parentc4a35c0e141a4bb05ba508914bebdc2884109e76 (diff)
Avoid nls crashes by checking for a correlation first
Diffstat (limited to 'R')
-rw-r--r--R/mkinfit.R7
1 files changed, 7 insertions, 0 deletions
diff --git a/R/mkinfit.R b/R/mkinfit.R
index ecbef67e..2c4e3268 100644
--- a/R/mkinfit.R
+++ b/R/mkinfit.R
@@ -415,6 +415,13 @@ mkinfit <- function(mkinmod, observed,
# We need unweighted residuals to update the weighting
cost_tmp <- cost(fit$par)
+ p_tmp <- cor.test(abs(cost_tmp$residuals$res.unweighted),
+ cost_tmp$residuals$obs, method = "kendall")$p.value
+ if (p_tmp > 0.1) {
+ stop("No correlation of absolute residuals with observed values found.\n",
+ "Try without reweighting or with reweight.method = 'obs'.")
+ }
+
tc_fit <- try(
nls(abs(res.unweighted) ~ sigma_twocomp(obs, sigma_low, rsd_high),
start = list(sigma_low = tc["sigma_low"], rsd_high = tc["rsd_high"]),

Contact - Imprint