Learn R Programming

TeachingDemos (version 2.7)

Pvalue.norm.sim: Simulate P-values

Description

Simulate and plot p-values from a normal or binomial based test under various conditions. When all the assumptions are true, the p-values should follow an approximate uniform distribution. These functions show that along with how violating the assumptions changes the distribution of the p-values.

Usage

Pvalue.norm.sim(n = 50, mu = 0, mu0 = 0, sigma = 1, sigma0 = sigma,
     test= c("z", "t"), alternative = c("two.sided", "less", "greater", "<>",
           "!=", "<", "="">"), alpha = 0.05, B = 10000)
Pvalue.binom.sim(n=100, p=0.5, p0=0.5, test=c('exact','approx'),
                            alternative=c('two.sided', 'less', 'greater',
                            '<>','!=','<','>'),
                            alpha=0.05, B=1000)
run.Pvalue.norm.sim()
run.Pvalue.binom.sim()

Arguments

n
Sample Size for each simulated dataset
mu
Simulation mean for samples
mu0
Hypothesized mean for tests
sigma
Simulation SD for samples
sigma0
Hypothesized SD for tests, if blank or missing, use the sample SD in the tests
p
Simulation proportion for samples
p0
Hypothesized proportion for tests
test
Which test to use, "z" or "t" tests for normal, "exact" (binomial) or "approx" (normal approximation) for binomial
alternative
Direction for alternative hypothesis
alpha
alpha level for test (optional)
B
Number of simulated datasets

Value

  • The P-values are invisibly returned.

Details

These functions generate B samples from either a normal or binomial distribution, then compute the P-values for the test of significance on each sample and plot the P-values. The run.Pvalue.norm.sim and run.Pvalue.binom.sim functions are GUI wrappers for the other 2 functions allowing you to change the parameters and click on "refresh" to run a new set of simulations. Using NA for sigma0 will result in the sample standard deviations being used (leave blank in the GUI). When the simulation conditions and the hypothesized values match, the distributions of the p-values will be approximately uniform. Changing the parameter of interest will show the idea of power. Changing the other parameters can show the effects of assumptions not being met.

References

Murdock, D, Tsai, Y, and Adcock, J (2008) _P-Values are Random Variables_. The American Statistician. (62) 242-245.

See Also

t.test, z.test, binom.test, prop.test, tkexamp

Examples

Run this code
if(interactive()) {
  run.Pvalue.norm.sim()
  run.Pvalue.binom.sim()
}

Run the code above in your browser using DataLab