This is the data that is a file named cricket.txt 20 88.6 16 71.6 19.8 93.3 18.4
ID: 3566243 • Letter: T
Question
This is the data that is a file named cricket.txt
20 88.6
16 71.6
19.8 93.3
18.4 84.3
17.1 80.6
15.5 75.2
14.7 69.7
17.1 82
15.4 69.4
16.2 83.3
15 79.6
17.2 82.6
16 80.6
17 83.5
14.4 76.3
Part 1: Read the data from the file and store it in two arrays, one for the chirp frequency and another for the temperature. Use the method StdDraw.point(x, y) from the library stdlib.jar (used in previous labs) to draw a scatter plot of the data. Before you plot the points you will need to set the size of the plot and the pen size. To set the size of the plot you need to call the methods StdDraw.setXscale(minX, maxX) and StdDraw.setYscale(minY, maxY) where minX, maxX, minY, and maxY are the minimum and maximum of the chirp frequency and the temperature respectively (You need to calculate this from your data.) To set the pen size use StdDraw.setPenRadius(0.01);
Note: You should write few methods to accomplish this namely a method to read into the arrays, method for finding the min of an array, method for finding the maximum of an array, and a method for drawing the scatter plots.
Part 2: Now that you have a scatter plot of the data we can use linear regression to fit a line in this dataset. A simple linear regression is a very useful technique for fitting a straight line.
A straight line can be defined by the formula: y = ax +b
Where a is the slope, and b is the intercept with the y
This is the data that is a file named cricket.txt 20 88.6 16 71.6 19.8 93.3 18.4 84.3 17.1 80.6 15.5 75.2 14.7 69.7 17.1 82 15.4 69.4 16.2 83.3 15 79.6 17.2 82.6 16 80.6 17 83.5 14.4 76.3 Part 1: Read the data from the file and store it in two arrays, one for the chirp frequency and another for the temperature. Use the method StdDraw.point(x, y) from the library stdlib.jar (used in previous labs) to draw a scatter plot of the data. Before you plot the points you will need to set the size of the plot and the pen size. To set the size of the plot you need to call the methods StdDraw.setXscale(minX, maxX) and StdDraw.setYscale(minY, maxY) where minX, maxX, minY, and maxY are the minimum and maximum of the chirp frequency and the temperature respectively (You need to calculate this from your data.) To set the pen size use StdDraw.setPenRadius(0.01); Note: You should write few methods to accomplish this namely a method to read into the arrays, method for finding the min of an array, method for finding the maximum of an array, and a method for drawing the scatter plots. Part 2: Now that you have a scatter plot of the data we can use linear regression to fit a line in this dataset. A simple linear regression is a very useful technique for fitting a straight line. A straight line can be defined by the formula: y = ax +b Where a is the slope, and b is the intercept with the y??? axis. For this assignment x is the chirp frequency and y is the temperature. We need to find the coefficients a and b. To accomplish this, as previously mentioned, we will use simple linear regression. The coefficient a can be calculated using the formula: a=correlation(x,y)sd(y)sd(x) and the coefficient b can be calculated as: b= y-ax where x and y denote the mean of x and y respectively. The sample standard deviation of a variable x, sd(x), can be calculated using the formula: sd(x)= 1N-1i=1N(xi-x)2 where N is the number of samples (i.e. points) for the variable. In this assignment the number of samples is 15 (use a final variable!). The correlation of two variables x and y (correlation(x, y)) can be calculated using the formula: Correlation (x, y) = (sigma^Ni=1 xiyi) - nx y/(n - 1)sd(x)sd(y) Write methods for calculating the slope and the intercept of a line using the formulas above. You should write additional methods to simplify the design. This will also simplify your code. Calculate the slope and the intercept for the cricket data set. Display the formula in the format a??y =ax+ba??. Plot the line using the method drawLine:Explanation / Answer
contact on timacs12@gmail.com
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.