Calculate the linear combination of a matrix
Arguments
- x
numeric matrix
- coeffs
numeric vector of coefficients
- version
1 or 2 (default: 1). Allows for two different versions of calculation both of which should return the same!
Examples
(x <- randomMatrix(c(4, 2)))
#> [,1] [,2]
#> [1,] 6 64
#> [2,] 22 40
#> [3,] 19 65
#> [4,] 2 28
(coeffs <- rnorm(ncol(x)))
#> [1] 0.5777091 0.1181949
# Calculate the linear combination manually
LC1 <- x[, 1] * coeffs[1] + x[, 2] * coeffs[2]
# Caluclate with linearCombination()
LC2 <- linearCombination(x, coeffs)
# The result shoulc be the same!
all.equal(LC1, LC2) # TRUE
#> [1] TRUE