diff options
author | ranke <ranke@5fad18fb-23f0-0310-ab10-e59a3bee62b4> | 2007-10-01 19:44:04 +0000 |
---|---|---|
committer | ranke <ranke@5fad18fb-23f0-0310-ab10-e59a3bee62b4> | 2007-10-01 19:44:04 +0000 |
commit | 14a5af60a36071f6a9b4471fdf183fd91e89e1cd (patch) | |
tree | 8c845109c3b3e7663b903f3a9d06f7094a4438d8 /trunk/R/lod.R | |
parent | 3dec3886b58f73427409d3ef9427c8440420cbc0 (diff) |
Moved everything into the trunk directory, in order to enable branching
git-svn-id: http://kriemhild.uft.uni-bremen.de/svn/chemCal@22 5fad18fb-23f0-0310-ab10-e59a3bee62b4
Diffstat (limited to 'trunk/R/lod.R')
-rw-r--r-- | trunk/R/lod.R | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/trunk/R/lod.R b/trunk/R/lod.R new file mode 100644 index 0000000..f5bbb7d --- /dev/null +++ b/trunk/R/lod.R @@ -0,0 +1,53 @@ +lod <- function(object, ..., alpha = 0.05, beta = 0.05, method = "default") +{ + UseMethod("lod") +} + +lod.default <- function(object, ..., alpha = 0.05, beta = 0.05, method = "default") +{ + stop("lod is only implemented for univariate lm objects.") +} + +lod.lm <- function(object, ..., alpha = 0.05, beta = 0.05, method = "default") +{ + if (length(object$weights) > 0) { + stop(paste( + "\nThe detemination of a lod from calibration models obtained by", + "weighted linear regression requires confidence intervals for", + "predicted y values taking into account weights for the x values", + "from which the predictions are to be generated.", + "This is not supported by the internally used predict.lm method.", + sep = "\n" + )) + } + xname <- names(object$model)[[2]] + yname <- names(object$model)[[1]] + newdata <- data.frame(0) + names(newdata) <- xname + y0 <- predict(object, newdata, interval = "prediction", + level = 1 - 2 * alpha) + yc <- y0[[1,"upr"]] + if (method == "din") { + y0.d <- predict(object, newdata, interval = "prediction", + level = 1 - 2 * beta) + deltay <- y0.d[[1, "upr"]] - y0.d[[1, "fit"]] + lod.y <- yc + deltay + lod.x <- inverse.predict(object, lod.y)$Prediction + } else { + f <- function(x) { + newdata <- data.frame(x) + names(newdata) <- xname + pi.y <- predict(object, newdata, interval = "prediction", + level = 1 - 2 * beta) + yd <- pi.y[[1,"lwr"]] + (yd - yc)^2 + } + lod.x <- optimize(f,interval=c(0,max(object$model[[xname]])))$minimum + newdata <- data.frame(x = lod.x) + names(newdata) <- xname + lod.y <- predict(object, newdata) + } + lod <- list(lod.x, lod.y) + names(lod) <- c(xname, yname) + return(lod) +} |