diff options
author | jranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb> | 2012-03-15 15:54:14 +0000 |
---|---|---|
committer | jranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb> | 2012-03-15 15:54:14 +0000 |
commit | 1718d434efae26de02754c6622c43f4dc9e624b9 (patch) | |
tree | c2dafe942f65e94cd43e1ba17933b667f284d154 /R/mkinstart.R | |
parent | 2b244ef7d3cbebaaa653d8c8ac87090e34525f7a (diff) |
Update kinfit and mkin to the latest version published on BerliOS.
git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@17 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Diffstat (limited to 'R/mkinstart.R')
-rw-r--r-- | R/mkinstart.R | 23 |
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)
+ }
+}
|