0

I have the sex ratios (M / M + F) of the offspring of ~35,000 mother birds from >400 species organized in this manner:

IOC_species DamID SR
Acanthis_flammea 3579601 0.333333333
Accipiter_gentilis 3431823 0.333333333
Accipiter_gentilis 3109836 0.4
Accipiter_gentilis 3824842 0.636363636
Accipiter_nisus 542070 0.5
Accipiter_nisus 4006664 0.5
Acridotheres_burmannicus 2207112 1
Acridotheres_burmannicus 947697 0.666666667
Acridotheres_burmannicus 10101 0.833333333
Acridotheres_cristatellus 920019 0.333333333

I want to calculate the median sex ratio per species and then use a statistic to see if this differs significantly from 50/50. My current plan is to use a one-sample sign test in the DescTools package on R. Here is the code I've been using:

library(DescTools)
data <- read.csv(file.choose())
df <- data.frame(Species=data$IOC_species,SR=data$SR)
sumstats = df %>% group_by (Species) %>%
summarise (medianSR = median(SR), signtest = SignTest (SR,mu=.5),.groups='drop'))

When I do this I get the following error message:

Error in `summarise()`:
! Problem while computing `signtest = SignTest(SR, mu = 0.5), .groups =
  "drop")`.
x `signtest` must be a vector, not a `htest` object.
i The error occurred in group 1: Species = "Acanthis_flammea".
Run `rlang::last_error()` to see where the error occurred.

I'm not sure where to go from here - as might be obvious I am fairly new to RStudio. Ideally, I want my answers formatted in a summary table with species names, medians, n's, and sign test p-values. Thanks in advance!

Julia
  • 21
  • 2
  • This has nothing to do with `RStudio` which is a graphical user interface, not R. The error message indicates that the `signtest=` argument in `summarize()` wants a vector, not an `htest` object which is what `SignTest()` returns. Without a reproducible example, it is difficult to be more specific. – dcarlson Jul 14 '22 at 01:41
  • @dcarlson right so my question is how to conduct a sign test on median species values in an ungrouped dataset of individual values. What kind of reproducible example would you need? – Julia Jul 14 '22 at 11:45
  • 1
    Enough sample (or made up) data to generate the error message. +/- 10 observations each from 2 or 3 species. – dcarlson Jul 14 '22 at 13:31
  • Please see this https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example on how to make a reproducible example in R – Andrea M Jul 15 '22 at 09:49

0 Answers0