|
R demos
Back to all R demos
Histograms and density functions
You can try out the functions I used in lectures 3 and 4 to compare histograms of two data sets with superimposed density functions.
- Download this file: show.R to your computer, and save it (as show.R)
- Start up R and load stats1.RData 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 show.R
- Run the demonstrations by typing either show.quakes() or show.newcomb()
- In each case the function first displays a histogram and a particular density function (exponential or normal respectively) with the indicated parameters
- You can control the display with the mouse and pointer
- The first click displays a menu at the pointer position
- You can exit the function by clicking near 'stop'
- The 'up', 'down', 'mu+', 'sigma-', etc menu items adjust the parameters in the obvious way
- The 'mom' menu item sets the parameters to the method of moments estimates
- In the case of the show.newcomb() function, the 'drop' menu item deletes the 2 outlying observations, displays the modified histogram and re-displays the current density function; after this, the first click re-establishes the menu
- If you are interested in seeing how this is all done in R, and perhaps even modifying the actions, you can view each function by simply typing its name (without the () afterwards)
|