diff options
author | jranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb> | 2013-02-18 22:11:49 +0000 |
---|---|---|
committer | jranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb> | 2013-02-18 22:11:49 +0000 |
commit | fa10b85d6bb964742d2c5a3e3f633a5238c43d56 (patch) | |
tree | 7497bddd9937aee3989db75cae5bbdff3fae9146 /R | |
parent | 67860242fc619624421a8fd96ba9e385456a9c2d (diff) |
- Completion of the multicompartment part of the mkin examples vignette
- Fix to chi2 error level calculation by correctly returning backtransformed
parameters as bparms.optim and bparms.fixed
- Adaptations of unit tests, summary and plot functions
git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@67 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
Diffstat (limited to 'R')
-rw-r--r-- | R/endpoints.R | 2 | ||||
-rw-r--r-- | R/mkinerrmin.R | 2 | ||||
-rw-r--r-- | R/mkinfit.R | 22 | ||||
-rw-r--r-- | R/plot.mkinfit.R | 5 |
4 files changed, 17 insertions, 14 deletions
diff --git a/R/endpoints.R b/R/endpoints.R index 98e290d..163dc8d 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -3,7 +3,7 @@ endpoints <- function(fit, pseudoDT50 = FALSE) { # fractions and SFORB eigenvalues from optimised parameters
ep <- list()
obs_vars <- fit$obs_vars
- parms.all <- fit$parms.all
+ parms.all <- fit$bparms.ode
ep$distimes <- data.frame(DT50 = rep(NA, length(obs_vars)),
DT90 = rep(NA, length(obs_vars)),
row.names = obs_vars)
diff --git a/R/mkinerrmin.R b/R/mkinerrmin.R index 49538e3..8b1e9b2 100644 --- a/R/mkinerrmin.R +++ b/R/mkinerrmin.R @@ -20,7 +20,7 @@ utils::globalVariables(c("name"))
mkinerrmin <- function(fit, alpha = 0.05)
{
- parms.optim <- fit$parms.all
+ parms.optim <- fit$par
kinerrmin <- function(errdata, n.parms) {
means.mean <- mean(errdata$value_mean, na.rm=TRUE)
df = length(errdata$value_mean) - n.parms
diff --git a/R/mkinfit.R b/R/mkinfit.R index e084cf1..3ca3899 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -191,7 +191,9 @@ mkinfit <- function(mkinmod, observed, value = c(state.ini.fixed, parms.fixed))
fit$fixed$type = c(rep("state", length(state.ini.fixed)), rep("deparm", length(parms.fixed)))
- parms.all = backtransform_odeparms(c(fit$par, parms.fixed), mod_vars)
+ bparms.optim = backtransform_odeparms(fit$par, mod_vars)
+ bparms.fixed = backtransform_odeparms(c(state.ini.fixed, parms.fixed), mod_vars)
+ bparms.all = c(bparms.optim, bparms.fixed)
# Collect observed, predicted and residuals
data <- merge(fit$observed, fit$predicted, by = c("time", "name"))
@@ -201,8 +203,10 @@ mkinfit <- function(mkinmod, observed, fit$data <- data[order(data$variable, data$time), ]
fit$atol <- atol
fit$rtol <- rtol
- fit$parms.all <- parms.all # Return all backtransformed parameters for summary
- fit$odeparms.final <- parms.all[mkinmod$parms] # Return ode parameters for further fitting
+ # Return all backtransformed parameters for summary
+ fit$bparms.optim <- bparms.optim
+ fit$bparms.fixed <- bparms.fixed
+ fit$bparms.ode <- bparms.all[mkinmod$parms] # Return ode parameters for further fitting
fit$date <- date()
class(fit) <- c("mkinfit", "modFit")
@@ -231,7 +235,7 @@ summary.mkinfit <- function(object, data = TRUE, distimes = TRUE, ...) { param <- cbind(param, se)
dimnames(param) <- list(pnames, c("Estimate", "Std. Error"))
- bparam <- as.matrix(object$parms.all)
+ bparam <- as.matrix(object$bparms.optim)
dimnames(bparam) <- list(pnames, c("Estimate"))
ans <- list(
@@ -259,9 +263,9 @@ summary.mkinfit <- function(object, data = TRUE, distimes = TRUE, ...) { ans$errmin <- mkinerrmin(object, alpha = 0.05)
- ans$parms.all <- object$parms.all
+ ans$bparms.ode <- object$bparms.ode
ep <- endpoints(object)
- if (!is.null(ep$ff))
+ if (length(ep$ff) != 0)
ans$ff <- ep$ff
if(distimes) ans$distimes <- ep$distimes
if(length(ep$SFORB) != 0) ans$SFORB <- ep$SFORB
@@ -305,19 +309,19 @@ print.summary.mkinfit <- function(x, digits = max(3, getOption("digits") - 3), . if(printdistimes){
cat("\nEstimated disappearance times:\n")
print(x$distimes, digits=digits,...)
- }
+ }
printff <- !is.null(x$ff)
if(printff & x$use_of_ff == "min"){
cat("\nEstimated formation fractions:\n")
print(data.frame(ff = x$ff), digits=digits,...)
- }
+ }
printSFORB <- !is.null(x$SFORB)
if(printSFORB){
cat("\nEstimated Eigenvalues of SFORB model(s):\n")
print(x$SFORB, digits=digits,...)
- }
+ }
printcor <- is.numeric(x$cov.unscaled)
if (printcor){
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R index fc8ecf7..59ef861 100644 --- a/R/plot.mkinfit.R +++ b/R/plot.mkinfit.R @@ -30,9 +30,8 @@ plot.mkinfit <- function(x, fit = x, 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) + parms.all <- c(fit$bparms.optim, fit$bparms.fixed) + ininames <- c( rownames(subset(fit$start, type == "state")), rownames(subset(fit$fixed, type == "state"))) |