You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add beta coefficients (coefficients for standardized data) as a post-estimation results method.
API: return similar to t_test with params table, summary, summary_frame
Most likely this can internally reuse t_test, we just need the linear transformation matrix to standardize.
Alternative would be similar to transformation in models, e.g. fit_constrained and returning a results instance.
Applies to linear model, but I never looked at the interpretation in GLM, discrete. So, I'm not sure whether it would be helpful to add in base instead of regression.
Issue #1131 discusses transformation to improve estimation but here it is just a post-estimation diagnostic.
I wrote this function already a long time ago, but never committed it anywhere. If the design in not orthogonal, then the beta coefficients are not a variance decomposition. I read some papers for importance statistics in that case, but those didn't look very popular.
related topic: SAS has a large number of extra statistics and diagnostics for the linear model.
WLS (GLM IRLS related) should we use plain variance or weighted variance.
models that are not linear homogenous (scale of exog matters), e.g. penalized estimators: as diagnostic we don't rescale the penalization. E,g, estimator/penalization is on original scale, but beta coefficients are standardized post-estimation.
(For penalization we also have the opposite case, we keep the parameters on the original scale, but adjust penalization for the variance of exog. I.e. penalize at standardized coefficients but report original coefficients.)
In those cases we don't have equivalence between results after standardizing endog and exog and the post-estimation beta coefficients, and cannot use that property in unit tests.
just a thought "eform" with/as standardized coefficients?
multiplier in exp mean function or oddsration in logit mean function are normalized for the interpretation of the response, but still depend on the exog scale.
e.g. standardize/rescale only the exog
"odds_ratio for one standard deviation change in explanatory variables"?
There is no need to reestimate the model, (although in corner cases standardizing the exog can improve numerical stability of the computations)
We can just transform the estimated params by the standard deviation of the exog. results.t_test(transformation) computes the parameter table for the linearly transformed variables.
AFAIR, the following should produce the beta coefficients and corresponding inferential statistics.
Compute standard deviation, but set it to 1 for the constant.
std = model.exog.std()
std[0] = 1
Then use results.t_test and look at the params_table. np.diag(std) creates a diagonal matrix that transforms the params.
tt = results.t_test(np.diag(std))
print(tt.summary()
tt.summary_frame()
using std on all exog includes the constant
If we only want the standardized slope coefficients, then we need to remove the row in np.diag(std) that refers to the constant, i.e. where std=0.
I'm not sure whether that is needed, i.e. standardized beta for constant is zero, and bse should still be correct (also=0 ? I think, without doing the math or checking an example again).
Sorry, my mistake, also on the stackoverflow answer. (Problem with typing answers without trying out the code. I did this several years ago, and don't remember where I put my examples.)
use std(0): we need std along axis=0 to get the std for each column of exog.
Also, std[0] = 1 in my code assumes that the constant is in the first column, which does not standardize the constant.
(I remember that I looked at the literature for something similar to beta coefficients in the orthogonal/uncorrelated exog case where we have some interpretation as variance decomposition.
It didn't sound exciting or generally applicable enough to me to write code for it.)
I no longer use SPSS but Stata sometimes. I actually checked my results using lm.beta in R before posting. I checked Stata and it actually indeed transfer all variable to a z distribution
In other words, the beta coefficients are the coefficients that you would obtain if the outcome and predictor variables were all transformed standard scores, also called z-scores, before running the regression.
The beta coefficients are the regression coefficients obtained by first standardizing all variables to have a mean of 0 and a standard deviation
I think you're right about GLM and I never hear of using beta coef in GLM and Stata doesn't offer that option either. Thus, I think maybe we should only include it in OLS/linear model summary or add an attribute to allow user's access to it in RegressionResults?
t_test in the results classes does the same thing, it tests linear combination of parameters for each row in the restriction matrix. With a diagonal restriction matrix, each parameter is multiplied by the corresponding diagonal element.
The main advantage is that t_test can produce the entire params_table including standard errors, pvalue and confidence interval.
For WLS and IRLS, we have the choice or option to standardize w.r.t. endog, exog or wendog, wexog.
In terms of var_weights, I think this correspond to standardizing the original data by var (std) or weighted var (std).
I guess we can check the definitions in terms of variance decomposition in an orthogonal design with var_weights, e.g. for balanced anova.
Implemented in PR #10248. Added RegressionResults.get_beta_coefficients() (and alias beta_coefficients()) returning a structured BetaCoefficientsResults container with standardized beta estimates, standard errors, $t$-values, $p$-values, confidence intervals, and .summary(). Matches direct z-score standardized OLS regression.
Activity
josef-pkt commentedon Aug 6, 2017
possible issues:
(For penalization we also have the opposite case, we keep the parameters on the original scale, but adjust penalization for the variance of exog. I.e. penalize at standardized coefficients but report original coefficients.)
In those cases we don't have equivalence between results after standardizing endog and exog and the post-estimation beta coefficients, and cannot use that property in unit tests.
josef-pkt commentedon Sep 26, 2017
just a thought "eform" with/as standardized coefficients?
multiplier in exp mean function or oddsration in logit mean function are normalized for the interpretation of the response, but still depend on the exog scale.
e.g. standardize/rescale only the exog
"odds_ratio for one standard deviation change in explanatory variables"?
stevenlis commentedon Feb 12, 2019
My current workaround:
Is there any other easy ways to get the beta coefficients with the current SM api?
josef-pkt commentedon Feb 13, 2019
see my answer to the stackoverflow question https://stackoverflow.com/questions/50842397/how-to-get-standardised-beta-coefficients-for-multiple-linear-regression-using
There is no need to reestimate the model, (although in corner cases standardizing the exog can improve numerical stability of the computations)
josef-pkt commentedon Feb 13, 2019
using std on all exog includes the constant
If we only want the standardized slope coefficients, then we need to remove the row in
np.diag(std)that refers to the constant, i.e. where std=0.I'm not sure whether that is needed, i.e. standardized beta for constant is zero, and bse should still be correct (also=0 ? I think, without doing the math or checking an example again).
stevenlis commentedon Feb 13, 2019
I tried
but it returned a floating number. Am I missing something?
josef-pkt commentedon Feb 13, 2019
Sorry, my mistake, also on the stackoverflow answer. (Problem with typing answers without trying out the code. I did this several years ago, and don't remember where I put my examples.)
use
std(0): we need std along axis=0 to get the std for each column of exog.Also,
std[0] = 1in my code assumes that the constant is in the first column, which does not standardize the constant.stevenlis commentedon Feb 13, 2019
Could you try the following code and the results doesn't seem to match with one another.
josef-pkt commentedon Feb 13, 2019
AFAIR, the endog is not zscored for the beta coefficients
using original 'tip'
then I get
to get the standardized coefficient if also endog is standardized we can use:
josef-pkt commentedon Feb 13, 2019
wikipedia says dependent variable is also z-scored
so my "AFAIR" is based on not remembering this correctly (or I had a different definition)
e.g.
https://www3.nd.edu/~rwilliam/stats1/x92.pdf
josef-pkt commentedon Feb 13, 2019
related issue #1660
(I remember that I looked at the literature for something similar to beta coefficients in the orthogonal/uncorrelated exog case where we have some interpretation as variance decomposition.
It didn't sound exciting or generally applicable enough to me to write code for it.)
josef-pkt commentedon Feb 13, 2019
GLM/discrete like Poisson or Binomial:
i.e. if we want generic beta coefficients, we cannot use linear model properties.
(Ok, I should read my early comments above instead of coming up with the same thoughts again.)
josef-pkt commentedon Feb 13, 2019
one more comment
numpy std uses ddof=0 by default, I guess SPSS uses ddof=1.
(ddof drops out in
std_x / std_y)stevenlis commentedon Feb 14, 2019
I no longer use SPSS but Stata sometimes. I actually checked my results using lm.beta in R before posting. I checked Stata and it actually indeed transfer all variable to a z distribution
From REGRESSION WITH STATA CHAPTER
From Stata's regress doc on page 3
I think you're right about GLM and I never hear of using beta coef in GLM and Stata doesn't offer that option either. Thus, I think maybe we should only include it in OLS/linear model summary or add an attribute to allow user's access to it in
RegressionResults?stevenlis commentedon Feb 14, 2019
I'm not very familiar with this
.t_test()method but using the equation in the handout you linked seems working.Output:
josef-pkt commentedon Feb 14, 2019
t_testin the results classes does the same thing, it tests linear combination of parameters for each row in the restriction matrix. With a diagonal restriction matrix, each parameter is multiplied by the corresponding diagonal element.The main advantage is that
t_testcan produce the entire params_table including standard errors, pvalue and confidence interval.josef-pkt commentedon Oct 30, 2021
For WLS and IRLS, we have the choice or option to standardize w.r.t. endog, exog or wendog, wexog.
In terms of var_weights, I think this correspond to standardizing the original data by var (std) or weighted var (std).
I guess we can check the definitions in terms of variance decomposition in an orthogonal design with var_weights, e.g. for balanced anova.
ENH: Add Brant test, standardized beta coefficients, and Dunn post-ho…
Shikhar-Kesharwani commentedon Sep 13, 2026
Implemented in PR #10248. Added$t$ -values, $p$ -values, confidence intervals, and
RegressionResults.get_beta_coefficients()(and aliasbeta_coefficients()) returning a structuredBetaCoefficientsResultscontainer with standardized beta estimates, standard errors,.summary(). Matches direct z-score standardized OLS regression.Shikhar-Kesharwani commentedon Sep 13, 2026
Dedicated PR opened in #10250 with isolated diff, full test suite, and benchmarks.