<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import numpy as np <EOL> from statsmodels . sandbox . panel . mixed import OneWayMixed , Unit <EOL> examples = [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in examples : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> nsubj = <NUM_LIT> <EOL> units = [ ] <EOL> nobs_i = <NUM_LIT:4> <EOL> nx = <NUM_LIT:4> <EOL> nz = <NUM_LIT:2> <EOL> beta = np . ones ( nx ) <EOL> gamma = <NUM_LIT:0.5> * np . ones ( nz ) <EOL> gamma [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> gamma_re_true = [ ] <EOL> for i in range ( nsubj ) : <EOL> gamma_re = gamma + <NUM_LIT> * np . random . standard_normal ( nz ) <EOL> gamma_re_true . append ( gamma_re ) <EOL> if i > nsubj // <NUM_LIT:4> : <EOL> nobs_i = <NUM_LIT:6> <EOL> X = np . random . standard_normal ( ( nobs_i , nx ) ) <EOL> Z = np . random . standard_normal ( ( nobs_i , nz - <NUM_LIT:1> ) ) <EOL> Z = np . column_stack ( ( np . ones ( nobs_i ) , Z ) ) <EOL> noise = <NUM_LIT:0.1> * np . random . randn ( nobs_i ) <EOL> Y = np . dot ( X , beta ) + np . dot ( Z , gamma_re ) + noise <EOL> X = np . hstack ( ( X , Z ) ) <EOL> unit = Unit ( Y , X , Z ) <EOL> units . append ( unit ) <EOL> m = OneWayMixed ( units ) <EOL> import time <EOL> t0 = time . time ( ) <EOL> m . initialize ( ) <EOL> res = m . fit ( maxiter = <NUM_LIT:100> , rtol = <NUM_LIT> , params_rtol = <NUM_LIT> , params_atol = <NUM_LIT> ) <EOL> t1 = time . time ( ) <EOL> print ( '<STR_LIT>' , t1 - t0 ) <EOL> print ( '<STR_LIT>' , m . iterations ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( m . a ) <EOL> print ( m . params ) <EOL> bfixed_cov = m . cov_fixed ( ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . sqrt ( np . diag ( bfixed_cov ) ) ) <EOL> print ( m . bse ) <EOL> b_re = m . params_random_units <EOL> print ( '<STR_LIT>' , b_re . mean ( <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT>' , b_re . std ( <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . cov ( b_re , rowvar = <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . sqrt ( np . diag ( np . cov ( b_re , rowvar = <NUM_LIT:0> ) ) ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( m . cov_random ( ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( res . std_random ( ) ) <EOL> print ( np . sqrt ( np . diag ( m . cov_random ( ) ) ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( m . history [ '<STR_LIT>' ] [ - <NUM_LIT:4> : ] ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . diff ( np . vstack ( m . history [ '<STR_LIT>' ] [ - <NUM_LIT:4> : ] ) , axis = <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( np . diff ( np . array ( m . history [ '<STR_LIT:D>' ] [ - <NUM_LIT:4> : ] ) , axis = <NUM_LIT:0> ) ) <EOL> zb = np . array ( [ ( unit . Z * unit . b [ None , : ] ) . sum ( <NUM_LIT:0> ) for unit in m . units ] ) <EOL> '''<STR_LIT>''' <EOL> print ( '<STR_LIT>' ) <EOL> gamma_re_true = np . array ( gamma_re_true ) <EOL> print ( '<STR_LIT>' , gamma_re_true . mean ( <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT>' , m . params [ - <NUM_LIT:2> : ] ) <EOL> print ( '<STR_LIT>' , b_re . mean ( <NUM_LIT:0> ) ) <EOL> print ( '<STR_LIT>' ) <EOL> absmean_true = np . abs ( gamma_re_true ) . mean ( <NUM_LIT:0> ) <EOL> mape = ( ( m . params [ - <NUM_LIT:2> : ] + b_re ) / gamma_re_true - <NUM_LIT:1> ) . mean ( <NUM_LIT:0> ) * <NUM_LIT:100> <EOL> mean_abs_perc = np . abs ( ( m . params [ - <NUM_LIT:2> : ] + b_re ) - gamma_re_true ) . mean ( <NUM_LIT:0> ) / absmean_true * <NUM_LIT:100> <EOL> median_abs_perc = np . median ( np . abs ( ( m . params [ - <NUM_LIT:2> : ] + b_re ) - gamma_re_true ) , <NUM_LIT:0> ) / absmean_true * <NUM_LIT:100> <EOL> rmse_perc = ( ( m . params [ - <NUM_LIT:2> : ] + b_re ) - gamma_re_true ) . std ( <NUM_LIT:0> ) / absmean_true * <NUM_LIT:100> <EOL> print ( '<STR_LIT>' , mape ) <EOL> print ( '<STR_LIT>' , mean_abs_perc ) <EOL> print ( '<STR_LIT>' , median_abs_perc ) <EOL> print ( '<STR_LIT>' , rmse_perc ) <EOL> from numpy . testing import assert_almost_equal <EOL> print ( res . llf ) <EOL> print ( res . tvalues ) <EOL> print ( res . pvalues ) <EOL> print ( res . t_test ( [ <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( res . f_test ( [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] ) ) <EOL> plots = res . plot_random_univariate ( bins = <NUM_LIT:50> ) <EOL> fig = res . plot_scatter_pairs ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> import matplotlib . pyplot as plt <EOL> plt . show ( ) </s>
