aboutsummaryrefslogtreecommitdiff
path: root/R/mkinstart.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/mkinstart.R')
-rw-r--r--R/mkinstart.R23
1 files changed, 23 insertions, 0 deletions
diff --git a/R/mkinstart.R b/R/mkinstart.R
new file mode 100644
index 00000000..46e5bed7
--- /dev/null
+++ b/R/mkinstart.R
@@ -0,0 +1,23 @@
+mkinstart <- function(model, data, mode = "auto")
+{
+ if (class(model) != "mkinmod") stop("The first argument must be a model of class mkinmod")
+ names <- model$parms
+ observed <- names(model$map)
+ if(!all(observed %in% levels(data$name))) stop("The data must contain the observed variables used in the model")
+ for (obs in observed)
+ {
+ tmp <- subset(data, name == obs)
+ max <- tmp[which.max(tmp$value), ]
+ type = names(model$map[[obs]])[[1]]
+ kinmodel <- ifelse(type == "SFORB", "DFOP", type)
+ tmp.longdata <- subset(data, name == obs & time >= max$time)
+ tmp.widedata <- mkin_long_to_wide(tmp.longdata, outtime = "t")
+ names(tmp.widedata) <- c("t", "parent")
+ tmp.fit <- kinfit(
+ kindata = tmp.widedata,
+ kinmodels = kinmodel,
+ parent.0.user = max$value)
+ if(class(tmp.fit[[kinmodel]]) == "try-error") stop(paste("Automatic generation of starting parameters failed\nkinfit failed to find a", kinmodel, "fit for", obs))
+ tmp.results <- kinresults(tmp.fit)
+ }
+}

Contact - Imprint