# [R] Testing for normality in categorical data

Nancy Felix n@ncy|e||x25 @end|ng |rom gm@||@com
Fri Oct 4 16:09:58 CEST 2019

```Hello
I have data that are categorical both independent variable and dependent as
well having levels more than 3. How can i check the normality of my data?

I have tried the example given of Shapiro-Wilk for levels of factors

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")]))))

But ended up with Error message that x should be numeric and more comments
see below.
Hope to get some help on this

Thanks,
Nancy

## linear model and ANOVA
> fm <- lm(retaliation ~ occupation, data = kazi)
Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z\$residuals) : ‘-’ not meaningful for factors
> anova(fm)
Error in if (ssr < 1e-10 * mss) warning("ANOVA F-tests on an essentially
perfect fit are unreliable") :
missing value where TRUE/FALSE needed
In Ops.factor(object\$residuals, 2) : ‘^’ not meaningful for factors
> ## QQ plot for residuals + Shapiro-Wilk test
> shapiro.test(residuals(fm))
Error in class(y) <- oldClass(x) :
adding class "factor" to an invalid object
> ## separate tests for all groups of observations
> ## (with some formatting)
> do.call("rbind", with(kazi, tapply(retaliation, occupation,
+                                        function(x)
unlist(shapiro.test(x)[c("statistic", "p.value")]))))

[[alternative HTML version deleted]]

```