#NEWLINE# @ cache_readonly #NEWLINE# def random_effects_cov( self ) : #NEWLINE# #INDENT# '\n        Returns the conditional covariance matrix of the random\n        effects for each group given the data.\n\n        Returns\n        -------\n        random_effects_cov : dict\n            A dictionary mapping the distinct values of the `group`\n            variable to the conditional covariance matrix of the\n            random effects given the data.\n        ' #NEWLINE# try : #NEWLINE# #INDENT# cov_re_inv = np . linalg . inv ( self . cov_re ) #NEWLINE# #UNINDENT# except np . linalg . LinAlgError : #NEWLINE# #INDENT# cov_re_inv = None #NEWLINE# #UNINDENT# vcomp = self . vcomp #NEWLINE# ranef_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for group_ix in range ( self . model . n_groups ) : #NEWLINE# #INDENT# ( ex_r , ex2_r ) = ( self . model . _aex_r [ group_ix ] , self . model . _aex_r2 [ group_ix ] ) #NEWLINE# label = self . model . group_labels [ group_ix ] #NEWLINE# vc_var = self . model . _expand_vcomp ( vcomp , group_ix ) #NEWLINE# solver = _smw_solver ( self . scale , ex_r , ex2_r , cov_re_inv , ( 1 / vc_var ) ) #NEWLINE# n = ex_r . shape [ 0 ] #NEWLINE# m = self . cov_re . shape [ 0 ] #NEWLINE# mat1 = np . empty ( ( n , m ) ) #NEWLINE# mat1 [ : , 0 : m ] = np . dot ( ex_r [ : , 0 : m ] , self . cov_re ) #NEWLINE# mat1 [ : , m : ] = np . dot ( ex_r [ : , m : ] , np . diag ( vc_var ) ) #NEWLINE# mat2 = solver ( mat1 ) #NEWLINE# mat2 = np . dot ( mat1 . T , solver ) #NEWLINE# v = ( - mat2 ) #NEWLINE# v [ 0 : m , 0 : m ] += self . cov_re #NEWLINE# ix = np . arange ( m , v . shape [ 0 ] ) #NEWLINE# v [ ( ix , ix ) ] += vc_var #NEWLINE# na = self . _expand_re_names ( group_ix ) #NEWLINE# v = pd . DataFrame ( v , index = na , columns = na ) #NEWLINE# ranef_dict [ label ] = v #NEWLINE# #UNINDENT# return ranef_dict