I have data where my x is a categorical variable that I have used dummy variables for (I have 4 categories as my dependent variable) and my y is a continuous variable (height).

Edit: the independent variable is the number of ribosomes (however these are losely grouped, so one group might have 11+ ribosomes), and the dependent variable is the height of a peak the sample generates on my software when I run the sample

I want to see if there is a significant difference between the heights of each group. I did an advanced stats course and they said a Mann-Whitney is outdated (this is what my colleagues use to analyse this kind of data) and that I should do a linear model or generalized linear model.

I have done a linear model and my residuals vs fitted plot shows that my residuals are non-normal.

enter image description here

I have tried transforming the data using $1/y, \ln y, \log y, \sqrt y$ and I've done a Box Cox transformation which all result in very similar residuals vs fitted plots to the one above so do not help.

I thought a generalised linear model would be the next step but I can't do poisson/negative binomial as my y is non-integer, and Gaussian and Gamma GLMs don't solve my issue either.

I'm not sure if it's because I have 4 different categories, all with separate heights and that's what the residual plots is showing? So how would I overcome that?

This is the residuals vs fitted for the gamma glm with link=log

enter image description here


1 Answer 1


The scale location plot demonstrates that you have a non-constant variance problem (heteroscedasticity); the spread (scale) of points on the linear predictor (mean or location) is increasing. The issue is that you have more variance in heights across the groups.

Height is a positive continuous variable, so I would have though that a Gamma GLM with a log link would be a reasonable starting point. (You don't explain why the Gamma GLM didn't work for you, so perhaps you can add to your question outputs from the Gamma GLM?)

With the Gamma GLM in R you have to specify the log link (for your case) because the default (canonical) link is the inverse link function which is less-widely useful than the log link.

glm(y ~ f, data = my_data, family = Gamma(link = 'log'))
  • $\begingroup$ Hi Thank you so much for your comment, I've added my residuals v/s fitted for the Gamma GLM with link =log like in the code you gave. I'm not sure if it may be because I have done dummy variables for my x variable as they are categorical. So I've automatically generated them in R. I don't know if I am essentially trying to compare 4 different distributions (4 categorical variables, i.e groups as dependent) and that's why these 4 groups are showing up constantly on the residuals vs fitted $\endgroup$
    – anro3
    Commented Jan 21, 2021 at 15:45
  • $\begingroup$ The scale-location plot would have been better; f in my example is a factor; you should code your categorical variable as a factor and let R take care of creating the appropriate contrasts $\endgroup$ Commented Jan 21, 2021 at 15:54
  • $\begingroup$ I tried just doing it as a factor by data$Number<-as.factor(data$Number) is that what you mean? I get exactly the same result with that $\endgroup$
    – anro3
    Commented Jan 21, 2021 at 15:56
  • $\begingroup$ If you found this answer helpful, then please consider upvoting and/or accepting it. $\endgroup$ Commented Oct 9, 2021 at 14:09

Your Answer

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