From dfe21c80737eff2f273f54fa4bc781b4ddf6e5c8 Mon Sep 17 00:00:00 2001 From: ranke Date: Tue, 9 May 2006 15:26:22 +0000 Subject: Started a new approach, namely just adding a inverse.predict method for univariate lm models. This will be based on Massart, p. 200. git-svn-id: http://kriemhild.uft.uni-bremen.de/svn/chemCal@3 5fad18fb-23f0-0310-ab10-e59a3bee62b4 --- R/inverse.predict.lm.R | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 R/inverse.predict.lm.R diff --git a/R/inverse.predict.lm.R b/R/inverse.predict.lm.R new file mode 100644 index 0000000..f438d99 --- /dev/null +++ b/R/inverse.predict.lm.R @@ -0,0 +1,40 @@ +# This is an implementation of Equation (8.28) in the Handbook of Chemometrics +# and Qualimetrics, Part A, Massart et al, page 200, validated with Example 8 +# on the same page + +inverse.predict <- function(object, newdata, alpha=0.05) +{ + UseMethod("inverse.predict") +} + +inverse.predict.default <- function(object, newdata, alpha=0.05) +{ + stop("Inverse prediction only implemented for univariate lm objects.") +} + +inverse.predict.lm <- function(object, newdata, alpha=0.05) +{ + if (is.list(newdata)) { + if (!is.null(newdata$y)) + newdata <- newdata$y + else + stop("Newdata list should contain element newdata$y") + } + + if (is.matrix(newdata)) { + Y <- newdata + Ybar <- apply(Y,1,mean) + nrepl <- ncol(Y) + } + else { + Y <- as.vector(newdata) + Ybar <- Y + nrepl <- 1 + } + + if (length(object$coef) > 2) + stop("Inverse prediction not yet implemented for more than one independent variable") + + if (alpha <= 0 | alpha >= 1) + stop("Alpha should be between 0 and 1 (exclusive)") +} -- cgit v1.2.1