Calculate the linear combination of a matrix
linearCombination(x, coeffs, version = 1)
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! |
#> [,1] [,2] #> [1,] 3 39 #> [2,] 38 53 #> [3,] 56 61 #> [4,] 86 27(coeffs <- rnorm(ncol(x)))#> [1] -0.5532382 1.4051089# 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