rStats.js v1.3.0
    Preparing search index...

    Function cov

    • Covariance of two vectors, or covariance matrix of the columns of a matrix (or between the columns of x and y). Equivalent to R's cov().

      Parameters

      Returns number

      cov([1, 2, 3, 4], [2, 4, 5, 9]);       // 3.6666666666666665
      cov([[1, 2], [2, 4], [3, 5], [4, 9]]); // [[1.6666666666666667, 3.6666666666666665], [3.6666666666666665, 8.666666666666666]]
    • Covariance of two vectors, or covariance matrix of the columns of a matrix (or between the columns of x and y). Equivalent to R's cov().

      Parameters

      • x: readonly (readonly number[])[] | Sample
      • Optionaly: readonly (readonly number[])[] | Sample
      • Optionaloptions: CovOptions

      Returns number | number[][]

      cov([1, 2, 3, 4], [2, 4, 5, 9]);       // 3.6666666666666665
      cov([[1, 2], [2, 4], [3, 5], [4, 9]]); // [[1.6666666666666667, 3.6666666666666665], [3.6666666666666665, 8.666666666666666]]