aboutsummaryrefslogtreecommitdiff
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
parent43c0ae8431440bab723b35909d43f51434288c33 (diff)
Show chi2 in plot.mkinfit, round with signif
-rw-r--r--R/plot.mkinfit.R19
-rw-r--r--R/plot.mmkin.R9
-rw-r--r--man/mmkin.Rd9
-rw-r--r--man/plot.mkinfit.Rd12
-rw-r--r--man/plot.mmkin.Rd4
5 files changed, 40 insertions, 13 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)
diff --git a/R/plot.mmkin.R b/R/plot.mmkin.R
index 2cbb4a79..7de91e3e 100644
--- a/R/plot.mmkin.R
+++ b/R/plot.mmkin.R
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>
-plot.mmkin <- function(x, main = "auto", legends = 1, errmin_var = "All data", errmin_digits = 2,
+plot.mmkin <- function(x, main = "auto", legends = 1, errmin_var = "All data", errmin_digits = 3,
cex = 0.7, rel.height.middle = 0.9, ...) {
n.m <- nrow(x)
n.d <- ncol(x)
@@ -79,10 +79,9 @@ plot.mmkin <- function(x, main = "auto", legends = 1, errmin_var = "All data", e
datasets = colnames(x)[i.fit],
none = "")
- if (!is.null(errmin_var)) {
- chi2 <- paste0(round(100 * mkinerrmin(fit)[errmin_var, "err.min"], errmin_digits), "%")
- mtext(bquote(.(fit_name) ~ chi^2 ~ "error level" == .(chi2)), cex = cex, line = 0.4)
- }
+ chi2 <- paste0(signif(100 * mkinerrmin(fit)[errmin_var, "err.min"], errmin_digits), "%")
+ mtext(bquote(.(fit_name) ~ chi^2 ~ "error level" == .(chi2)), cex = cex, line = 0.4)
+
mkinresplot(fit, legend = FALSE, ...)
mtext(paste(fit_name, "residuals"), cex = cex, line = 0.4)
}
diff --git a/man/mmkin.Rd b/man/mmkin.Rd
index d088e804..689a1eb4 100644
--- a/man/mmkin.Rd
+++ b/man/mmkin.Rd
@@ -67,10 +67,13 @@ endpoints(fits[["SFO_lin", 2]])
# Plot.mkinfit handles rows or columns of mmkin result objects
plot(fits.0[1, ])
+plot(fits.0[1, ], obs_var = c("M1", "M2"))
plot(fits.0[, 1])
-# Double brackets to select a single mkinfit object, which will be
-# plotted by plot.mkinfit
-plot(fits.0[[1, 1]], sep_obs = TRUE, show_residuals = TRUE)
+# Use double brackets to extract a single mkinfit object, which will be plotted
+# by plot.mkinfit
+plot(fits.0[[1, 1]], sep_obs = TRUE, show_residuals = TRUE, show_errmin = TRUE)
+# Plotting with mmkin (single brackets, extracting an mmkin object) does not
+# allow to plot the observed variables separately
plot(fits.0[1, 1])
}
}
diff --git a/man/plot.mkinfit.Rd b/man/plot.mkinfit.Rd
index bc0b85e8..82900e48 100644
--- a/man/plot.mkinfit.Rd
+++ b/man/plot.mkinfit.Rd
@@ -19,7 +19,8 @@
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), \dots)
+ lpos = "topright", inset = c(0.05, 0.05),
+ show_errmin = FALSE, errmin_digits = 3, \dots)
}
\arguments{
\item{x}{
@@ -84,6 +85,12 @@
\item{inset}{
Passed to \code{\link{legend}} if applicable.
}
+ \item{show_errmin}{
+ Should the FOCUS chi2 error value be shown in the upper margin of the plot?
+ }
+ \item{errmin_digits}{
+ The number of significant digits for rounding the FOCUS chi2 error percentage.
+ }
\item{\dots}{
Further arguments passed to \code{\link{plot}}.
}
@@ -104,7 +111,8 @@ plot(fit, show_residuals = TRUE)
plot(fit, sep_obs = TRUE, lpos = c("topright", "bottomright"))
# Show the observed variables separately, with residuals
-plot(fit, sep_obs = TRUE, show_residuals = TRUE, lpos = c("topright", "bottomright"))
+plot(fit, sep_obs = TRUE, show_residuals = TRUE, lpos = c("topright", "bottomright"),
+ show_errmin = TRUE)
}
\author{
Johannes Ranke
diff --git a/man/plot.mmkin.Rd b/man/plot.mmkin.Rd
index 37d7a25a..cfc7a35b 100644
--- a/man/plot.mmkin.Rd
+++ b/man/plot.mmkin.Rd
@@ -9,7 +9,7 @@
to the same dataset is shown.
}
\usage{
-\method{plot}{mmkin}(x, main = "auto", legends = 1, errmin_var = "All data", errmin_digits = 2,
+\method{plot}{mmkin}(x, main = "auto", legends = 1, errmin_var = "All data", errmin_digits = 3,
cex = 0.7, rel.height.middle = 0.9, ...)
}
\arguments{
@@ -26,7 +26,7 @@
The variable for which the FOCUS chi2 error value should be shown.
}
\item{errmin_digits}{
- The number of digits for rounding the FOCUS chi2 error percentage.
+ The number of significant digits for rounding the FOCUS chi2 error percentage.
}
\item{cex}{
Passed to the plot functions and \code{\link{mtext}}.

Contact - Imprint