R Cookbook by Teetor Paul

R Cookbook by Teetor Paul

Author:Teetor, Paul [Paul Teetor]
Language: eng
Format: epub
Tags: COMPUTERS / Mathematical & Statistical Software
ISBN: 9781449307264
Publisher: O'Reilly Media
Published: 2011-03-02T16:00:00+00:00


9.12. Forming a Confidence Interval for a Proportion

Problem

You have a sample of values from a population consisting of successes and failures. Based on the sample data, you want to form a confidence interval for the population’s proportion of successes.

Solution

Use the prop.test function. Suppose the sample size is n and the sample contains x successes:

> prop.test(n, x)

The function output includes the confidence interval for p.

Discussion

I subscribe to a stock market newsletter that is well written for the most part but includes a section purporting to identify stocks that are likely to rise. It does this by looking for a certain pattern in the stock price. It recently reported, for example, that a certain stock was following the pattern. It also reported that the stock rose six times after the last nine times that pattern occurred. The writers concluded that the probability of the stock rising again was therefore 6/9 or 66.7%.

Using prop.test, we can obtain the confidence interval for the true proportion of times the stock rises after the pattern. Here, the number of observations is n = 9 and the number of successes is x = 6. The output shows a confidence interval of (0.309, 0.910) at the 95% confidence level:

> prop.test(6, 9) 1-sample proportions test with continuity correction data: 6 out of 9, null probability 0.5 X-squared = 0.4444, df = 1, p-value = 0.505 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.3091761 0.9095817 sample estimates: p 0.6666667

The writers are pretty foolish to say the probability of rising is 66.7%. They could be leading their readers into a very bad bet.

By default, prop.test calculates a confidence interval at the 95% confidence level. Use the conf.level argument for other confidence levels:

> prop.test(n, x, p, conf.level=0.99) # 99% confidence level



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.