Shapiro test for multiple variables

Hi I have a large dataset named "macquarie" that looks like this:

   Date     Year    Local.ID      Capture       Brumation     Gender  PCV TPP 
2  26-Feb-10 2010   B00289        Big Cat Lake  Prebrumation  Female  35   80
4  26-Feb-10 2010   B00292        Big Cat Lake  Prebrumation    Male  40   75 
17  2-Mar-16 2016   960065        Big Cat Lake  Prebrumation    Male  41   65
18  2-Mar-16 2018   B60203        Big Cat Lake  Prebrumation    Male  42   78
20 10-Mar-16 2018   B30259        Big Cat Lake  Prebrumation    Male  35   77

I want to run a shapiro test using multiple variables ie, effect of gender and year on PCV and when I run the code:

macquarie %>% group_by(Gender) %>% shapiro.test(PCV)

I get the following error:

Error in shapiro.test(., PCV) : unused argument (PCV)

Any tips on how to resolve this?

1 answer

  • answered 2021-11-23 02:13 Park

    Try using broom::tidy. In your data, Gender with Female has only one sample, so I just ignore that case.(You need 3~5000 samples to fit shapiro-wilks test)

    library(dplyr)
    library(broom)
    
    df %>% 
      group_by(Gender) %>%
      filter(n() >1) %>%
      do(tidy(shapiro.test(.$PCV)))
    
      Gender statistic p.value method                     
      <chr>      <dbl>   <dbl> <chr>                      
    1 Male       0.854   0.240 Shapiro-Wilk normality test
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum