I've tried searching for an answer to this problem but so far I haven't found any. I used statsmodel to implement an Ordinary Least Squares regression model on a mean-imputed dataset. I can access the list of residuals in the OLS results, but not studentized residuals. How can I calculate/get studentized residuals? I know the formula for calculating studentized residuals but I'm not exactly sure how to code this formula in Python.
Thanks in advance.
UPDATE: I've found the answer. I can get a dataframe containing the studentized residuals from the outlier_test() function from OLS reults.
A studentized residual is calculated by dividing the residual by an estimate of its standard deviation. The standard deviation for each residual is computed with the observation excluded. For this reason, studentized residuals are sometimes referred to as externally studentized residuals.
In statistics, a studentized residual is the quotient resulting from the division of a residual by an estimate of its standard deviation. It is a form of a Student's t-statistic, with the estimate of error varying between points. This is an important technique in the detection of outliers.
The standardized residual is found by dividing the difference of the observed and expected values by the square root of the expected value. The standardized residual can be interpreted as any standard score. The mean of the standardized residual is 0 and the standard deviation is 1.
I was dealing with the same issue. The solution is to use the statsmodels
library:
from statsmodels.stats.outliers_influence import OLSInfluence
It has a resid_studentized_internal
method included.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With