Information Technology Reference
In-Depth Information
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 proba-
bility 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, like this:
>
prop.test(n, x, p, conf.level=0.99)
# 99% confidence level
1.14 Comparing the Means of Two Samples
Problem
You have one sample each from two populations. You want to know if the two popu-
lations could have the same mean.
Solution
Perform a
t
test by calling the
t.test
function:
>
t.test(x, y)
By default,
t.test
assumes that your data is not paired. If the observations are paired
(i.e., if each
x
i
is paired with the corresponding
y
i
), then specify
paired=TRUE
:
>
t.test(x, y, paired=TRUE)