Set the language level to Intermediate Student. Procure your linear regression code, and copy it into a file
Lab6.ss. Download the necessary teachpacks from this
page.
Use the following data file to test your work:
discus.txt.
The data gives the gold metal distance for discus throws in the Olympic
Games from 1900 to 1992. The data is strongly linear. The x values
are years since 1900 and the y values are distances in meters.
The first component is a visual tool for linear regression. You will write a function
that, given a dataset, will produce a plot of the data overlaid with the best-fit line as determined by the analysis, as well as the text of the linear equation.
Your visual representation of linear regression analysis must include, at a minimum,
You may break this problem into smaller pieces as you see fit. Here is a skeleton of a possible implementation, which you may use if you like:
[Note: Functions axes and plot-point should be finished by the end of the lab session. To receive full credit, you should also get started on the other helper functions. Turn in all your work at the end of the lab session according to these submission instructions.]
[Note: If you have reached this far, well done! Part 2 will be part of this week's homework, but you can get started on it in the lab.]
Write a function
;; filename->dataset: string -> dataset
to produce a dataset from a file. The input argument to this function will be a string representing the full path to a data file.
Recall that the teachpack cs151-io.ss provides the following function:
;; read-from-file: string -> list
The function read-from-file takes one argument: a string which is the name of a data file. That file is read into a list, token by token. The value that results from a read-from-file is like any other Racket list and is ready to be used as such.
Use read-from-file as the basis for function filename->dataset.[Note: Part 3 will be part of this week's homework.]
Finally, you will put the pieces together into a function
which will consume the names of an input data file and an output data file, respectively, read the data in from the former and save an image to the latter.
The teachpack save-image.ss provides
Its first argument is the image to save, the second is the filename to be saved, and the third is the filetype to save. The save-image teachpack can save images in three formats: png, xbm, and xpm. For this exercise, use 'png for the filetype. The function returns true when the save operation was successful.
For example, assuming some-img is an image, you can say
(save-image some-img "~\Desktop\some-img.png" 'png)
As stated above, your image must include axes, datapoints, the best-fit line, and the text of the linear equation, as follows:
|
If you are somewhat more ambitious, you can enrich the appearance of your image with various features, as in the following illustration:
|
To receive full credit, you should complete functions axes and plot-point of Part 1 and have made a good start on other helper functions of Part 1. This week's homework will include all parts of this lab.
Save all your files and submit all your work according to the submission instructions.
Material designed by Adam Shaw.