|
R demos
Back to all R demos
Normal linear regression
You can try out the function I used in lectures 18/19 to visualise variation in normal linear regression.
- Download this file: norm.reg.R to your computer, and save it (as norm.reg.R)
- Start up R in the usual way
- In R, using the Source R code command (on the File menu), navigate to the appropriate folder, and select the file norm.reg.R
- The function visualises variation in normal linear regression
- Run the demonstration by typing norm.reg()
- You can control the simulation and display with the mouse and pointer
- If you click in the main part of the figure, the number of trials is increased: the display shows the true regression line (in black) used in generation of the data, the current sample (black dots), the least squares regression line for this current sample (in blue) and regression lines for past samples (in red).
- If you click in the menu:
- You can change the sample size, and start again
- You can vary the spacing of the x's
- You can visually show or hide the x's
- To vary the parameters used in simulating the data, type (e.g.) norm.reg(beta=0) or norm.reg(sigma=0.4).
- If you are interested in seeing how this is all done in R, and perhaps even modifying the actions, you can view the function by simply typing its name (without the () afterwards)
|