What is correct interpretation of "p" in R(squared) adjusted formula?

I was looking at a regression problem I have, and I'm using the R(squared) metric to assess my model, in addition to other metrics. I'm aware that R(squared) will always increase as the number of features increase/add more features, which I'm also using the R(squared) adjusted metric to account for this change.

Using the following formula, I'm having doubts about the actual value of p.

If I have a number of independent variables (a mix between numerical and categorical), should the value of p be based on the number of variables after processing categorical features or not?

Lets say I have 3 variables: Num_1, Cat_1, Cat_2. And Cat_1 is a binary categorical variable, and Cat_2 has 3 unique values. Would the value of p be 4? Since Cat_2 gets encoded into 2 variables. Or is it 3? Not accounting encoding.

• It's not clear from your description how you're representing your data to the model. How many coefficients are you estimating? If both cat_1 and cat_2 are encoded using 1-hot encoding, then $p = 1 + 2 + 3$. But if cat_1 is binary encoded and cat_2 is dummy-encoded, then $p = 1 + 1 + 2$ (including num_1). If cat_3 has only 3 values, but those values are numerical (e.g. -0.5, 1.2, 101.7), then cat_3 only estimates one coefficient, so cat_3 only counts as 1 for computing $p$.
– Sycorax
Commented Feb 18, 2022 at 15:10
• I think it's dummy-encoded. I was going to mention the dummy variable trap, but did not find necessary as per OP's examples. But, yes, I believe it should be clarified better. Commented Feb 18, 2022 at 15:15