aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorranke <ranke@5fad18fb-23f0-0310-ab10-e59a3bee62b4>2006-05-09 15:26:22 +0000
committerranke <ranke@5fad18fb-23f0-0310-ab10-e59a3bee62b4>2006-05-09 15:26:22 +0000
commitdfe21c80737eff2f273f54fa4bc781b4ddf6e5c8 (patch)
treef81188b5ae07c3884099e2e29689420151fdc1e1
parent965af33bfc386b0c96a50c85fbddf98211e266c4 (diff)
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
-rw-r--r--R/inverse.predict.lm.R40
1 files changed, 40 insertions, 0 deletions
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)")
+}

Contact - Imprint