0

So these are the survey results. I have tried to do pairwise testing (pairwise.wilcox.test) for these results collected in Spring and Autumn for these sites. But I can't get a specific P -value as to which site has the most influence.

This is the error message I keep getting. My dataset isn't even, ie there were some of the sites that were not surveyed in Spring which I think may be the issue.

Error in wilcox.test.default(xi, xj, paired = paired, ...) : 'x' must be numeric

So I'm not sure if I have laid it out in the table wrong to see how much site influences the results between Spring and Autumn

Site      Autumn    Spring
Stokes Bay  25  6
Stokes Bay  54  6
Stokes Bay  31  0
Gosport Wall    213 16
Gosport Wall    24  19
Gosport Wall    54  60
No Mans Land    76  25
No Mans Land    66  68
No Mans Land    229 103
Osbourne 1  77  
Osbourne 1  92  
Osbourne 1  92  
Osbourne 2  114 33
Osbourne 2  217 114
Osbourne 2  117 64
Osbourne 3  204 131
Osbourne 3  165 85
Osbourne 3  150 81
Osbourne 4  124 15
Osbourne 4  79  64
Osbourne 4  176 65
Ryde Roads  217 165
Ryde Roads  182 63
Ryde Roads  112 53
Ryde Sands  386 44
Ryde Sands  375 25
Ryde Sands  147 45
Spit Bank   223 23
Spit Bank   78  29
Spit Bank   60  15
St Helen's 1    247 11
St Helen's 1    126 36
St Helen's 1    107 20
St Helen's 2    108 115
St Helen's 2    223 25
St Helen's 2    126 30
Sturbridge  58  43
Sturbridge  107 34
Sturbridge  156 0
Osbourne Deep 1 76  59
Osbourne Deep 1 64  52
Osbourne Deep 1 77  30
Osbourne Deep 2 153 60
Osbourne Deep 2 106 88
Osbourne Deep 2 74  35
Sturbridge Shoal    169 45
Sturbridge Shoal    19  84
Sturbridge Shoal    81  44
Mother's Bank   208 
Mother's Bank   119 
Mother's Bank   153 
Ryde Middle 16  
Ryde Middle 36  
Ryde Middle 36  
Stanswood   14  132
Stanswood   47  87
Stanswood   14  88

This is what I've done so far:

MWU <- read.csv(file.choose(), header = T)

#attach file to workspace
attach(MWU)

#Read column names of the data 
colnames(MWU) # Site, Autumn, Spring
MWU.1 <- MWU[c(1,2,3)] #It included blank columns in the df
kruskal.test(MWU.1$Autumn ~ MWU.1$Site) 

#Kruskal-Wallis rank sum test

#data:  MWU.1$Autumn by MWU.1$Site
#Kruskal-Wallis chi-squared = 36.706, df = 24, p-value = 0.0468

kruskal.test(MWU.1$Spring ~ MWU.1$Site)

#Kruskal-Wallis rank sum test

#data:  MWU.1$Spring by MWU.1$Site
#Kruskal-Wallis chi-squared = 35.134, df = 21, p-value = 0.02729

wilcox.test(MWU.1$Autumn, MWU.1$Spring, paired = T)

#Wilcoxon signed rank exact test

#data:  MWU.1$Autumn and MWU.1$Spring**
#V = 1066, p-value = 8.127e-08**
#alternative hypothesis: true location shift is not equal to 0******

#Tried this version too to see if it would give a summary of where the influence is.
pairwise.wilcox.test(MWU.1$Spring, MWU.1$Autumn)
#Error in wilcox.test.default(xi, xj, paired = paired, ...) : not enough (non-missing) 'x' observations
Robert Hacken
  • 3,878
  • 1
  • 13
  • 15
Liblob
  • 1
  • 1
  • 1
    First, don't use `attach()`. But that's not the problem - the problem is that something has gone wrong when the CSV file is read into R. `'x' must be numeric` means that something you thought was a numeric variable is not. Try `str(MWU)` to see the column types. – neilfws Feb 15 '23 at 11:05
  • Hi @neilfws - I've tried it again using your suggestions; str(MWU) gives me Site (chr), Autumn & Spring as (int) which seems right? I've run through it again and I get 'Error in wilcox.test.default(xi, xj, paired = paired, ...) : not enough (non-missing) 'x' observations' – Liblob Feb 15 '23 at 12:23
  • @Liblob `pairwise.wilcox.test` takes a response and a grouping variable as its first two arguments. The way you use it, it treats Autumn as a grouping variable, which leads to the error since autumn values are mostly unique so there will be many small groups (mostly of size 1), some of them containing NA only. I don't think it is actually able to do what you want it to, i.e. quantify the differences (between sites) in differences (between autumn and spring). – Robert Hacken Feb 15 '23 at 13:58
  • @RobertHacken Thank you for your response - I shall go back to the drawing board and see if I can fix the data :-) – Liblob Feb 15 '23 at 14:35

0 Answers0