aboutsummaryrefslogtreecommitdiff
path: root/R/plot.mkinfit.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-06-27 10:02:49 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2016-06-27 10:02:49 +0200
commitb14fe21e176f523e800793102fb5634e468b3165 (patch)
treea67888ca4da48f0ce191a23be706268e104aa01e /R/plot.mkinfit.R
parent43c0ae8431440bab723b35909d43f51434288c33 (diff)
Show chi2 in plot.mkinfit, round with signif
Diffstat (limited to 'R/plot.mkinfit.R')
-rw-r--r--R/plot.mkinfit.R19
1 files changed, 18 insertions, 1 deletions
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R
index 58ff88bc..3ca18c19 100644
--- a/R/plot.mkinfit.R
+++ b/R/plot.mkinfit.R
@@ -28,7 +28,8 @@ plot.mkinfit <- function(x, fit = x,
add = FALSE, legend = !add,
show_residuals = FALSE, maxabs = "auto",
sep_obs = FALSE, rel.height.middle = 0.9,
- lpos = "topright", inset = c(0.05, 0.05), ...)
+ lpos = "topright", inset = c(0.05, 0.05),
+ show_errmin = FALSE, errmin_digits = 3, ...)
{
if (add && show_residuals) stop("If adding to an existing plot we can not show residuals")
if (add && sep_obs) stop("If adding to an existing plot we can not show observed variables separately")
@@ -152,6 +153,22 @@ plot.mkinfit <- function(x, fit = x,
col = col_obs[row_obs_vars], pch = pch_obs[row_obs_vars], lty = lty_obs[row_obs_vars])
}
+ # Show chi2 error value if requested
+ if (show_errmin) {
+ if (length(row_obs_vars) == 1) {
+ errmin_var = row_obs_vars
+ } else {
+ errmin_var = "All data"
+ if (length(row_obs_vars) != length(fit$mkinmod$map)) {
+ warning("Showing chi2 error level for all data, but only ",
+ row_obs_vars, " were selected for plotting")
+ }
+ }
+
+ chi2 <- paste0(signif(100 * mkinerrmin(fit)[errmin_var, "err.min"], errmin_digits), "%")
+ mtext(bquote(chi^2 ~ "error level" == .(chi2)), cex = 0.7, line = 0.4)
+ }
+
# Show residuals if requested
if (show_residuals) {
residuals <- subset(fit$data, variable %in% row_obs_vars, residual)

Contact - Imprint