Learn R Programming

heplots (version 1.7.8)

rel_diff: Relative Difference between two Arrays or Data Frames

Description

Calculates the relative difference, defined as $$\frac{\vert x - y \vert}{x} $$ between two arrays or data frames, where x are considered reference values.

Usage

rel_diff(x, y, pct = TRUE, epsilon = 10 * .Machine$double.eps)

Value

An array or data frame the same size as x and y containing the relative differences

Arguments

x

An array or data frame, considered the reference values

y

Comparison array or data frame

pct

Logical; if TRUE the relative differences are multiplied by 100, giving values in percent difference from x.

epsilon

Threshold for values near zero

Details

Beyond the obvious, a natural use case is to compare coefficients for alternative models for the same data, e.g., a classical and a robust model.

See Also

link{robmlm}

Examples

Run this code
# simple example
m1 <- cbind(c(0,1), c(1,1))
m2 <- cbind(c(0,1), c(1.01,1.11))
rel_diff(m1, m2, pct = FALSE) 
rel_diff(m1, m2) 

# compare coefficients
data(Skulls)

# fit manova model, classically and robustly
sk.mlm <- lm(cbind(mb, bh, bl, nh) ~ epoch, data=Skulls)
sk.rlm <- robmlm(cbind(mb, bh, bl, nh) ~ epoch, data=Skulls)
rel_diff(coef(sk.mlm),
         coef(sk.rlm))

Run the code above in your browser using DataLab