Home > Mobile >  Calculating correlation coefficient between two groups
Calculating correlation coefficient between two groups

Time:12-07

A large group were asked which brand of bread they preferred Q, B or D. prQ of the group preferred A. prB of the group preferred B and the rest preferred B.

CodePudding user response:

To calculate the Pearson correlation, start by determining each variable's standard deviation as well as the covariance between them. The correlation coefficient is covariance divided by the product of the two variables' standard deviations.

CodePudding user response:

Here is explanation of what this function does:

  1. The function takes in two variables, pA and pB, which represent the values of the two variables being compared.

  2. The first step in calculating the correlation coefficient is to determine the covariance between pA and pB. This is done by multiplying the negative of pA by pB, resulting in a value of -pA * pB. This negative value indicates that there is a negative relationship between the two variables, meaning that when one variable increases, the other decreases.

  3. Next, the variance for each variable is calculated. The variance is a measure of how much the values of a variable differ from the mean value of the variable. To calculate the variance for pA, the variable is multiplied by one minus the variable, resulting in a value of pA * (1-pA). This is done for pB as well, resulting in a value of (1-pB) * pB.

  4. The final step in calculating the correlation coefficient is to divide the covariance by the product of the square roots of the variances. This is done by dividing covXY by the result of the square root of varX * varY, with an exponent of 2. This results in the correlation coefficient, which is a value between -1 and 1 that indicates the strength and direction of the relationship between the two variables.

  5. Finally, the function returns the calculated correlation coefficient.

  • Related