From 9e0dae397df8c18e7333d2604cae96b2a7927420 Mon Sep 17 00:00:00 2001 From: ranke Date: Fri, 23 Jun 2006 15:33:27 +0000 Subject: - inverse.predict now has a var.s argument instead of the never tested ss argument. This is documented in the updated vignette - loq() now has w.loq and var.loq arguments, and stops with a message if neither are specified and the model has weights. - calplot doesn't stop any more for weighted regression models, but only refrains from drawing prediction bands - Added method = "din" to lod(), now that I actually have it (DIN 32645) and was able to see which approximation is used therein. - removed the demos, as the examples and tests are already partially duplicated - The vignette is more of a collection of various notes, but should certainly be helpful for the user. - Version bump to 0.1-xxx git-svn-id: http://kriemhild.uft.uni-bremen.de/svn/chemCal@16 5fad18fb-23f0-0310-ab10-e59a3bee62b4 --- R/lod.R | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'R/lod.R') diff --git a/R/lod.R b/R/lod.R index 54618c8..f5bbb7d 100644 --- a/R/lod.R +++ b/R/lod.R @@ -1,14 +1,14 @@ -lod <- function(object, ..., alpha = 0.05, beta = 0.05) +lod <- function(object, ..., alpha = 0.05, beta = 0.05, method = "default") { UseMethod("lod") } -lod.default <- function(object, ..., alpha = 0.05, beta = 0.05) +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) +lod.lm <- function(object, ..., alpha = 0.05, beta = 0.05, method = "default") { if (length(object$weights) > 0) { stop(paste( @@ -24,23 +24,29 @@ lod.lm <- function(object, ..., alpha = 0.05, beta = 0.05) yname <- names(object$model)[[1]] newdata <- data.frame(0) names(newdata) <- xname - y0 <- predict(object, newdata, interval="prediction", - level = 1 - 2 * alpha ) + y0 <- predict(object, newdata, interval = "prediction", + level = 1 - 2 * alpha) yc <- y0[[1,"upr"]] - xc <- inverse.predict(object,yc)[["Prediction"]] - f <- function(x) - { - newdata <- data.frame(x) - names(newdata) <- xname - pi.y <- predict(object, newdata, interval = "prediction", + if (method == "din") { + y0.d <- predict(object, newdata, interval = "prediction", level = 1 - 2 * beta) - yd <- pi.y[[1,"lwr"]] - (yd - yc)^2 + 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.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) -- cgit v1.2.1