# How to determine if a variable is categorical?

I am looking at the variable vs response plot, and it seems categorical for most observations, but some are not.

Here is a picture of the plot.

Is there a threshold on the amount of "outliers" to determine whether a variable can be categorical?

edit: In the plot, x is the tax rate ($\times 100$) of various regions, and y is the median value of homes in the region.

-
What do you mean? The question doesn't make sense to me. –  Jonathan Christensen Dec 19 '12 at 20:12
@JonathanChristensen I am wondering if I should use the linear model y~x or y~factor(x) given the plot. –  Saber CN Dec 19 '12 at 20:23
y~x, no question. What you're seeing is probably either an artifact of the design or some sort of rounding going on. That's certainly not a categorical variable. –  Jonathan Christensen Dec 19 '12 at 20:30
Those look like numbers (I'd guess perhaps counts, though that distribution is rather odd), rather than categories. Are you asking if they're maybe integer? You could easily check if any in the sample are not integers. (But who knows, maybe they're serial numbers or something, which could be categorical/ordered categorical.) .... but then why are you trying to model with variables if you don't know what they are? –  Glen_b Dec 19 '12 at 20:48
@Glen_b x is the tax rate*100 of various regions, and y is the median value of homes. Because the tax rate is the same for regions within the same city, I thought I might have to categorize it. –  Saber CN Dec 19 '12 at 21:03

Tax rates are not categorical, they are continuous. A tax rate can vary - e.g. the sales tax in New York City is, I believe, 8.825%.

It appears that the data you have only has certain tax rates. But that is a feature of your data, not an underlying characteristic of the variable. Categorical variables CANNOT take values in between other values. For example, "country of birth" is categorical. You were born in some country. It makes no sense to say (e.g.) that the USA is halfway between Norway and Czechoslovakia - it is not even wrong, it's nonsensical.

A separate question is how you should model these data. I think linear regression is a good first attempt, then you should look at plots of the residuals.

-

It certainly looks as if the variable plotted along the X axis can only take certain discrete values.

However ... a categorical variable is one that takes values in a sample space where neither magnitude nor order have any meaning. Example: a medical study might record the gender of the patient (male/female), which is categorical .. the age (which is numeric) ... and which of several possible OTC cold medications they took -- also categorical.

A categorical variable could have infinite support --- imagine sequences of letters from the Latin alphabet -- of arbitrary length. You have an infinite number of possibilities -- all categorical, because there is no natural way to measure the distance between them, or to rank them (although we could come up with a few).

Contrarywise, a numeric variable could admit to a discrete number of possible outcomes -- such as the spectrum of a particular chemical element.

-
(+1) I think there’s some confusion between discrete and categorical. It is dubious here that $X$ is categorical. OP should just explain what $X$ is to get more advides –  Elvis Dec 19 '12 at 20:58
Categorical data can be ordinal –  Peter Flom Dec 19 '12 at 22:13
Can you give an example of categorical ordinal data where we do not assume an underlying continuous distribution? –  Placidia Dec 20 '12 at 1:41
Data that are counts are categorical ordinal data, typically with no assumption of an underlying continuous distribution. Examples abound in many fields, such as the sequence of phases of a substance (solid, liquid, gas) or stages in the development of an insect. –  whuber Dec 20 '12 at 2:23
It's a question of semantics. I tend to view data SPSS style as falling into 3 classes: categorical (where order is not relevant); ordinal and scale. I like your example of stages of development of an insect, by the way. Not sure what you mean by count data being ordinal. A poisson process is count data - but 6 events is double 3 events ... so I would call that scale data -- it's just scale data with support on the Natural numbers. –  Placidia Dec 20 '12 at 2:53