#NEWLINE# def gen_endog( lin_pred , family_class , link , binom_version = 0 ) : #NEWLINE# #INDENT# np . random . seed ( 872 ) #NEWLINE# fam = sm . families #NEWLINE# mu = link ( ) . inverse ( lin_pred ) #NEWLINE# if ( family_class == fam . Binomial ) : #NEWLINE# #INDENT# if ( binom_version == 0 ) : #NEWLINE# #INDENT# endog = ( 1 * ( np . random . uniform ( size = len ( lin_pred ) ) < mu ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# endog = np . empty ( ( len ( lin_pred ) , 2 ) ) #NEWLINE# n = 10 #NEWLINE# endog [ : , 0 ] = ( np . random . uniform ( size = ( len ( lin_pred ) , n ) ) < mu [ : , None ] ) . sum ( 1 ) #NEWLINE# endog [ : , 1 ] = ( n - endog [ : , 0 ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( family_class == fam . Poisson ) : #NEWLINE# #INDENT# endog = np . random . poisson ( mu ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( family_class == fam . Gamma ) : #NEWLINE# #INDENT# endog = np . random . gamma ( 2 , mu ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( family_class == fam . Gaussian ) : #NEWLINE# #INDENT# endog = ( mu + np . random . normal ( size = len ( lin_pred ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( family_class == fam . NegativeBinomial ) : #NEWLINE# #INDENT# from scipy.stats.distributions import nbinom #NEWLINE# endog = nbinom . rvs ( mu , 0.5 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( fam == fam . InverseGaussian ) : #NEWLINE# #INDENT# from scipy.stats.distributions import invgauss #NEWLINE# endog = invgauss . rvs ( mu ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return endog