I am looking at whether abundance is related to size. Size is (of course) continuous, however, abundance is recorded on a scale such that

A = 0-10
B = 11-25
C = 26-50
D = 51-100
E = 101-250
F = 251-500
G = 501-1000
H = 1001-2500
I = 2501-5000
J = 5001-10,000

A through Q... 17 levels. I was thinking one possible approach would be to assign each letter a number: either the minimum, maximum, or median (ie A=5, B=18, C=38, D=75.5...).

What are the potential pitfalls -- and as such, would it better to treat this data as categorical?

I have read through this question which provides some thoughts -- but one of the keys of this data set is that the categories are not even -- so treating it as categorical would assume the difference between A and B is the same as the difference between B and C... (which can be rectified by using logarithm - thanks Anonymouse)

Ultimately, I would like to see whether size can be used as a predictor for abundance after taking other environmental factors into consideration. The prediction will also be in a range: Given size X and factors A, B, and C we predict that Abundance Y will fall between Min and Max (which I suppose could span one or more scale points: More than Min D and less than Max F... though the more precise the better).


2 Answers 2


Categorical solution

Treating the values as categorical loses the crucial information about relative sizes. A standard method to overcome this is ordered logistic regression. In effect, this method "knows" that $A\lt B\lt \cdots \lt J\lt \ldots$ and, using observed relationships with regressors (such as size) fits (somewhat arbitrary) values to each category that respect the ordering.

As an illustration, consider 30 (size, abundance category) pairs generated as

size = (1/2, 3/2, 5/2, ..., 59/2)
e ~ normal(0, 1/6)
abundance = 1 + int(10^(4*size + e))

with abundance categorized into intervals [0,10], [11,25], ..., [10001,25000].

Scatterplot of abundance category vs size

Ordered logistic regression produces a probability distribution for each category; the distribution depends on size. From such detailed information you can produce estimated values and intervals around them. Here is a plot of the 10 PDFs estimated from these data (an estimate for category 10 was not possible due to lack of data there):

Probability densities by category

Continuous solution

Why not select a numeric value to represent each category and view the uncertainty about the true abundance within the category as part of the error term?

We can analyze this as a discrete approximation to an idealized re-expression $f$ which converts abundance values $a$ into other values $f(a)$ for which the observational errors are, to a good approximation, symmetrically distributed and of roughly the same expected size regardless of $a$ (a variance-stabilizing transformation).

To simplify the analysis, suppose the categories have been chosen (based on theory or experience) to achieve such a transformation. We may assume then that $f$ re-expresses the category cutpoints $\alpha_i$ as their indexes $i$. The proposal amounts to selecting some "characteristic" value $\beta_i$ within each category $i$ and using $f(\beta_i)$ as the numerical value of abundance whenever the abundance is observed to lie between $\alpha_i$ and $\alpha_{i+1}$. This would be a proxy for the correctly re-expressed value $f(a)$.

Suppose, then, that abundance is observed with error $\varepsilon$, so that the hypothetical datum is actually $a+\varepsilon$ instead of $a$. The error made in coding this as $f(\beta_i)$ is, by definition, the difference $f(\beta_i) - f(a)$, which we can express as a difference of two terms

$$\text{error} = f(a + \varepsilon) - f(a) - \left(f(a + \varepsilon) - f(\beta_i)\right).$$

