# The Kuiper GOF: # this is the most correcrt: Vn, Vc, pVn, H0_K2, lev_K2 = DFST.Kuiper_GOF( cX_c ) print('Kuiper GOF =', Vn, pVn, H0_K2, lev_K2) # The R2 coefficient: fX_r2 = np.zeros(len(x1),) for mu, kap, pii in zip(loc_mle, kap_mle, p_mle): temp = stats.vonmises( kap, mu, scal_ ) fX_r2 += pii*temp.pdf( x1 ) dx = np.diff(x1) cX_r2 = np.ones(len(x1),) cX_r2[0:-1] = np.cumsum(fX_r2[0:-1]*dx) R2 = DFST.myR2( cX_r2, cfX_obs ) print('R2 =', R2) if R2 > 0.90: H0_R2 = "Do not reject" else: H0_R2 = "Reject" # Plot the Probability-Probability Plot: DFST.PP_GOF( cX_r2, cfX_obs ) # ---------------------------------------------------------------------- # #%% Collect all results into a Pandas dataFrame: gof_list = ["Waston", "Kuiper", "R2"] gof_stats = np.array([U2, Vn, R2]) gof_crVal = np.array([uc, Vc, 1.0]) gof_pvals = np.array([pu2, pVn, 1.0])
U2, Us, uc, pu2, pus = DFst.watson( cfX_tot, alphal=2 ) print('1st DFst.watson =',U2, Us, uc, pu2, pus) Vn, pVn = DFst.Kuiper_GOF( cfX_tot ) print('1st Kuiper:', Vn, pVn) # --------------------------------------------------------------- # # get the CDF of the postulated distribution: # using the bins from the histogram of the random sample: # so the CDF is computed over equally-spaced points: print('# ------- Case with bins from histogram (equally-spaced): -------- #') cfX_temp1 = fX_i.cdf(bins) # make the P-P plot: DFst.PP_GOF( cfX_temp1[0:-1], cdfX_samp ) # compute the R2 coefficient: R2 = DFst.myR2( cfX_temp1[0:-1], cdfX_samp ) print('R2 (cumsum-1):', R2) # make the P-P plot: DFst.PP_GOF( cfX_temp1[0:-1], EEE ) # compute the R2 coefficient: R2 = DFst.myR2( cfX_temp1[0:-1], EEE ) print('R2 (cumsum-2):', R2) # a. compute the K-S statistic # we CAN because of the form of the statistic, being the difference of the # model and the emprirical CDFs: d00 = np.array([1.63, 1.36, 1.22])/np.sqrt(len(cdfX_samp)) Dm = abs(cfX_temp1[0:-1] - cdfX_samp) D = max(Dm) sqnD = np.sqrt(len(cdfX_samp))*D pval = 1 - DFst.KS_CDF( sqnD )
dx = abs(x[0] - x[1]) fig, ax = plt.subplots(1, 1, figsize=(4, 3)) ax.set_title('CDF plot') ax.plot(x, cfX_obs, 'b', lw=3, alpha=0.6, label='ECDF, ecdf()') ax.plot(x, np.cumsum(X_tot * dx), 'r--', lw=2, alpha=0.6, label='CDF model') #ax.plot(x, cXtot, 'g', lw=2, alpha=0.6, label='CDF fit +=') ax.set_xlabel(r'$\theta$ (rads)', fontsize=12) ax.set_ylabel('Cumulative distribution', fontsize=12) ax.legend() R2 = DFST.myR2(np.cumsum(X_tot * dx), cfX_obs) print('R2:', R2) DFST.PP_GOF(np.cumsum(X_tot * dx), cfX_obs) # this returns wrong conclusion: U2, Us, uc, pu2, pus = DFST.watson_GOF(np.cumsum(X_tot * dx), alphal=2) print('1st DFst.watson =', U2, Us, uc, pu2, pus) #%% ------------------------------------------------------------------- # # based on populated points for every angle based on its intensity: # CAUTION !!! # THIS IS THE CORRECT APPROACH !!! aa = np.sort(p_X) fX_t = np.zeros(len(aa), ) cX_t = np.zeros(len(aa), )