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.
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()','>",>
The P-values are invisibly returned.
Sample Size for each simulated dataset
Simulation mean for samples
Hypothesized mean for tests
Simulation SD for samples
Hypothesized SD for tests, if blank or missing, use the sample SD in the tests
Simulation proportion for samples
Hypothesized proportion for tests
Which test to use, "z" or "t" tests for normal, "exact" (binomial) or "approx" (normal approximation) for binomial
Direction for alternative hypothesis
alpha level for test (optional)
Number of simulated datasets
Greg Snow, 538280@gmail.com
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.
Murdock, D, Tsai, Y, and Adcock, J (2008) _P-Values are Random Variables_. The American Statistician. (62) 242-245.
t.test
, z.test
,
binom.test
, prop.test
, tkexamp
if(interactive()) {
run.Pvalue.norm.sim()
run.Pvalue.binom.sim()
}
Run the code above in your browser using DataLab