Lab2: Two-Sample Rank Tests


Getting Started with R

Click on the R icon

If no R icon, go to Start and then All Programs to find R


Let's repeat Example 4.2 Alcohol Intake

Here is the R code

Notice that the W=15 is not the Wilcoxon W, but the Mann-Whitney U!


Example: Let's get the dataset vitcap by sourcing the file:

The help file for the data set is vitcap.pdf

 > source("http://www.rohan.sdsu.edu/~babailey/stat672/vitcap.R") 
To see if you have it,
> vitcap
Let's make some exporatory plots of the data:

> plot(vital.capacity~age, pch=group, data=vitcap)

> boxplot(vital.capacity~group, data=vitcap)

> hist(vitcap$vital.capacity[vitcap$group==1])

> hist(vitcap$vital.capacity[vitcap$group==3])


Part 2: Classical t and F Tests

Let's make 2 datasets,

> x <-  vitcap$vital.capacity[vitcap$group==1]

> y <- vitcap$vital.capacity[vitcap$group==3]

Let's do an F test (just for fun):

> help(var.test)
Let's do a t-test (just for fun)
> help(t.test)
Maybe normality is not such a good assumption?


Part 3: Rank Tests

What about the Wilcoxon Rank Sum Test?


Example: Writing R code and functions

Practice writing R code that can calculate the Uhat statistics for Problem 4.41,
which should be close to -1.348.

How would you make a function?

Make your own function uhat that will make calculate the Uhat statistics from an x and y.

Here is a place to start: ustat.r