Re: [R] Shapiro-Wilk for levels of factor
Achim showed you how, but you might want to consider why. If you are trying to learn more about your data, then plots or other strategies may work better than the test. If you are testing for normality in order to meet the assumptions of a test, then the test may not be accomplishing what you think. The assumptions of normality are most important when sample sizes are low, but when sample sizes are low, most normality tests have low power to detect non-normality (I only know of one that has high power in this case, but there are other issues with that one), so a lack of significance does not mean that your routine is safe to use. As sample sizes get larger, the normality tests become more powerful, but the need for normality goes away (CLT). So testing normality to satisfy assumptions is usually meaningless for small sample sizes, and meaningless in a different way for large samples. See fortune(234) and fortune(117). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Ravi Kulkarni Sent: Sunday, February 14, 2010 9:49 AM To: r-help@r-project.org Subject: [R] Shapiro-Wilk for levels of factor Hello, I have data for an ANOVA where the between-subjects factor has three levels. How do I run a test of normality (using shapiro.test) on each of the levels of the factor for the dependent variable separately without creating extra datasets? Thanks, Ravi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Shapiro-Wilk for levels of factor
Hello, I have data for an ANOVA where the between-subjects factor has three levels. How do I run a test of normality (using shapiro.test) on each of the levels of the factor for the dependent variable separately without creating extra datasets? Thanks, Ravi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Shapiro-Wilk for levels of factor
On Sun, 14 Feb 2010, Ravi Kulkarni wrote: Hello, I have data for an ANOVA where the between-subjects factor has three levels. How do I run a test of normality (using shapiro.test) on each of the levels of the factor for the dependent variable separately without creating extra datasets? You can use tapply(y, x, shapiro.test) which will then conduct as many Shapiro-Wilk tests as x has levels (without adjusting for multiple testing). Another approach might be to look at shapiro.test(residualslm(y ~ x))) which tests the null hypothesis that the residuals in all groups come from the same normal distribution. A worked example for the chickwts data is included below. Z ## data summary(chickwts) ## linear model and ANOVA fm - lm(weight ~ feed, data = chickwts) anova(fm) ## QQ plot for residuals + Shapiro-Wilk test shapiro.test(residuals(fm)) ## separate tests for all groups of observations ## (with some formatting) do.call(rbind, with(chickwts, tapply(weight, feed, function(x) unlist(shapiro.test(x)[c(statistic, p.value)] Thanks, Ravi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Shapiro-Wilk for levels of factor
Thanks! Exactly what I wanted. Ravi -- View this message in context: http://n4.nabble.com/Shapiro-Wilk-for-levels-of-factor-tp1555254p1555720.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.