Rweb in Stat 3011 Home Page Stat 3011 Home Page About the Rweb in Stat 3011 Web Pages
R has no simple procedure for doing "large sample" procedures for means. The reason is that when using a computer, you might as well use the "small sample" procedure. Just ignore the n > 30 rule and use the t distribution for all procedures. It will do almost the same thing for large n and be more conservative to boot. Hence, to do things the easy way, go to the small sample section.
If for some reason you want the "large sample" procedure, perhaps to
get the answer in the back of the book for a homework problem, you
can use Rweb as a calculator and for the "normal table look-up" with
Rweb's pnorm
and qnorm
functions. We won't
give a detailed explanation. It's analogous to one-sample procedures;
see the explanation for them.
For this section, we will use the data set for Problem 10.20 in Devore and Peck
http://superior.stat.umn.edu/~charlie/3011/ex1020.dat
Rweb has a function t.test
that does t tests and
confidence intervals.
Type the URL above in the data URL window and submit
t.test(x, y)and Rweb returns, among other things, the 95% confidence interval (-142.9985, 118.9985).
This agrees more or less with the MINITAB output shown in the book. The agreement is not exact, even allowing for rounding, MINITAB must be doing something wrong. Apparently, the difference is that Rweb is using the non-integer degrees of freedom defined by the formula in the box on page 364 in Devore and Peck, which we can calculate using Rweb by
nx <- length(x) ny <- length(y) vx <- var(x) vy <- var(y) df <- (vx + vy)^2 / (vx^2 / (nx - 1) + vy^2 / (ny - 1))getting 13.95066. MINITAB apparently follows the advice given in the book to round down to the nearest integer, which is wrong (even silly) when using a computer! The computer happily handles non-integer degrees of freedom. The Rweb look-up of the t critical value is
- qt(0.025, 13.95066)giving 2.145499. If you round the degrees of freedom down to 13, you get 2.160369. That's apparently what MINITAB used.
You use optional arguments described in the on-line help to get other confidence levels or do other procedures.
For example, you use
t.test(x, y, var.equal=TRUE)136a137,139 to do the so-called "pooled t test, which assumes equal population variances (). Since there is rarely, if ever, any reason to believe this assumption. This procedure should, rarely, if ever, be used. (Never say "never", but if there is a "never" anywhere in statistics, this is it.)
We'll use the same data to illustrate hypothesis tests. In fact Problem 10.20 in Devore and Peck asks for a test of whether there is a "significance difference" in population means, that is, the hypotheses are
t.test(x, y)In the output of this function, you find P = 0.847 for the P-value of the test (nowhere near "statistically significant").
As always, optional arguments described in the on-line help are used to do one-tailed tests or test other hypotheses.
The Rweb function t.test
does this kind of t test and
confidence intervals too.
For this section, we will use the data set for Problem 10.38 in Devore and Peck
http://superior.stat.umn.edu/~charlie/3011/ex1038.dat
Type the URL above in the data URL window and submit
t.test(x, y, paired=TRUE)and Rweb returns, the 95% confidence interval (1.897882, 5.352118) for the difference of population means and the P-value for the two-tailed test of equality of population means, P = 0.001632.
This isn't, however, the question this problem asks. The book actually asks for a test of whether "the mean number of words recalled after 1 hr exceeds the mean recall after 24 hr by more than 3", that is, we want to test the hypotheses
mu
to specify
the hypothesized value of
and the optional argument alternative
to specify which alternative.
So the Rweb code to do this problem is
t.test(x, y, paired=TRUE, mu=3, alternative="greater")which gives P = 0.2102 for the P-value of the test (the one-tailed test of whether = 3), which is nowhere near "statistically significant."
As for the t-test, there is an Rweb function prop.test
that does large sample tests and confidence intervals for proportions.
For this section, we will use the data set for Example 10.12 in Devore and Peck.
For a confidence interval example we will use Example 8.8 in Devore and Peck. The problem data are
statistic | sample 1 | sample 2 |
---|---|---|
x | 463 | 405 |
n | 615 | 585 |
prop.test
function shows that we
want to make the x
and n
arguments vectors,
each being a row of the table above.
Thus the Rweb code is
prop.test(c(463, 405), c(615, 585))Rweb gives both a 95% confidence interval (0.008263403, 0.112812269) for the difference of population proportions and the
-value for the two-tailed test of equality of population proportions
= 0.02269. (The latter agrees with the number given in the book.)