All residuals on 0,0 line after linear regression

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? • A perfect fit is unfortunately all too likely to be spurious, as if you fit a separate term for each observation. – Nick Cox Jan 16 '18 at 15:53

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).

• 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? – Celine D Jan 16 '18 at 16:06
• So, your variables should be (a) number of species (b) height. – Nick Cox Jan 16 '18 at 16:11
• indeed those are my variables :) – Celine D Jan 16 '18 at 16:12
• But then my categorical independent variable (height) has a number of levels equal to the number of samples (number of species per height) no? – Celine D Jan 16 '18 at 16:14
• 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. – Nick Cox Jan 16 '18 at 17:08