9
$\begingroup$

I have been modelling a data set that contains several predictor variables, but after extensive research, I am even more confused as to whether I should be using a lm() or glm() function for the following:

Model4 <-lm(Height_cm ~ Sleep.hours + Gender + Age + Exercise, data=Data.dat.complete)

Where height is continuous, sleep.hours is continuous, gender is male/female, age is continuous and exercise is count (the number of times someone exercised in a week).

As I have a binary variable (gender), my diagnostic plots do not look too good, and I am tempted to use a glm() with family=binomial and link=logit. However, after researching for several hours, I am beginning to question this, as I have seen examples of gender being fitted using just lm() and my other predictors are clearly not binary.

If at all possible, I would like to try and work at least some of this out on my own, but if someone could please point me in the right direction (i.e. where is the flaw in my understanding), it would be very much appreciated.

Thank you.


Diagnostic plots:

enter image description here

$\endgroup$
6
  • 4
    $\begingroup$ Can you please include links to some of your not-good-looking diagnostic plots? The short answer to your question is that the choice of lm vs glm depends on the response variable (Height_cm), not anything having to do with the predictor variables ... $\endgroup$
    – Ben Bolker
    Nov 21, 2021 at 23:05
  • 2
    $\begingroup$ 1. Having a binary variable is a nonissue for a linear model (and is not related in any way to the differences between lm and glm). 2. The plots look just fine to me (maybe a small amount of heteroskedasticity - perhaps - but if present it would be of little consequence). What do you think is wrong with them? Is it the gap on the x-axis in the first plot? That's just a big gender effect. $\endgroup$
    – Glen_b
    Nov 21, 2021 at 23:22
  • 4
    $\begingroup$ You're being badly misled by that unfortunate choice of phrasing. There can be all manner of pattern in the horizontal direction - gaps, skewness, etc. What you're looking for is whether the vertical distribution in thin vertical slices (with more than a few points in a slice) is more or less the same across each section of the x-axis. The average in each slice should stay close to 0, the spread should be more or less constant, and so on. $\endgroup$
    – Glen_b
    Nov 21, 2021 at 23:28
  • 4
    $\begingroup$ It would be a great idea to go back and clarify this with your statistics lecturer - ideally even have them present something about this in class, as I've seen this confusion happen many many many times ... "Reference line should be flat and horizontal", as in the plots below, is a better rubric. $\endgroup$
    – Ben Bolker
    Nov 21, 2021 at 23:28
  • 1
    $\begingroup$ Continuous variables can be negative too. DItto discrete. $\endgroup$
    – Nick Cox
    Nov 22, 2021 at 16:52

1 Answer 1

24
$\begingroup$

A few points:

  • The short (tl;dr) answer to your question is that the choice of linear (lm) vs generalized linear (glm) models depends on the response variable (Height_cm), not on anything having to do with the predictor variables. Since your response is continuous, you definitely should avoid the standard GLMs (Poisson, binomial/logistic) which are meant for count or proportion data.
  • your diagnostic plots don't look that bad to me: no systematic variation in y as a function of x for residual-vs-fitted or scale-location plots; Q-Q plot is approximately a straight line; all residuals have Cook's distance < 0.5 (within innermost contour). . I suspect that the 'badness' you're referring to is the non-uniform distribution of the fitted values (x-axis in fitted-vs-residual and scale-location) plots. This is presumably happening because there is a big effect of gender (the only binary predictor I see in your data set); you can plot(Model4, col = as.numeric(Data.dat.complete$Gender)) to check this.
  • In theory, a positive variable would be better modeled using a log-transformed response or a Gamma GLM, but when the coefficient of variation is low (standard deviation of response variables << mean of variables, say <1/3; the value is on the order of 1/8 here) then the implied probability of a negative response is very small and you probably don't need to worry about it.

You may find the annotated version of the diagnostics from the performance::diagnostics() function useful (I don't agree with all of the design decisions, e.g. the fifth plot showing "normality of residuals" is redundant and less revealing than the Q-Q plot, but overall it's helpful).

enter image description here

$\endgroup$

Your Answer

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