`mandel.kh`

calculates Mandel's h and k statistics for replicate observations.
These are traditionally used to provide a rapid graphical summary of results
from an inter-laboratory exercise in which each organisation provides replicate
observations of one or more measurands on one or more test items.
Mandel's h is an indication of relative deviation from the mean value; Mandel's
k is an indicator of precision compared to the pooled standard deviation across
all groups.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ```
mandel.kh(x, g = NULL, m = NULL, na.rm = T, rowname = NULL,
type = c("h", "k"), method=c("classical", "robust"), n = NA, ...)
## Default S3 method:
mandel.kh(x, g = NULL, m = NULL, na.rm = T, rowname = NULL,
type = c("h", "k"), method=c("classical", "robust"), n = NA, ...)
## S3 method for class 'data.frame'
mandel.kh(x, g = NULL, m = NULL, na.rm = T, rowname = NULL,
type = c("h", "k"), method=c("classical", "robust"), n = NA, ...)
## S3 method for class 'matrix'
mandel.kh(x, g = NULL, m = NULL, na.rm = T, rowname = NULL,
type = c("h", "k"), method=c("classical", "robust"), n = NA, ...)
## S3 method for class 'array'
mandel.kh(x, g = NULL, m = NULL, na.rm = T, rowname = NULL,
type = c("h", "k"), method=c("classical", "robust"), n = NA, ...)
## S3 method for class 'ilab'
mandel.kh(x, g = NULL, m = NULL, na.rm = T, rowname = NULL,
type = c("h", "k"), method=c("classical", "robust"), n = NA, ...)
``` |

`x` |
An R object (see Details below), which contains replicate observations or,
if |

`g` |
A primary grouping factor, usually corresponding to Laboratory in an
inter-laboratory study. If not present, |

`m` |
A secondary grouping factor, usually corresponding to test item
or measured quantity. |

`na.rm` |
A logical value indicating whether 'NA' values should be
stripped before the computation proceeds. Passed to functions
such as |

`rowname` |
A single character label for the primary grouping factor (e.g. "Lab", "Organisation"). |

`type` |
Character denoting the statistic to be calculated; may be "h" or "k". |

`method` |
Character scalar giving the calculation method. |

`n` |
scalar number of observations per group. Required only if |

`...` |
Additional parameters passed to |

`mandel.kh`

can be called directly, but is usually intended to be called via
convenience functions `mandel.h`

or `mandel.k`

.

`mandel.kh`

is a generic, with methods for numeric vectors, arrays, data
frames, matrices and objects of class `'ilab'`

.

Mandel's statistics are simple indicators of relative deviation or precision for grouped
sets of observations. Given a set of observations *x[i,j,l]* where *i, j, l*
denotes observation *l*, *l=1, 2, ... n* for measurand or test item *j* and group
(usually laboratory) *i*, *i=1, 2, ... p*, Mandel's *h* and *k* are given by:

*h=\frac{\bar{x_{ij}}-\bar{x_j}}{s_j}*

where
* s_j=√{∑_{i=1}^p{\frac{(\bar{x_{ij}}-\bar{x_j})}{p-1}}}*

and

*k=√{\frac{s_{ij}^2}{∑_{i=1}^p{s_{ij}^2/p}}}*

where *s_{ij}* is the standard deviation of values *x_{ijk}* over *k=1, 2, ..., n*.

If `x`

is a vector, one-dimensional array or single-column matrix, values are aggregated
by `g`

and, if present, by `m`

. If `x`

is a data frame or matrix, each column
is aggregated by `g`

and `m`

silently ignored if present. In all cases, if `g`

is `NULL`

or missing, each row (or value, if a vector) in `x`

is taken as a pre-calculated mean (for Mandel's *h*) or standard deviation (for Mandel's *k*).

If `x`

is an object of class `'ilab'`

, `g`

defaults to `'$org'`

and
`m`

to `$measurand`

.

The returned object includes a label (`'grouped.by'`

) for the primary grouping factor.
For the `'ilab'`

method, this is "Organisation". For other methods, If `rowname`

is
non-null, `rowname`

is used. If `rowname`

is NULL, the default is `deparse(substitute(g))`

;
if `g`

is also NULL or missing, "Row" is used.

If `method="robust"`

, Mandel's *h* is replaced by a robust z score calculated by replacing *\bar{x_j}*
and *s_j* with the robust estimates of location and scale obtained using Huber's estimate with tuning constant
`k`

set to 1.5 (or as included in `...`

), and Mandel's *k* is calculated by replacing the
classical pooled standard deviation in the denominator with the robust pooled standard deviation
calculated by algorithm S (see `algS`

).

mandel.kh returns an object of class `"mandel.kh"`

, which is a data frame consisting
of the required Mandel's statistics and in which each row corresponds to a level of `g`

and each column to a level of `m`

or (if `x`

was a matrix or data frame) to the
corresponding column in `x`

. In addition to the class, the object has attributes:

- 'mandel.type'
`"h"`

or`"k"`

- 'grouped.by'
Character scalar giving the label used for the grouping factor

`g`

; see Details above for the defaults.- 'n'
Number of observations per group (

`n`

if specified

S Ellison s.ellison@lgc.co.uk

Accuracy (trueness and precision) of measurement methods and results – Part 2: Basic method for the determination of repeatability and reproducibility of a standard measurement method. ISO, Geneva (1994).

`mandel.h`

, `mandel.k`

for convenience functions;
`pmandelh`

, `pmandelk`

for probabilities, quantiles etc.;
`plot.mandel.kh`

, `barplot.mandel.kh`

for plotting methods.
`algS`

and `hubers`

for robust estimates used when `method="robust"`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ```
data(RMstudy)
#Data frame examples: note no secondary grouping factor
h <- with(RMstudy, mandel.kh(RMstudy[2:9], g=Lab, type="h"))
plot(h, las=2)
k <- with(RMstudy, mandel.kh(RMstudy[2:9], g=Lab, type="k"))
plot(k, las=2)
#Vector variant
RMstk <- stack(RMstudy[,2:9])
names(RMstk) <- c("x", "meas")
#names replace 'values' and 'ind'
RMstk$Lab <- rep(RMstudy$Lab, 8)
h2 <- with(RMstk, mandel.kh(x, g=Lab, m=meas, rowname="Laboratory"))
#Note use of rowname to override g
plot(h2, las=2)
#ilab method
RM.ilab <- with(RMstk, construct.ilab(org=Lab, x=x, measurand=meas,
item=factor(rep("CRM", nrow(RMstk))) ) )
plot(mandel.kh(RM.ilab, type="h"))
#Robust variants
hrob <- with(RMstudy, mandel.kh(RMstudy[2:9], g=Lab, type="h", method="robust"))
plot(hrob, las=2)
krob <- with(RMstudy, mandel.kh(RMstudy[2:9], g=Lab, type="k", method="robust"))
plot(krob, las=2)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.