Tutorials › Regression Analysis (Undergraduate) › Cell-Means Coding Without an Intercept

Coding Categorical Predictors · Tutorial 303 of 991

Cell-Means Coding Without an Intercept

Represent category-specific means directly with a no-intercept indicator model, and see how least squares estimates each coefficient.

Beginner 9 min read

What You'll Learn

  • Write a factor-only regression model with one indicator for each category and no intercept.
  • Interpret each coefficient as the fitted mean for its category.
  • Derive the least-squares estimates from the residual sum of squares.
  • Calculate fitted category means from hypothetical observations.
  • Distinguish cell-means coefficients from an intercept and category differences.
  • Recognize when a category-specific coefficient cannot be estimated.

Introduction

A categorical predictor with several levels can be represented in more than one way. In reference-category coding, one category is represented by the intercept and the remaining categories by indicators. In cell-means coding, the model instead uses one indicator for every category and has no intercept. The result is direct: each regression coefficient is the fitted mean for one category.

This is a way to write a factor-only model, not a claim that the categories have a numerical order or that their labels are quantitative. The observations are still grouped by category; the coding simply assigns one coefficient to each group.

The No-Intercept Indicator Model

Suppose each observation belongs to exactly one of \(K\) categories. Let \(y_i\) be the response for observation \(i\), and define \(D_{ij}=1\) if observation \(i\) belongs to category \(j\), and \(D_{ij}=0\) otherwise. The cell-means model is

$$ y_i=\beta_1D_{i1}+\beta_2D_{i2}+\cdots+\beta_KD_{iK}+\epsilon_i,\qquad i=1,\ldots,n. $$

There is no separate constant or intercept term. Because every observation belongs to exactly one category, exactly one of its indicators is 1 and all the others are 0. Thus the model's mean for an observation in category \(j\) is \(\beta_j\). The error \(\epsilon_i\) describes the difference between the observed response and that category's model mean.

Definition: In cell-means coding, a factor with \(K\) observed categories is represented by \(K\) indicator variables and no intercept. The coefficient \(\beta_j\) is the model mean for category \(j\); its least-squares estimate \(\hat{\beta}_j\) is that category's fitted mean.

The corresponding design row has a 1 in the column for the observation's category and 0 in every other category column. For three categories, the rows are \((1,0,0)\), \((0,1,0)\), or \((0,0,1)\). Multiplying any such row by the coefficient vector selects just one coefficient as the fitted value.

Assumptions and What Is Being Estimated

The model describes the response mean using category membership alone. In particular, observations in a category share the same model mean, and no other predictor is included. The least-squares procedure chooses the coefficients to minimize the sum of squared differences between observed and fitted responses. This calculation does not require normally distributed errors.

For the usual regression model used in standard inference, errors are assumed to have mean zero, to be independent across observations, and to have a common variance. Normal errors are additionally assumed when exact small-sample \(t\)- and \(F\)-inference is required. These conditions concern the error structure, not the indicator coding itself. The examples below estimate fitted means, not significance tests, so they do not need a normality assumption.

The coefficients are estimable only for categories represented by observations in the data: a category with no observations has no data-based mean to estimate. In applying the model, also consider whether grouping observations by the factor alone is a useful description of their response means. If relevant systematic differences have been left out, the fitted category means may not answer the scientific question of interest.

Worked Example: Fitted Means for Three Training Formats

Suppose, hypothetically, that six independent learners are assigned to one of three training formats, and their quiz scores are recorded. The scores are 70 and 74 for Format A, 80 and 86 for Format B, and 68 and 72 for Format C. Use a factor-only cell-means model to estimate the fitted score for each format.

The observations are assigned to exactly one of the three formats, so each design row has a 1 in its format's column. All three formats have observations. Assume the six learners' responses are independent for the purpose of this illustrative calculation; normality is not needed to obtain the least-squares estimates.

