Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute Studentized Residuals in Python?

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.

like image 478
Hanazono Sakura Avatar asked Aug 03 '17 13:08

Hanazono Sakura


People also ask

How do you calculate studentized residuals?

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.

What does studentized residuals measure?

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.

How standardized residuals are calculated?

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.


1 Answers

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.

like image 133
nimi1234 Avatar answered Sep 17 '22 20:09

nimi1234