Wishlist: allow NA values in medpolish (package 'eda') (PR#2298)

schutz@wehi.edu.au schutz@wehi.edu.au
Sat, 16 Nov 2002 05:44:02 +0100 (MET)


Full_Name: Frederic Schutz
Version: 1.6.1
OS: Linux
Submission from: (NULL) (128.250.252.193)


The subject says everything... This has already been proposed in
June 2001 (cf http://maths.newcastle.edu.au/~rking/R/help/01a/2333.html),
but no reply followed.

I attach the patch that I used on my system to add this feature
(including an updated help page), if it can help. Sorry, the
two "diff..." lines will certainly been wrapped due to the HTML form.

Frederic

diff -ur R-1.6.1.old/src/library/eda/R/medpolish.R
R-1.6.1/src/library/eda/R/medpolish.R
--- R-1.6.1.old/src/library/eda/R/medpolish.R   Mon Jan 31 21:01:52 2000
+++ R-1.6.1/src/library/eda/R/medpolish.R       Sat Nov 16 15:18:07 2002
@@ -1,4 +1,5 @@
-medpolish <- function (x, eps=0.01, maxiter=10, trace.iter = TRUE)
+medpolish <- function (x, eps=0.01, maxiter=10, trace.iter = TRUE,
+                       na.rm = FALSE)
 {
     z <- as.matrix(x)
     nr <- nrow(z)
@@ -8,19 +9,19 @@
     c <- numeric(nc)
     oldsum <- 0
     for(iter in 1:maxiter) {
-       rdelta <- apply(z, 1, median)
+       rdelta <- apply(z, 1, median, na.rm = na.rm)
        z <- z - matrix(rdelta, nr=nr, nc=nc)
        r <- r + rdelta
-       delta <- median(c)
+       delta <- median(c, na.rm = na.rm)
        c <- c - delta
        t <- t + delta
-       cdelta <- apply(z, 2, median)
+       cdelta <- apply(z, 2, median, na.rm = na.rm)
        z <- z - matrix(cdelta, nr=nr, nc=nc, byrow=TRUE)
        c <- c + cdelta
-       delta <- median(r)
+       delta <- median(r, na.rm = na.rm)
        r <- r - delta
        t <- t + delta
-       newsum <- sum(abs(z))
+       newsum <- sum(abs(z), na.rm = na.rm)
        converged <- newsum==0 || abs(1-oldsum/newsum) < eps
         if(converged) break
        oldsum <- newsum
diff -ur R-1.6.1.old/src/library/eda/man/medpolish.Rd
R-1.6.1/src/library/eda/man/medpolish.Rd
--- R-1.6.1.old/src/library/eda/man/medpolish.Rd        Tue Aug 14 07:41:51
2001
+++ R-1.6.1/src/library/eda/man/medpolish.Rd    Sat Nov 16 14:47:24 2002
@@ -7,7 +7,8 @@
   Fits an additive model using Tukey's \emph{median polish} procedure.
 }
 \usage{
-medpolish(x, eps = 0.01, maxiter = 10, trace.iter = TRUE)
+medpolish(x, eps = 0.01, maxiter = 10, trace.iter = TRUE,
+          na.rm = FALSE)
 }
 \arguments{
   \item{x}{a numeric matrix.}
@@ -15,6 +16,7 @@
     see \bold{Details}.}
   \item{maxiter}{the maximum number of iterations}
   \item{trace.iter}{logical. Should progress in convergence be reported?}
+  \item{na.rm}{logical. Should missing values be removed?}
 }
 \details{
   The model fitted is additive (constant + rows + columns). The
@@ -24,6 +26,8 @@
   or until there have been \code{maxiter} iterations.
   The sum of absolute residuals is printed at
   each iteration of the fitting process, if \code{trace.iter} is \code{TRUE}.
+  If \code{na.rm} is \code{FALSE} the presence of any \code{NA} value in
+  \code{x} will cause an error, otherwise \code{NA} values are ignored.
 
   \code{medpolish} returns an object of class \code{medpolish} (see below).
   There are printing and plotting methods for this


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._