[R-sig-eco] (no subject)

Kerstin Kober KKober at gmx.de
Mon Oct 17 15:33:18 CEST 2011


Hi,
This is a question from an R-newby! 
I’ve got a very extensive data set and will need to run a large number of Mann-Whitney U tests (in R: wilcox.test) between several sets of data. I am trying to automate this as far as possible so I won’t need to run each test one by one. I asked already somebody for help which provided a short piece of code which enables me to run several tests one after another. However, I will need to re-adjust this code as there are missing values and it stops every time it encounters this.


The data (I’ve attached a small file with some example data, so you can have an idea how it looks like and run code on it):
We’ve got bird density data from various locations, collected over the course of several years. One location (“0”) is our control, which is supposed to be tested against each of the other locations (“1” – “3”). We would like to run this test only on data collected during the same year, so we would test “0” vs “1” in 1980, “0” vs “1” in 1981 etc.

This is the code I’ve got so far and which works fine as long as there exists data from all years in all locations:

for(i in 1980:1983){
    for(j in 1:3){ 
        tmp<- d[d$year == i & d$hotspot %in% c(0, j), ]
        print(c(i, j))
        print(wilcox.test(densities~factor(hotspot), data= tmp))
    }
}

Now, the problem is, that I don’t have data from all years in all locations: during some years some locations are missing and some years are missing entirely.

I tried to find my way through the R help files, but because I am not quite sure where exactly I would need to insert information about the dealing with missing values (is the problem with the for-loop or in the wilcox.test, possibly in both???), I am not entirely sure how to do this.

If anybody has an idea how to do this, please let me know.
Thank you very much for your help!!!

Kerstin

-- 
Dr. Kerstin Kober
Joint Nature Conservation Committee
7 Thistle Place
Aberdeen
AB10 1UZ
United Kingdom

e-mail: kerstin.kober at jncc.gov.uk





More information about the R-sig-ecology mailing list