2
$\begingroup$

I have to perform a Shapiro-Wilk normality test. My dataset is build like this:

Condition0 <- c(0.9201584, 0.8386860, 0.8092635, 0.8166590, 0.8653545)
Condition1 <- c(0.9905397, 0.9498400, 1.0378111, 0.9740314, 1.0355568)
Condition2 <- c(0.9529179, 1.0919274, 1.0089470, 1.0067670, 0.9686904)
Condition3 <- c(0.7402958, 0.7890059, 0.8060471, 0.8020820, 0.7931508)
Condition4 <- c(0.7725662, 0.6916708, 0.7698080, 0.7476060, 0.7602339)
Control <- c(0.7707546, 0.7035131, 0.7268695, 0.8217838, 0.7641010)

dataset <- data.frame(Condition0, Condition1, Condition2, Condition3, Condition4, Control, row.names = c("d1", "d2", "d3", "d4", "d5"))

As you see can there are 6 conditions with 5 results for each condition.

Is it right to do the Shapiro-Wilk test in this way, dividing the dataset for every single condition?

shapiro.test(dataset$Condition0)
shapiro.test(dataset$Condition1)
shapiro.test(dataset$Condition2)
shapiro.test(dataset$Condition3)
shapiro.test(dataset$Condition4)
shapiro.test(dataset$Control)

or, should I built my dataset in a different way and do the test in the whole dataset, regardless of the factor "condition"? Like this:

    my_data <- c(0.9201584, 0.8386860, 0.8092635, 0.8166590, 0.8653545, 
              0.9905397, 0.9498400, 1.0378111, 0.9740314, 1.0355568,
              0.9529179, 1.0919274, 1.0089470, 1.0067670, 0.9686904,
              0.7402958, 0.7890059, 0.8060471, 0.8020820, 0.7931508,
              0.7725662, 0.6916708, 0.7698080, 0.7476060, 0.7602339,
             0.7707546, 0.7035131, 0.7268695, 0.8217838, 0.7641010)
cycle <- rep(c("d1", "d2", "d3", "d4", "d5"), 6)
Condition <- rep(c("Condition0","Condition1", "Condition2", "Condition3", "Condition4", "Control"), each = 5)

dataset2 <- data.frame(my_data, cycle, Condition)

shapiro.test(dataset2$my_data)

After the Shapiro-Wilk test I'll run an ANOVA or a Kruskall-Wallis (depends on the result) to see if there is any difference among different conditions. Like this:

my_lm <- lm(my_data ~ Condition, data= dataset2)
anova(my_lm)

Which one do you think is the correct one? Thank you for the answer!

$\endgroup$
6
  • $\begingroup$ (Although asked in the context of R, this is a statistical question & is on topic here.) $\endgroup$ Commented Oct 24, 2016 at 12:15
  • $\begingroup$ yes, it is on topic. The question is basically: Should I run the Shapiro-Wilk using the entire dataset, or should I divide the dataset based on the different condition and therefore run the Shapiro-Wilk on 6 small datasets? $\endgroup$
    – Wildebeest
    Commented Oct 24, 2016 at 12:23
  • 1
    $\begingroup$ Those are distinctly different tests, so your question can be resolved by considering what it is you want to determine: are you trying to tell whether the collection of all data is consistent with independent draws from a single Normal distribution or do you want to know whether each group looks like independent draws from some Normal distribution, but possibly a different distribution in each group? $\endgroup$
    – whuber
    Commented Oct 24, 2016 at 12:37
  • $\begingroup$ I think that the second description @whuber give is the right one. Since each "Condition" refers to a different treatment, it is important to maintain the groups separate? Does it make sense? $\endgroup$
    – Wildebeest
    Commented Oct 24, 2016 at 15:03
  • $\begingroup$ Where does the compulsion arise ("have to perform a Shapiro Wilk")? Whoever is compelling you to run the test should probably answer this question. Who knows what their reasoning might be? If you were to ask me, I'd say the best choice is to perform it zero times (but to do something else instead, something less likely to lead you to do exactly the wrong thing later), but I'm not the one compelling you to do it -- it's hard to give advice on actions I disagree with absent a good rationale for doing them at all. $\endgroup$
    – Glen_b
    Commented Oct 24, 2016 at 23:09

2 Answers 2

1
$\begingroup$

What matters for ANOVA is the normality of the residuals rather than the raw normality. The Shapiro-Wilk test is only one of the possible ways of checking normality, others including boxplots, plot(resid(model)), and z-scores of skewness and kurtosis, stat.desc(model, norm=T) (with the pastecs package). Never rely on Shapiro alone. In fact, the z-scores are possibly the go-to scores, as they are robust to sample size, and don't require you being terribly experienced with instances of non-normality. The key figures for the z-scores are 'skew.2SE' and 'kurt.2SE', and the scores are expected to lie below 0.96 if the distribution is normal.

Now, if those residuals are non-normal, then consider solutions. Besides non-parametric alternatives to ANOVA, you might try replacing your dependent variable with its transformation, e.g., log(), and then checking the residuals again.

Aside from that, if you want to check the normality of the variables themselves, do it per condition. Personally, I would enter the data in long format, with condition as one column, and then use subsetting, i.e., dataset[dataset$condition=='0',], dataset[dataset$condition=='1',]...

For a more advanced discussion of normality (along the lines of @Glen_b's comments), see this question.

$\endgroup$
0
$\begingroup$

You can use the package rstatix. It "provides a simple and intuitive pipe-friendly framework, coherent with the tidyverse design philosophy, for performing basic statistical tests, including t-test, Wilcoxon test, ANOVA, Kruskal-Wallis and correlation analyses."

I think the package's example can help you apply the same steps for your conditions and control. As follows:

# Shapiro Wilk normality test for one variable
iris %>% shapiro_test(Sepal.Length)
#> # A tibble: 1 x 3
#>   variable     statistic      p
#>   <chr>            <dbl>  <dbl>
#> 1 Sepal.Length     0.976 0.0102

# Shapiro Wilk normality test for two variables
iris %>% shapiro_test(Sepal.Length, Petal.Width)
#> # A tibble: 2 x 3
#>   variable     statistic            p
#>   <chr>            <dbl>        <dbl>
#> 1 Petal.Width      0.902 0.0000000168
#> 2 Sepal.Length     0.976 0.0102      

# Multivariate normality test
mshapiro_test(iris[, 1:3])
#> # A tibble: 1 x 2
#>   statistic p.value
#>       <dbl>   <dbl>
#> 1     0.991   0.443
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.