aboutsummaryrefslogtreecommitdiff
path: root/R/plot.mkinfit.R
diff options
context:
space:
mode:
authorjranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>2012-11-26 23:03:19 +0000
committerjranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>2012-11-26 23:03:19 +0000
commitdf916b91c90f80e2c68f3e136a7b6e07b8c6bae1 (patch)
tree4b54b46c68a0b5866aa6bf15131b55b34668af08 /R/plot.mkinfit.R
parentd267b8c116f78ee9b7b4d76c9ddb7b8950a127b4 (diff)
- Added an S3 plot method for mkinfit models
- Fixed a bug in the mkinfit summary method which crashed on missing covariance matrices git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@58 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Diffstat (limited to 'R/plot.mkinfit.R')
-rw-r--r--R/plot.mkinfit.R45
1 files changed, 45 insertions, 0 deletions
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R
new file mode 100644
index 0000000..1858aa8
--- /dev/null
+++ b/R/plot.mkinfit.R
@@ -0,0 +1,45 @@
+plot.mkinfit <- function(x, fit = x,
+ xlab = "Time", ylab = "Observed",
+ xlim = range(fit$data$time), ylim = range(fit$data$observed, na.rm = TRUE),
+ col_obs = 1:length(fit$mkinmod$map),
+ pch_obs = col_obs, lty_obs = rep(1, length(fit$mkinmod$map)),
+ add = FALSE, legend = !add, ...)
+{
+ solution_type = fit$solution_type
+ fixed <- fit$fixed$value
+ names(fixed) <- rownames(fit$fixed)
+ parms.all <- c(fit$parms.all, fixed)
+ ininames <- c(
+ rownames(subset(fit$start, type == "state")),
+ rownames(subset(fit$fixed, type == "state")))
+ odeini <- parms.all[ininames]
+ names(odeini) <- names(fit$mkinmod$diffs)
+
+ outtimes <- seq(xlim[1], xlim[2], length.out=100)
+
+ odenames <- c(
+ rownames(subset(fit$start, type == "deparm")),
+ rownames(subset(fit$fixed, type == "deparm")))
+ odeparms <- parms.all[odenames]
+
+ out <- mkinpredict(fit$mkinmod, odeparms, odeini, outtimes,
+ solution_type = solution_type, atol = fit$atol, rtol = fit$rtol, ...)
+
+ # Set up the plot if not to be added to an existing plot
+ if (add == FALSE) {
+ plot(0, type="n",
+ xlim = xlim, ylim = ylim,
+ xlab = xlab, ylab = ylab, ...)
+ }
+ # Plot the data and model output
+ names(col_obs) <- names(pch_obs) <- names(lty_obs) <- names(fit$mkinmod$map)
+ for (obs_var in names(fit$mkinmod$map)) {
+ points(subset(fit$data, variable == obs_var, c(time, observed)),
+ pch = pch_obs[obs_var], col = col_obs[obs_var])
+ }
+ matlines(out$time, out[-1], col = col_obs, lty = lty_obs)
+ if (legend == TRUE) {
+ legend("topright", inset=c(0.05, 0.05), legend=names(fit$mkinmod$map),
+ col=col_obs, pch=pch_obs, lty=lty_obs)
+ }
+}

Contact - Imprint