Learn R Programming

TeachingDemos (version 2.13)

put.points.demo: Demonstrate Correlation and Regression by placing and moving data points

Description

Place data points on a graph to demonstrate concepts related to correlation and regression.

Usage

put.points.demo(x = NULL, y = NULL, lsline = TRUE)

Value

This function does not return anything.

Arguments

x

x-coordinates for initial points.

y

y-coordinates for initial points.

lsline

Logical, should the ls regresion line be included.

Author

Greg Snow 538280@gmail.com

Details

The plot area is divided into 2 sections, the left section shows a scatterplot of your points, the right panel controls what happens when you click in the left panel.

The top of the right panel has an "end" button that you click on to end the demonstration.

The middle right panel toggles the least squares line and information.

The bottom right panel has radio buttons that determine what clicking in the left panel will do, the options are to add a point, delete a point, or move a point.

To move a point click on the point you want to move, it will become solid, then click in the place you want it to move to.

When deleting or moving points, the closest point to where you click will be deleted or moved, even if you click in an empty area.

Whenever you add, delete, or move a point the correlation, r^2, and regression line will be updated. You can start with a set of points then demonstrate what happens to the correlation and regression line when outliers are added or important points are moved or deleted.

See Also

Examples

Run this code

if(interactive()){
put.points.demo()

x <- rnorm(25, 5, 1)
y <- x + rnorm(25)
put.points.demo(x,y)
}

Run the code above in your browser using DataLab