{smcl}
*  rdiag version 1.010  Robert A. Yaffee  8 Aug 2012


{title:Title} rdiag  {hline 2}  Executes an ordinary least squares regression diagnostic analysis as a 
                       post-estimation regression command.

{phang}


{title:Syntax}  {cmd:rdiag {it:resx} }
                        
                        where resx is any name the user assigns to the standardized residuals prior to diagnosis.

{p 8 17 2}


{title: Description}            The {bf:rdiag} command automatically performs a residual diagnostic battery
                        of tests.   The battery consists of 7 sets of tests for ordinary least squares
                        regression analysis.  It constructs standardized residuals from the name assigned
                        to them by the user after the {it: rdiag} command.  In short, you do not have to
                        create them before hand if you have not already done so. Just give your residuals
                        a new name--for example, resx and type the command above. It will construct 
                        standardized residuals from which it will provide a diagnosis of them.
                        
                        It performs a summary statistical description of the standardized residuals,  which
                        includes an estimate of the percentiles, the mean, the stadnard deviation,
                        the variance, as well as the skewness and kurtosis.
                        
                        
                        The first test performed is that for variance stability as a kind of {bf:structural break}
                        in the sample. The sample is split into thirds and the variance for each is computed. 
                        The smallest variance is divided into each of the others. If the Kruskall Wallis test  
                        is statistically significant , the residuals point to the existence of a sample a structural 
                        break or level shift in the data.  This could cause heteroskedasticity.
                        
                        The second set of tests comprises an {bf:outlier analysis}. Any observation with a value of
                        the standardized residual greater than 3.5 or less than - 3.5 and not equal to missing
                        is identified as an outlier.  They are split into positive and negative outliers and
                        listed along with their id,  {it:Cook's D}, and leverage value.  To facilitate visualizing
                        these outliers a stem and leaf plot is presented.
                        
                        The third test is for {bf:multicollinearity}. If the explanatory variables are substantially
                        correlated, there could be problems with the analysis. Variance inflation scores {bf:VIF},
                        condition numbers, and condition indices are generated as indicators of the extent of 
                        multicollinearity. As a rule the condition number should be below 5 for assurance of no 
                        multicollinearity. According to Professor Richard Williams of Notre Dame,  VIF scores above 
                        30 suggest serious collinearity among the explanatory variables and VIF scores above 20 
                        can even indicate problems. VIF =  1/(1 - R^2) = 1/tolerance.   If the condition index is 
                        above 15, that is another indicator of collinearity problems.  Under conditions of 
                        collinearity, the standard errors become large and there is a tendency to the significance 
                        tests to become biased downward. 
                        
                        The fourth set of tests is for {bf:residual normality}. Three tests are performed to test
                        for a normal distribution of the residuals.  They include the {bf:Shapiro-Wilk
                        W} test, the {bf:Jargue-Bera} test, and the {bf:Kolmogorov-Smirnov} test. 
                        
                        The fifth set of tests is to test the assumption of homogeneity of the residuals.
                        To tests for this aspect of the residual distribution,  the {bf:Breusch-Pagan} 
                        test and {bf:Cameron and Trivedi}'s  decomposition of the information matrix test is also
                        provided.
                                                
                        A sixth test, the {bf:Ramsey Reset test}, is given as a form of specification error
                        test.  The percentage of these six assumptions violated is called the percent invalid.
                        The percent of pseudo-validity is computed by subtracting the percent invalid from 100.
                        A column vector indicating the tests and whether the assumption was violated, in which
                        case the value in the cell is a one, or not, in which case the score in the cell is 
                        equal to zero.  The total number of violated assumptions is indicated.  A percent
                        invalid and a percent pseudo-validity score is also computed.  This is a heuristic
                        by which to compare regression models rather than an established validity score.
                       
                        
                        
                        
{title: Options}        There are no options.


{title: Graphs}         Four diagnostic graphs are generated.  The are positioned in a 2 by 2 matrix.
                        In the upper left is a quantile normal plot, which defines the distributional 
                        deviation from the normal diagonal.  A box and Wisker plot is in the upper right,
                        giving another sense of outliers symmetry and the interquartile range with the 
                        horizontal line representing the median.  In the lower left, is an outlier
                        influence plot and in the lower right is a histogram with a theoretical normal
                        line overlaid.

{title: Assumptions violation list}   A column vector listing the assumptions and tests for those assumptions
                        is generated.  When a misspecification tests fails, a score of one is given, and when
                        a test does not fail, a score of zero is assigned. The number of assumptions violated
                        is computed and a column total of the number violated is assigned. Pseudo-validity
                        and invalidity scores are computed from the percentage of the sex assumptions violated.
                        These scores are found at the bottom of the column vector.
            


{title: return list}    Data returned when the user types: return list
                        r(pctvalid) = percentage of six regression assumptions fulfilled.
                        r(pctinvalid) = percentage of six regression assumptions violated.
                        r(indep) = whether your residuals are independently distributed, according to a 
                           runs test.
                        r(coltot)  =  Number of assumptions violated.
                        r(strbrk) =  Whether there is evidence of a structural break according to Box's F test.  
                        r(reset)  =  Whether Ramsey reset test is violated (if so, it  = 1). If not, it = 0.
                        r(het) = What proportiono of the two tests for heteroskedasticity were violated.
                        r(white) = Whether white's Imtest is violated.
                        r(Bpagan) = Whether the Breusch-Pagan test for heteroskedasticity was violated.
                        r(skrp) = Smirnov-Kolmogorov test for normality of the residuals.
                        r(sw) = Shapiro-Wilk test for normality of the residuals.
                        r(condxNumb) =  The condition number computed from the explanatory variables in the model.
                        r(badout) = number of outliers that have a significant critical value for Cook's D (criterion 1).
                        r(negoutliers) = number of negative outliers.                                                
                        r(dfcritval) = 2*sqrt(p/n) = critical value for Dffits.
                        r(cdcritval1) = 3p/n =   a critical value for Cook's D.
                        r(numnegouts) = number of negative outliers.
                        r(numpouts) = number of positive outliers.
                        
                     


{title: Examples}
{title: Example 1}      regress y x1 x2 x3
						rdiag res1
					   
{title: Example 2}      regress y x1 x2 z1 z2
						rdiag res2
						
						where res1 and res2 are the names that the user assigns to the 
						standadized residuals of the model being diagnosed.					
						                                                
{Author: Robert A. Yaffee}  Silver School of Social Work
                            New York University
                            robert.yaffee@nyu.edu
                            
                            
{title:References}
		   Bollen, K. and Jackman, R. (1990) Regression Diagnostics: An expository treatment of outliers and
		       inflfuential cases in John Fox, ed. Modern Methods of Data Analysis, Sage publications, 263.
                            


{end}
