0
$\begingroup$

I'm performing an ordinary least squares regression on a dataset whose predictors are two categorical variables and the dependent variable is continuous.

The resulting model gives me stats like the coefficient and p-value for each value (level) of the categorical variables, except one value is omitted for each variable. After some helpful pointers on my last question, I now realize that's because of the one-hot encoding, and why.

This this answer gives some useful tips on calculating the coefficients of the missing predictors, but I also need the p-values as well.

Details

I'm using statsmodels in Python, so it'd be great if there was a way to do it using that. Here's how I created and fit the model:

model = statsmodels.formula.api.ols('rates ~ C(models) + C(groups)', data=df)
fitted_model = model.fit()

And here's how my data is structured:

Group    Model    Rate 
----------------------
Group A  Model 1  1.3
Group B  Model 7  0.43
Group B  Model 1  0.77
Group G  Model 2  3.2
$\endgroup$
5
  • 2
    $\begingroup$ You need the p-value of what hypothesis test? $\endgroup$ – Dave Sep 23 '20 at 19:03
  • $\begingroup$ ... and once you can tell us that, you may discover this is the same as your first question. $\endgroup$ – whuber Sep 23 '20 at 19:44
  • $\begingroup$ @Dave So I'm using the p-values provided by statsmodels, and my understanding is that's a measure of whether that particular predictor is significantly correlated with the dependent variable. The library's definition is "The two-tailed p values for the t-stats of the params." $\endgroup$ – Nick S Sep 23 '20 at 20:01
  • $\begingroup$ What hypothesis do you want to test? $\endgroup$ – Dave Sep 23 '20 at 20:28
  • $\begingroup$ @Dave I think my null hypothesis is that this particular value of this categorical variable is not predictive of the outcome variable. At least, that's my understanding of the other p-values that statsmodels does give. $\endgroup$ – Nick S Sep 23 '20 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.