Introduction to Statistics (MAT/SST 115.03 2008S)

R Notes for Topic 20: Inference for Two-Way Tables


R notes for Activity 20-1: Basketball Scoring

You can load the sample NBA points data with

nba = read.csv("/home/rebelsky/Stats115/Data/NBAPoints.csv")

You will note that there are two columns in the data frame: One for the date in which the game was played and one for the total score that night.

> head(nba)
        Date Points
1 12/10/1999    196
2 12/10/1999    198
3 12/10/1999    205
4 12/10/1999    163
5 12/10/1999    184
6 12/10/1999    224

20-1 c. Visual Displays

It's been awhile, so you may not remember the techniques we use for visual displays of quantitative data. Let's review. You can try

  • a dot plot,
    library(BHH2, lib="/home/rebelsky/Stats115/Packages")
    dotPlot(nba$Points)
    
  • a histogram,
    hist(nba$Points)
    
  • or a normal probability plot.
    qqnorm(nba$Points, datax=T)
    qqline(nba$Points, datax=T)
    

20-1 d. Descriptive Statistics

A quick reminder ...

mean(nba$Points)
sd(nba$Points)

20-1 i. The t-test

You should compute the t-test statistic using the formula on p. 395. Note that you'll need to parenthesize the denominator.

(x_bar - mu_0)/(s/sqrt(n))

20-1 l. Using Technology

After using the applet, you might also just want to have R compute the test statistic and p-value directly from the original data.

t.test(nba$Points, mu=183.2, alternative="greater")

Sometimes you just have the test statistic, and not the original data (or just the mean and standard deviation, and not the original data, in which case you can compute the test statistic). In that case, you can still have R compute the p-value using the pt function. You need to supply the test statistic and the degrees of freedom. As is the case for the standard normal probability table, this gives the area to the left, so you will need to subtract it from 1.

pt(3.13, df=24)

R notes for Activity 20-2: Sleeping Times

We will need two data sets for this activity, a set of sleep times for this class (SleepData.csv) and a set of hypothesized sleep times (HypoSleep.csv). Let's start with our class.

classdata = read.csv("/home/rebelsky/Stats115/Data/SleepData.csv")

So, what does that table look like again?

> head(classdata)
  HoursSlept
1       5.50
2      10.00
3       5.75
4       7.50
5      11.00
6       7.00

Okay, just one column, named HoursSlept. How many values are in that column?

> length(classtimes$HoursSlept)
[1] 31

What about the hypothetical data?

hyposleep = read.csv("/home/rebelsky/Stats115/Data/HypoSleep.csv")

And what are those columns named?

> head(hyposleep)
  Sample1 Sample2 Sample3 Sample4
1     7.5     5.1     6.1     7.7
2     7.4     9.1     7.3     8.4
3     6.8     4.7     6.1     5.6
4     7.3     5.2     6.9     5.0
5     6.1     7.2     6.5     5.9
6     5.4     5.3     5.2     8.9

20-2 a. Exploring Class Data

The authors clearly intend for you to do this test “manually”, first computing the mean and standard deviation, then computing the test statistic, and finally looking up the p-value in the table.

20-2 e. Using Technology

There are two kinds of technology appropriate for filling in the table. You can use the applet. I'll admit that I find that an attractive option, since it shows you the parts of the curve for that proportion.

However, you may find it easier, faster, and more accurate to use R. Minimally, you should know what commands are appropriate. In this case, our alternative is two-sided, so we use a slightly different command.

t.test(hyposleep$Sample1, mu=7, alternative="two.sided")
t.test(hyposleep$Sample2, mu=7, alternative="two.sided")
t.test(hyposleep$Sample3, mu=7, alternative="two.sided")
t.test(hyposleep$Sample4, mu=7, alternative="two.sided")

R notes for Activity 20-3: Golden Ratio

You can read the data with

br = read.csv("/home/rebelsky/Stats115/Data/BeadedRectangles.csv")

R notes for Activity 20-4: Children's Television Viewing

Since you do not have the original data, you cannot use the helpful t.test function. Instead, you will need to compute the test statistic manually and then use pt to find the p-value.

Of course, you can also use the applet.

Creative Commons License

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright (c) 2007-8 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.