That first term, $f(a + \varepsilon) - f(a)$, is controlled by $f$ (we can't do anything about $\varepsilon$) and would appear if we did not categorize aboundances. The second term is random--it depends on $\varepsilon$--and evidently is correlated with $\varepsilon$. But we can say something about it: it must lie between $i - f(\beta_i) \lt 0$ and $i+1 - f(\beta_i) \ge 0$. Moreover, if $f$ is doing a good job, the second term might be approximately uniformly distributed. Both considerations suggest choosing $\beta_i$ so that $f(\beta_i)$ lies halfway between $i$ and $i+1$; that is, $\beta_i \approx f^{-1}(i+1/2)$.

These categories in this question form an approximately geometric progression, indicating that $f$ is a slightly distorted version of a logarithm. Therefore, we should consider using the geometric means of the interval endpoints to represent the abundance data.

Ordinary least squares regression (OLS) with this procedure gives a slope of 7.70 (standard error is 1.00) and intercept of 0.70 (standard error is 0.58), instead of a slope of 8.19 (se of 0.97) and intercept of 0.69 (se of 0.56) when regressing log abundances against size. Both exhibit regression to the mean, because theoretical slope should be close to $4 \log(10) \approx 9.21$. The categorical method exhibits a bit more regression to the mean (a smaller slope) due to the added discretization error, as expected.

Regression results

This plot shows the uncategorized abundances along with a fit based on the categorized abundances (using geometric means of the category endpoints as recommended) and a fit based on the abundances themselves. The fits are remarkably close, indicating this method of replacing categories by suitably chosen numerical values works well in the example.

Some care usually is needed in choosing an appropriate "midpoint" $\beta_i$ for the two extreme categories, because often $f$ is not bounded there. (For this example I crudely took the left endpoint of the first category to be $1$ rather than $0$ and the right endpoint of the last category to be $25000$.) One solution is to solve the problem first using data not in either of the extreme categories, then use the fit to estimate appropriate values for those extreme categories, then go back and fit all the data. The p-values will be slightly too good, but overall the fit should be more accurate and less biased.

  • $\begingroup$ +1 excellent answer! I especially like how 2 different options are described along with their justifications. I also gather taking the log of abundance, not size, should be the emphasis, which was my thought as well. One question, in part 1, you state "you can produce estimated values and intervals around them". How does one do this? $\endgroup$ Dec 8, 2011 at 19:40
  • $\begingroup$ Good question, @gung. A crude way, which may be effective, is to treat the categories as interval-valued data and the ordered logit results are providing a (discrete) distribution over those intervals for any given value of the 'size'. The result is an interval-valued distribution, which will have an interval-valued mean and interval-valued confidence limits. $\endgroup$
    – whuber
    Dec 8, 2011 at 20:11
  • 3
    $\begingroup$ @whuber, it would be worth mentioning the software options. I am guessing that you used Stata (if I am trained well enough to Stata graphs and tell them from R and SAS graphs), where this model is fitted with ologit. In R, you can do this with polr in MASS package. $\endgroup$
    – StasK
    Dec 8, 2011 at 21:03
  • 1
    $\begingroup$ You're correct, @Stask. Thanks for the reference to the R solution. (The graphs are all default graphs in Stata 11; only the legend and line styles in the last one were customized because the red-green distinction might otherwise not be apparent to about 3% of all readers.) $\endgroup$
    – whuber
    Dec 8, 2011 at 21:15
  • 2
    $\begingroup$ @StasK rms::lrm and the ordinal (clm) package are also good options. $\endgroup$
    – chl
    Dec 8, 2011 at 22:40

Consider using the logarithm of the size.

  • $\begingroup$ Ha - That answer elicited a partial face palm. True that takes care of the scale issue - but still at hand: to categorize or not, and which number to peg the "value" to. If these questions are irrelevant, I can handle hearing that too. $\endgroup$ Dec 8, 2011 at 14:35
  • 1
    $\begingroup$ Well, you have been putting various issues into one. The data you have seems to make more sense on a logarithmic scale. Whether you want to do binning or not is a separate question, and there I only have another face palm reply for you: depends on your data and on what you want to achieve. Then there is another hidden question: how do I compute the difference between intervals - compute the difference of their means? or the minimal distance (then A to B would be 0, B to C would be 0, but A to C not). etc. $\endgroup$ Dec 8, 2011 at 14:42
  • $\begingroup$ Good points, I have updated my question with more information to address the goals. As for the difference in intervals, I think that is my question - what would be the relative advantages / disadvantages of computing the interval based on difference of means, minimal distance, maximal distance, distance between mins, distance between maxs, etc. Any advice on what sorts of things I need to consider to make this decision (or if it even needs to be considered) would be great. $\endgroup$ Dec 8, 2011 at 15:24
  • $\begingroup$ There are plenty of further options. For example, to eliminate all scale effects, you could try to predict the ranking position instead. Other than that, it is a question of measuring errors. By taking the logarithm, you usually also weight the errors this way. So when the true value is 10000 and the predicted value is 10100 this is much less of than when the predicted value is 1 and the true value is 101. By additionally doing binning and computing the mindist between the bins, you'd even weight small errors with 0. $\endgroup$ Dec 8, 2011 at 15:40

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.