Write the model as \(y_i=\beta_A D_{iA}+\beta_B D_{iB}+\beta_C D_{iC}+\epsilon_i\), with no intercept. Each category coefficient is estimated by its category mean. For Format A,

$$ \hat{\beta}_A=\frac{70+74}{2}=\frac{144}{2}=72. $$

For Format B and Format C, respectively,

$$ \hat{\beta}_B=\frac{80+86}{2}=\frac{166}{2}=83,\qquad \hat{\beta}_C=\frac{68+72}{2}=\frac{140}{2}=70. $$

Thus the fitted quiz scores are 72 points for Format A, 83 points for Format B, and 70 points for Format C. For a learner in Format B, the indicator row is \((0,1,0)\); multiplying by the coefficient vector gives the fitted value \(0(72)+1(83)+0(70)=83\) points. These are fitted group means, not predictions that every learner in a format will score exactly that value.

Why the Coefficients Are the Category Means

The direct interpretation follows from the least-squares calculation. Let category \(j\) contain \(n_j\) observations, with response values \(y_{1j},\ldots,y_{n_jj}\). Each of those observations has fitted value \(\beta_j\). The residual sum of squares for the whole model can therefore be grouped by category:

$$ SSE(\beta_1,\ldots,\beta_K) =\sum_{j=1}^{K}\sum_{r=1}^{n_j}(y_{rj}-\beta_j)^2. $$

Each \(\beta_j\) appears only in the part of the sum for category \(j\), so minimizing the full sum amounts to minimizing each category's sum separately. Differentiate that part with respect to \(\beta_j\), set the derivative to zero, and solve:

$$ \frac{\partial}{\partial\beta_j}\sum_{r=1}^{n_j}(y_{rj}-\beta_j)^2 =-2\sum_{r=1}^{n_j}(y_{rj}-\beta_j)=0, $$
$$ \sum_{r=1}^{n_j}y_{rj}-n_j\beta_j=0 \quad\Longrightarrow\quad \hat{\beta}_j=\frac{1}{n_j}\sum_{r=1}^{n_j}y_{rj}=\bar{y}_j. $$

This stationary point is a minimum: the second derivative of the category's sum of squares is \(2n_j\), which is positive when the category contains at least one observation. Consequently, for every observed category, the least-squares coefficient is its sample mean. The fitted values within that category are all this mean.

The calculation also explains why unequal category sizes cause no difficulty for estimating the category means. Each coefficient minimizes the squared residuals for its own category. A category with more observations contributes more residuals to the overall sum, but it does not change the formula for any other category's fitted mean.

Worked Example: Unequal Category Sizes

Consider hypothetical measurements of time to complete a task, in minutes. Group A has observations 12, 15, and 15; Group B has observations 10 and 14. The observations are from distinct individuals, each assigned to one group, and both groups have data. Assume independence for the illustrative model. Calculate the no-intercept coefficients and check the residual sums within the groups.

For Group A, the sum is \(12+15+15=42\), and \(n_A=3\). Therefore,

$$ \hat{\beta}_A=\bar{y}_A=\frac{42}{3}=14\text{ minutes}. $$

For Group B, the sum is \(10+14=24\), and \(n_B=2\). Therefore,

$$ \hat{\beta}_B=\bar{y}_B=\frac{24}{2}=12\text{ minutes}. $$

The fitted values are 14 minutes for observations in Group A and 12 minutes for observations in Group B. In Group A, the residuals are \(12-14=-2\), \(15-14=1\), and \(15-14=1\) minutes; they sum to \(0\), and their squared sum is \(4+1+1=6\). In Group B, the residuals are \(10-12=-2\) and \(14-12=2\) minutes; they sum to \(0\), and their squared sum is \(4+4=8\). The total residual sum of squares is \(6+8=14\) square minutes.

Group A has three observations and Group B has two, but the coefficients remain the respective group averages. In particular, the no-intercept coefficients are not automatically weighted averages across all observations; each one describes its own category.

