#NEWLINE# def anova2_lm_single( model , design_info , n_rows , test , pr_test , robust ) : #NEWLINE# #INDENT# '\n    ANOVA type II table for one fitted linear model.\n\n    Parameters\n    ----------\n    model : fitted linear model results instance\n        A fitted linear model\n\n    **kwargs**\n\n    scale : float\n        Estimate of variance, If None, will be estimated from the largest\n    model. Default is None.\n        test : str {"F", "Chisq", "Cp"} or None\n        Test statistics to provide. Default is "F".\n\n    Notes\n    -----\n    Use of this function is discouraged. Use anova_lm instead.\n\n    Type II\n    Sum of Squares compares marginal contribution of terms. Thus, it is\n    not particularly useful for models with significant interaction terms.\n    ' #NEWLINE# terms_info = design_info . terms [ : ] #NEWLINE# terms_info = _remove_intercept_patsy ( terms_info ) #NEWLINE# names = [ 'sum_sq' , 'df' , test , pr_test ] #NEWLINE# table = DataFrame ( np . zeros ( ( n_rows , 4 ) ) , columns = names ) #NEWLINE# cov = _get_covariance ( model , None ) #NEWLINE# robust_cov = _get_covariance ( model , robust ) #NEWLINE# col_order = [ ] #NEWLINE# index = [ ] #NEWLINE# for ( i , term ) in enumerate ( terms_info ) : #NEWLINE# #INDENT# cols = design_info . slice ( term ) #NEWLINE# L1 = lrange ( cols . start , cols . stop ) #NEWLINE# L2 = [ ] #NEWLINE# term_set = set ( term . factors ) #NEWLINE# for t in terms_info : #NEWLINE# #INDENT# other_set = set ( t . factors ) #NEWLINE# if ( term_set . issubset ( other_set ) and ( not ( term_set == other_set ) ) ) : #NEWLINE# #INDENT# col = design_info . slice ( t ) #NEWLINE# L1 . extend ( lrange ( col . start , col . stop ) ) #NEWLINE# L2 . extend ( lrange ( col . start , col . stop ) ) #NEWLINE# #UNINDENT# #UNINDENT# L1 = np . eye ( model . model . exog . shape [ 1 ] ) [ L1 ] #NEWLINE# L2 = np . eye ( model . model . exog . shape [ 1 ] ) [ L2 ] #NEWLINE# if L2 . size : #NEWLINE# #INDENT# LVL = np . dot ( np . dot ( L1 , robust_cov ) , L2 . T ) #NEWLINE# from scipy import linalg #NEWLINE# ( orth_compl , _ ) = linalg . qr ( LVL ) #NEWLINE# r = ( L1 . shape [ 0 ] - L2 . shape [ 0 ] ) #NEWLINE# L12 = np . dot ( orth_compl [ : , ( - r ) : ] . T , L1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# L12 = L1 #NEWLINE# r = L1 . shape [ 0 ] #NEWLINE# #UNINDENT# if ( test == 'F' ) : #NEWLINE# #INDENT# f = model . f_test ( L12 , cov_p = robust_cov ) #NEWLINE# table . ix [ ( i , test ) ] = test_value = f . fvalue #NEWLINE# table . ix [ ( i , pr_test ) ] = f . pvalue #NEWLINE# #UNINDENT# table . ix [ ( i , 'df' ) ] = r #NEWLINE# col_order . append ( cols . start ) #NEWLINE# index . append ( term . name ( ) ) #NEWLINE# #UNINDENT# table . index = Index ( ( index + [ 'Residual' ] ) ) #NEWLINE# table = table . ix [ np . argsort ( ( col_order + [ ( model . model . exog . shape [ 1 ] + 1 ) ] ) ) ] #NEWLINE# ssr = ( ( ( table [ test ] * table [ 'df' ] ) * model . ssr ) / LVL . df_resid ) #NEWLINE# table [ 'sum_sq' ] = ssr #NEWLINE# table . ix [ ( 'Residual' , [ 'sum_sq' , 'df' , test , pr_test ] ) ] = ( model . ssr , model . df_resid , np . nan , np . nan ) #NEWLINE# return table