-1
$\begingroup$

After doing a linear regression with 1 continuous response variable (number) and 1 categorical predictor variable I plotted the residuals and they are all on the 0,0 line. What does this mean and what can possibly cause that?

plotted residuals

$\endgroup$
  • 2
    $\begingroup$ A perfect fit is unfortunately all too likely to be spurious, as if you fit a separate term for each observation. $\endgroup$ – Nick Cox Jan 16 '18 at 15:53
3
$\begingroup$

If your categorical independent variable has a number of levels equal to the number of samples, then you get that.


On further clarifications

So I would probably have to change my dataset? The original dataset had a column with height (continuous) and a column with the species that was found at that height. What I did is categorize the height and then count the number of species that were present in each height-class. I wanted to know if the number of species increases with height. How do I do this then?

Height is by no means a categorical variable and, even if binned, the new binary variables should not be considered independent.

You can still bin height though, but keep it as an ordered categorical variable (in R, that's an "ordered factor") so the intrinsic ordering is maintained.

A more principled approach would be to keep height as it is and model the number of species using a Poisson generalized linear model (GLM, for short).

$\endgroup$
  • $\begingroup$ So I would probably have to change my dataset? The original dataset had a column with height (continuous) and a column with the species that was found at that height. What I did is categorize the height and then count the number of species that were present in each height-class. I wanted to know if the number of species increases with height. How do I do this then? $\endgroup$ – Celine D Jan 16 '18 at 16:06
  • $\begingroup$ So, your variables should be (a) number of species (b) height. $\endgroup$ – Nick Cox Jan 16 '18 at 16:11
  • $\begingroup$ indeed those are my variables :) $\endgroup$ – Celine D Jan 16 '18 at 16:12
  • $\begingroup$ But then my categorical independent variable (height) has a number of levels equal to the number of samples (number of species per height) no? $\endgroup$ – Celine D Jan 16 '18 at 16:14
  • $\begingroup$ I suspect this hinges on precisely what you are doing in your (unstated) software but if height is a measured height it is definitely not categorical and should not be declared as such. But how to do X in software Y is usually off-topic here. More generally, giving an example of your data would be likely to speed up discussion. $\endgroup$ – Nick Cox Jan 16 '18 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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