Calculates the relative difference, defined as
$$\frac{\vert x - y \vert}{x} $$
between two arrays or data frames, where x
are considered reference values.
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.
Examples
# 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)
#> [,1] [,2]
#> [1,] 0 0.01
#> [2,] 0 0.11
rel_diff(m1, m2)
#> [,1] [,2]
#> [1,] 0 1
#> [2,] 0 11
# 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))
#> mb bh bl nh
#> (Intercept) 0.01446592 0.08977463 0.04729215 0.08496078
#> epoch.L 3.46042186 -0.59951299 -3.48922244 3.87957519
#> epoch.Q -20.74713900 -3.30993862 -51.99508454 125.92364818
#> epoch.C -25.78059257 -1.43305167 4.19962200 -0.62550036
#> epoch^4 85.33424274 9.19478314 -15.44695305 -49.00471013