rmsd {statisfactory} | R Documentation |
Root-mean-square deviation (error)
Description
Calculate the root-mean-square deviation (sqrt(mean((x1 - x2)^2))
). If non-constant weights w
are supplied, then the calculation is sqrt(sum(w * (x1 - x2)^2) / sum(w))
. Alternatively, w
can be a function, in which case the returned value is equal to sqrt(mean(w((x1 - x2)^2)))
.
Usage
rmsd(x1, x2, w = NULL, na.rm = FALSE)
Arguments
x1 |
Numeric vector, matrix, or data frame. |
x2 |
Numeric vector the same length as |
w |
Weights or a function defining weights. If |
na.rm |
Logical, if |
Value
Numeric.
Examples
set.seed(123)
# numeric vectors
x1 <- 1:20
x2 <- 1:20 + rnorm(20)
rmsd(x1, x2)
x1[1] <- NA
rmsd(x1, x2)
rmsd(x1, x2, na.rm=TRUE)
# matrices
x1 <- matrix(1:20, ncol=5)
x2 <- matrix(1:20 + rnorm(20), ncol=5)
rmsd(x1, x2)
x1[1, 1] <- NA
rmsd(x1, x2)
rmsd(x1, x2, na.rm=TRUE)
# weights as values
x1 <- matrix(1:20, ncol=5)
x2 <- matrix(1:20 + rnorm(20, 0, 2), ncol=5)
w <- matrix(1:20, ncol=5)
rmsd(x1, x2)
rmsd(x1, x2, w)
# weights as a function
x1 <- matrix(1:20, ncol=5)
x2 <- matrix(20:1, ncol=5)
w <- function(x) 1 - exp(-x)
rmsd(x1, x2)
rmsd(x1, x2, w)