rmsd: Root-mean-square deviation (error)

rmsdR 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 x1, or a matrix or data frame the same dimensions as x1.

w

Weights or a function defining weights. If x1 and x2 are vectors, this can be a numeric vector the same length as x1 or x2. If x1 and x2 are matrices or data frames then this can be either a matrix or data frame with the same dimensions as x1 and x2. Alternatively, this can be a function to define weights. The function will be applied to each value of (x1 - x2)^2. The default value of NULL assigns each pair of values in x1 and x2 equal weight.

na.rm

Logical, if TRUE then remove any elements in x1 and x2 where either x1 or x2 is NA. Default is FALSE, in which case any NA returns NA.

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)


adamlilith/statisfactory documentation built on Jan. 3, 2024, 10:37 p.m.