Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
update Correlation godoc and comments
Browse files Browse the repository at this point in the history
as discussed
  • Loading branch information
jonlawlor committed Nov 15, 2014
1 parent 007b3e0 commit 2ce22f9
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions stat.go
Expand Up @@ -126,7 +126,7 @@ func ChiSquare(obs, exp []float64) float64 {

// Correlation returns the weighted correlation between the samples of x and y
// with the given means.
// sum_i {w_i (x_i - meanX) * (y_i - meanY)} / ((sum_j {w_j} - 1) * stdX * stdY)
// sum_i {w_i (x_i - meanX) * (y_i - meanY)} / (stdX * stdY)
// The lengths of x and y must be equal. If weights is nil then all of the
// weights are 1. If weights is not nil, then len(x) must equal len(weights).
func Correlation(x, y, weights []float64) float64 {
Expand Down Expand Up @@ -163,8 +163,6 @@ func Correlation(x, y, weights []float64) float64 {
sxx -= xcompensation * xcompensation / float64(len(x))
syy -= ycompensation * ycompensation / float64(len(x))

// sum_i { (x_i - meanX) * (y_i - meanY)} / sqrt{\sum_i{ (x_i - \mu_x)^2 } * \sum_i{ ( y_i - \mu_y)^2}}
// with the implicit 1/(N-1) cancelling out.
return (sxy - xcompensation*ycompensation/float64(len(x))) / math.Sqrt(sxx*syy)

}
Expand All @@ -191,8 +189,6 @@ func Correlation(x, y, weights []float64) float64 {
sxx -= xcompensation * xcompensation / sumWeights
syy -= ycompensation * ycompensation / sumWeights

// sum_i {w_i * (x_i - meanX) * (y_i - meanY)} / sqrt{\sum_i{w_i * (x_i - \mu_x)^2 } * \sum_i{w_i *( y_i - \mu_y)^2}}
// with sum_i { w_i } cancelling out.
return (sxy - xcompensation*ycompensation/sumWeights) / math.Sqrt(sxx*syy)
}

Expand Down

0 comments on commit 2ce22f9

Please sign in to comment.