R demos

Back to all R demos
Least squares and linear regression
You can try out the functions I used in lectures 8 and 9 to visualise linear (and quadratic) regression fitted by least squares to small data sets entered using the mouse.
  1. Download this file: regression.R to your computer, and save it (as regression.R)
  2. Start up R
  3. In R, using the Source R code command (on the File menu), navigate to the appropriate folder, and select the file regression.R
  4. Run the demonstration by typing regression()
  5. You can exit the function by clicking with the mouse below the horizontal axis of the plot.
  6. Use the mouse to choose the position of the menu
  7. Subsequent clicks add a data point at the pointer location, and display the least squares linear regression line (as soon as there are enough points for this to be defined)
    • To delete a data point, click 'delete' on the menu, then click near the point to be deleted.
    • To switch to quadratic regression, click on 'quadratic'
    • To switch back to linear regression, click on 'linear'
    • To stop, click on 'stop'