answersLogoWhite

0

Write a java program to compute correlation?

Updated: 8/17/2019
User Avatar

Wiki User

13y ago

Best Answer

public class Correlation {

public static double getPearsonCorrelation(double[] scores1,double[] scores2){

double result = 0;

double sum_sq_x = 0;

double sum_sq_y = 0;

double sum_coproduct = 0;

double mean_x = scores1[0];

double mean_y = scores2[0];

for(int i=2;i<scores1.length+1;i+=1){

double sweep =(double)(i-1)/i;

double delta_x = scores1[i-1]-mean_x;

double delta_y = scores2[i-1]-mean_y;

sum_sq_x += delta_x * delta_x * sweep;

sum_sq_y += delta_y * delta_y * sweep;

sum_coproduct += delta_x * delta_y * sweep;

mean_x += delta_x / i;

mean_y += delta_y / i;

}

double pop_sd_x = Math.sqrt(sum_sq_x/scores1.length);

double pop_sd_y = Math.sqrt(sum_sq_y/scores1.length);

double cov_x_y = sum_coproduct / scores1.length;

result = cov_x_y / (pop_sd_x*pop_sd_y);

return result;

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a java program to compute correlation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can we add website link when we write java program?

yes ,i can add the website link in java program when we write.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


What is javadoc?

write a java program to display "Welcome Java" and list its execution steps.


How write new line program in java?

\n


How do you write a java program for finding multiligual languages?

You can use Java's built-in functions to write a code that will find multilingual languages.


How java is 100 percent Internet based?

It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.


Write a java code to draw a circle inside in an ellipse?

write a program draw circle and ellipse by using oval methods in java


How do you write a java program to find the ad joint of a matrix?

bgfygfrhjyuyhh


How do you write algorithms of java programs?

Write a program that graphically demonstrates the shortest path algorithm


How do you write a program in java that prints 2 to the power of 999?

Fortunately for us, Java can handle arbitrarily-large numbers via the BigInteger class. This will compute and print out the value of 2999 final BigInteger TWO = BigInteger.valueOf(2L); final int exponent = 999; final BigInteger answer = TWO.pow(exponent); System.out.println(answer);


How do you write a java program to find the square root of a number?

You can use the Math.sqrt() method.


Is it possible to write a program in Java and partly in C?

Yes, that's what JNI is good for.