Median polish

Share:

Description

Median polish.

Usage

1
2
## S3 method for class 'matrix'
medianPolish(X, tol=0.01, maxIter=10L, na.rm=NA, ..., .addExtra=TRUE)

Arguments

X

N-times-K matrix

tol

A numeric value greater than zero used as a threshold to identify when the algorithm has converged.

maxIter

Maximum number of iterations.

na.rm

If TRUE (FALSE), NAs are exclude (not exclude). If NA, it is assumed that X contains no NA values.

.addExtra

If TRUE, the name of argument X is returned and the returned structure is assigned a class. This will make the result compatible what medpolish returns.

...

Not used.

Details

The implementation of this method give identical estimates as medpolish, but is about 3-5 times more efficient when there are no NA values.

Value

Returns a named list structure with elements:

overall

The fitted constant term.

row

The fitted row effect.

col

The fitted column effect.

residuals

The residuals.

converged

If TRUE, the algorithm converged, otherwise not.

Author(s)

Henrik Bengtsson

See Also

medpolish.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Deaths from sport parachuting;  from ABC of EDA, p.224:
deaths <- matrix(c(14,15,14, 7,4,7, 8,2,10, 15,9,10, 0,2,0), ncol=3, byrow=TRUE)
rownames(deaths) <- c("1-24", "25-74", "75-199", "200++", "NA")
colnames(deaths) <- 1973:1975

print(deaths)

mp <- medianPolish(deaths)
mp1 <- medpolish(deaths, trace=FALSE)
print(mp)

ff <- c("overall", "row", "col", "residuals")
stopifnot(all.equal(mp[ff], mp1[ff]))

# Validate decomposition:
stopifnot(all.equal(deaths, mp$overall+outer(mp$row,mp$col,"+")+mp$resid))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.