aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-11-10 17:21:11 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2015-11-10 17:21:11 +0100
commit95cd05e803213b37245e29108d4c89089a3fefc9 (patch)
tree3717771727a555e151c278061874530398c4ca66
parent1b656abc0f600af034dbbd68a929c1498f022fb6 (diff)
Make it possible to save model predictions as CSV file
-rw-r--r--inst/GUI/gmkin.R31
1 files changed, 31 insertions, 0 deletions
diff --git a/inst/GUI/gmkin.R b/inst/GUI/gmkin.R
index d93e296..751ffa9 100644
--- a/inst/GUI/gmkin.R
+++ b/inst/GUI/gmkin.R
@@ -982,6 +982,35 @@ keep_fit_handler <- function(h, ...) { # {{{3
update_plot_obssel()
p.modified <<- TRUE
}
+export_csv_handler <- function(h, ...) { # {{{3
+ csv_file <- paste(ftmp$ds$title, "_", ftmp$mkinmod$name, ".csv", sep = "")
+
+ solution_type = ftmp$solution_type
+ parms.all <- c(ftmp$bparms.optim, ftmp$bparms.fixed)
+
+ ininames <- c(
+ rownames(subset(ftmp$start, type == "state")),
+ rownames(subset(ftmp$fixed, type == "state")))
+ odeini <- parms.all[ininames]
+
+ # Order initial state variables
+ names(odeini) <- sub("_0", "", names(odeini))
+ odeini <- odeini[names(ftmp$mkinmod$diffs)]
+
+ xlim = range(ftmp$data$time)
+ outtimes <- seq(xlim[1], xlim[2], length.out=200)
+
+ odenames <- c(
+ rownames(subset(ftmp$start, type == "deparm")),
+ rownames(subset(ftmp$fixed, type == "deparm")))
+ odeparms <- parms.all[odenames]
+
+ out <- mkinpredict(ftmp$mkinmod, odeparms, odeini, outtimes,
+ solution_type = solution_type, atol = ftmp$atol, rtol = ftmp$rtol)
+
+ write.csv(out, csv_file)
+ svalue(sb) <- paste("Wrote model predictions to", file.path(getwd(), csv_file))
+}
get_Parameters <- function(stmp, optimised) # {{{3
{
pars <- rbind(stmp$start[1:2], stmp$fixed)
@@ -1140,6 +1169,8 @@ f.delete <- gbutton("Delete fit", cont = r.buttons,
f.keep <- gbutton("Keep fit", cont = r.buttons, handler = keep_fit_handler)
tooltip(f.keep) <- "Store the optimised model with all settings and the current dataset in the fit list"
f.keep$call_Ext("disable")
+f.csv <- gbutton("Export csv", cont = r.buttons, handler = export_csv_handler)
+tooltip(f.csv) <- "Save model predictions in a text file as comma separated values for plotting"
# Result name {{{2
r.line.name <- ggroup(cont = r.viewer, horizontal = TRUE)
r.name <- gedit("", label = "<b>Result name</b>",

Contact - Imprint