Reading a Coefficient and a Fitted Value

Once the coefficients have been estimated, use the indicator row to obtain a fitted value. An observation in category \(j\) has fitted value \(\hat{y}_i=\hat{\beta}_j\). Its observed response may be above or below that value; the difference \(y_i-\hat{y}_i\) is its residual. A coefficient is therefore a fitted category mean, not an individual response and not a difference from another category.

For instance, if the response is blood pressure measured in mmHg, a coefficient of 122 means a fitted mean of 122 mmHg for the category named by that coefficient. It does not, by itself, mean that the category is 122 mmHg higher than a comparison category. To discuss differences between categories requires comparing their fitted means; the coefficients themselves are on the response scale.

Worked Example: Predicting for a New Observation's Category

Suppose hypothetical measurements of plant height, in centimeters, produce fitted coefficients of \(\hat{\beta}_L=18.5\) cm and \(\hat{\beta}_S=15.0\) cm for plants grown under Light L and Light S. Each condition has observed plants, and the model uses only light condition as a factor. Treat the plants' measurements as independent for this illustrative mean model.

A new plant recorded in condition L has indicator row \((1,0)\). Its fitted value is

$$ \hat{y}=1(18.5)+0(15.0)=18.5\text{ cm}. $$

For a plant in condition S, the row is \((0,1)\), giving \(\hat{y}=0(18.5)+1(15.0)=15.0\) cm. The model gives the same fitted mean to every observation in the same condition, while individual measured heights can differ from that mean. These fitted values describe the modeled groups and do not establish that lighting condition caused any difference.

Why This Coding Matters

Cell-means coding is useful when the main quantities of interest are the fitted means for each category. It gives one coefficient per category, keeps the coefficients in the response's units, and makes a category's fitted value easy to read directly from the model. It can also make a model's output easier to connect to a table of group means.

The absence of an intercept is essential to that interpretation. If a separate intercept were added while retaining every category indicator, the intercept and indicators would not be uniquely identifiable: adding a constant to the intercept and subtracting it from every category coefficient would leave every fitted value unchanged. With no intercept, each category's indicator selects its own coefficient, and the coefficients are separately estimated as long as each category appears in the data.

This is not the same as fitting a numerical predictor with its line constrained to pass through zero. In cell-means coding, the indicators are category-membership variables. Since one and only one is 1 for each observation, each category has its own freely estimated mean; the coding does not impose a scientifically meaningful zero response for any category.

Common Mistakes

  • Calling a coefficient a difference. A no-intercept coefficient is the fitted mean for its category. A difference requires subtracting one category mean from another.
  • Leaving out a category indicator. With no intercept, every modeled category needs its own indicator. Otherwise, observations in the omitted category would have no category coefficient selecting their fitted mean.
  • Adding an intercept while keeping all indicators. That makes the parameters redundant because the indicators sum to 1 for every observation. Use the specified no-intercept model for cell-means coding.
  • Interpreting the fitted mean as every individual's response. The coefficient is the fitted value for the category; observations can differ from it, and their differences are residuals.
  • Using a coefficient for a category with no observations. Its mean is not determined by the data, so that category-specific coefficient cannot be estimated from this model.
Key takeaway: With one indicator per observed category and no intercept, each observation's indicator row selects its category's coefficient. Least squares estimates that coefficient as the sample mean response for that category.

Check Your Understanding

Answer each question using the definitions and calculations in this tutorial.

  1. A factor has four observed categories. How many indicators are used in cell-means coding, and is an intercept included?
  2. A category has responses 6, 8, and 10. What is its fitted coefficient, and what are the residuals for those three observations?
  3. Why does a no-intercept coefficient represent a category mean rather than a difference from another category?
  4. What happens to the fitted value for an observation when its indicator row has a 1 in category C's column and 0 in every other column?
  5. Why can the coefficient for a category with no observations not be estimated from the data?