What does having "constant variance" in the error term means. As I see it , we have a data with variable and 1 independent variable. This is one assumption of linear regression. I am wondering what this homoscedasticity means. Since if I am having 500 rows I would have single variance value which is obviously constant. With what variable should I compare the variance?
It means that when you plot the individual error against the predicted value, the variance of the error predicted value should be constant. See the red arrows in the picture below, the length of the red lines (a proxy of its variance) are the same.
This is a place where I've found looking at some formulas helps, even for people with some math anxiety (I'm not suggesting that you do, necessarily). The simple linear regression model is this:
It's important to realize that $\sigma^2_\varepsilon$ is not a variable (although in junior high school level algebra, we would call it that). It doesn't vary. $X$ varies. $Y$ varies. The error term, $\varepsilon$, varies randomly; that is, it is a random variable. However, the parameters ($\beta_0,~\beta_1,~\sigma^2_\varepsilon)$ are placeholders for values we don't know--they don't vary. Instead, they are unknown constants. The upshot of this fact for this discussion is that no matter what $X$ is (i.e., what value is plugged in there), $\sigma^2_\varepsilon$ remains the same. In other words, the variance of the errors / residuals is constant. For the sake of contrast (and perhaps greater clarity), consider this model:
The above discussion should help with understanding the nature of the assumption; the question also asks about how to assess the it. There are basically two approaches: formal hypothesis tests and examining plots. Tests for heteroscedasticity can be used if you have experimental-ish data (i.e., that only occur at fixed values of $X$) or an ANOVA. I discuss some such tests here: Why Levene test of equality of variances rather than F-ratio. However, I tend to think looking at plots is best. @Penquin_Knight has done a good job of showing what constant variance looks like by plotting the residuals of a model where homoscedasticity obtains against the fitted values. Heteroscedasticity can also possibly be detected in a plot of the raw data, or in a scale-location (also called spread-level) plot. R conveniently plots the latter for you with a call to
Consider the plots below, which compare how homoscedastic vs. heteroscedastic data might look in these three different types of figures. Note the funnel shape for the upper two heteroscedastic plots, and the upward sloping lowess line in the last one.
For completeness, here is the code that I used to generate these data: