diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2019-05-08 20:57:48 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2019-05-08 20:57:48 +0200 |
commit | c6079a807e2b400fe0c772603392aeacd887da2f (patch) | |
tree | 5b590e06de87ce9cd5c776fccfabc8a629a10cad /R/plot.mkinfit.R | |
parent | c322a8102a399cbb1fe38c4c4ca4485cea8bc4e8 (diff) |
Add functionality to plot the error model
by plotting squared residuals against predicted values, and
showing the variance function used in the fitted error model.
Rebuild docs
Diffstat (limited to 'R/plot.mkinfit.R')
-rw-r--r-- | R/plot.mkinfit.R | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R index ee836eb8..df9888e7 100644 --- a/R/plot.mkinfit.R +++ b/R/plot.mkinfit.R @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2016 Johannes Ranke +# Copyright (C) 2010-2016,2019 Johannes Ranke # Contact: jranke@uni-bremen.de # This file is part of the R package mkin @@ -26,12 +26,16 @@ plot.mkinfit <- function(x, fit = x, pch_obs = col_obs, lty_obs = rep(1, length(obs_vars)), add = FALSE, legend = !add, - show_residuals = FALSE, maxabs = "auto", + show_residuals = FALSE, + show_errplot = FALSE, + maxabs = "auto", sep_obs = FALSE, rel.height.middle = 0.9, 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 && show_errplot) stop("If adding to an existing plot we can not show the error model plot") + if (show_residuals && show_errplot) stop("We can either show residuals over time or the error model plot, not both") if (add && sep_obs) stop("If adding to an existing plot we can not show observed variables separately") solution_type = fit$solution_type @@ -68,8 +72,7 @@ plot.mkinfit <- function(x, fit = x, # Create a plot layout only if not to be added to an existing plot # or only a single plot is requested (e.g. by plot.mmkin) do_layout = FALSE - if (show_residuals) do_layout = TRUE - if (sep_obs) do_layout = TRUE + if (show_residuals | sep_obs | show_errplot) do_layout = TRUE n_plot_rows = if (sep_obs) length(obs_vars) else 1 if (do_layout) { @@ -78,7 +81,7 @@ plot.mkinfit <- function(x, fit = x, # If the observed variables are shown separately, do row layout if (sep_obs) { - n_plot_cols = if (show_residuals) 2 else 1 + n_plot_cols = if (show_residuals | show_errplot) 2 else 1 n_plots = n_plot_rows * n_plot_cols # Set relative plot heights, so the first and the last plot are the norm @@ -201,6 +204,12 @@ plot.mkinfit <- function(x, fit = x, } abline(h = 0, lty = 2) } + + # Show error model plot if requested + if (show_errplot) { + mkinerrplot(fit, obs_vars = row_obs_vars, pch_obs = pch_obs[row_obs_vars], col_obs = col_obs[row_obs_vars], + legend = FALSE) + } } if (do_layout) par(oldpar, no.readonly = TRUE) } |