Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 2: Correlation Coefficient (10pt) In data analysis, the correlation coefficient is commonly used as a measure of the linear correlation between two variables X

image text in transcribed

Exercise 2: Correlation Coefficient (10pt) In data analysis, the correlation coefficient is commonly used as a measure of the linear correlation between two variables X and Y. It has a value between +1 and -1, where 1 is total positive linear correlation, O is no linear correlation, and -1 is total negative linear correlation. Suppose we observe the prices of a certain item sold in a grocery store in the last four months, along with the monthly sales volume of this item. The data are: x2 = 29.99 Prices: x1 = 19.99 x3 = 14.45 x4 = 24.88 y3 = 402 y2 = 180 Sales: y1 = 300 y4 = 226 We want to find out the correlation coefficient between price (X) and sales quantity (Y). We can thus use the following formula to calculate the correlation coefficient r: E[(xi x)(yi y)] . JE-1(Xi x) E,Vi 9) where i and are the mean such that E=1Xi 1. 3 Now write a simple Java program to compute the correlation coefficients for the hypothetical data we have, {x1, X2, X3, X4; Y1, Y2, Y3, y4}. Save the file as Hw2 Ex2.java. You may follow the steps below: 1) Define variables x1, x2, x3, x4, y1, y2, y3, y4, and assign the corresponding values; Calculate the averages, and 2) 3) Calculate the correlation coefficient using the formula provided above Display the value of the correlation coefficient. Only display 4 digits after the decimal point. 4) (Hint: use printf) Hint: Your output should look like the following: . Command Prompt C: \test>javac Hw2_Ex2.java C:\test>java Hw2_Ex2 Correlation Coefficient: -0.9888 C: \test> 2 Note: Your program doesn't need to read in data from user input. Simply use the four data points provided above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Explain the statement: Religion is only one kind of worldview.

Answered: 1 week ago