Pvalue.sim: Simulate P-values

Description Usage Arguments Details Value Note Author(s) References See Also Examples

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

1
2
3
4
5
6
7
8
9
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

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.

Value

The P-values are invisibly returned.

Note

Note: the 2-sided p-values for the binomial may not match the results from binom.test and prop.test. The method used here is an approximation for speed.

Author(s)

Greg Snow, 538280@gmail.com

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

1
2
3
4

Example output



TeachingDemos documentation built on April 14, 2020, 6:26 p.m.