R demos

Back to all R demos
Tests for population mean
You can try out the function I used in lecture 17 to visualise basic ideas of testing hypotheses.
  1. Download this file: test.mean.R to your computer, and save it (as test.mean.R)
  2. Start up R in the usual way
  3. In R, using the Source R code command (on the File menu), navigate to the appropriate folder, and select the file test.mean.R
  4. The function visualises a test for the population mean of a normal distribution with known variance, based on the sample mean, as in section 8.5
  5. Run the demonstration by typing test.mean()
  6. You can control the simulation and display with the mouse and pointer
    • If you click in the main part of the figure, the observed value of the sample mean, or the critical value of the test, respectively, is moved to the x coordinate where you click
    • If you click in the menu:
      • You can switch between the 'p-value' view of the test and the 'critical region' view
      • You can change the sample size
      • You can specify a significance level
      • You can alter the alternative hypothesis
  7. 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)