(Y, f0, Y_em, R, alpha, m1, m2, m3, n1, n2, n3, n)
return select.reshape(n,)
Use F-test for model selection.
Use F-test for model selection.
Use F - test for model selection .
def f_test(Y, f0, Y_em, R, alpha, m1, m2, m3, n1, n2, n3, n):
    """Use F-test for model selection."""
    # Initialize ind with zeros (all terms insignificant)
    select = np.zeros((n, 1))

    # Determine the significant components of the HDMR model via the F-test
    Y_res0 = Y - f0
    SSR0 = np.sum(np.square(Y_res0))
    p0 = 0
    for i in range(n):
        # model with ith term included
        Y_res1 = Y_res0 - Y_em[:, i].reshape(R, 1)

        # Number of parameters of proposed model (order dependent)
        if i <= n1:
            p1 = m1        # 1st order
        elif i > n1 and i <= (n1 + n2):
            p1 = m2        # 2nd order
        else:
            p1 = m3        # 3rd order

        # Calculate SSR of Y1
        SSR1 = np.sum(np.square(Y_res1))

        # Now calculate the F_stat (F_stat > 0 -> SSR1 < SSR0 )
        F_stat = ((SSR0 - SSR1) / (p1 - p0)) / (SSR1 / (R - p1))

        # Now calculate critical F value
        F_crit = stats.f.ppf(q=alpha, dfn=p1 - p0, dfd=R - p1)

        # Now determine whether to accept ith component into model
        if F_stat > F_crit:
            # ith term is significant and should be included in model
            select[i] = 1

    return select.reshape(n,)
def f_test ( Y , f0 , Y_em , R , alpha , m1 , m2 , m3 , n1 , n2 , n3 , n ) : # Initialize ind with zeros (all terms insignificant) select = np . zeros ( ( n , 1 ) ) # Determine the significant components of the HDMR model via the F-test Y_res0 = Y - f0 SSR0 = np . sum ( np . square ( Y_res0 ) ) p0 = 0 for i in range ( n ) : # model with ith term included Y_res1 = Y_res0 - Y_em [ : , i ] . reshape ( R , 1 ) # Number of parameters of proposed model (order dependent) if i <= n1 : p1 = m1 # 1st order elif i > n1 and i <= ( n1 + n2 ) : p1 = m2 # 2nd order else : p1 = m3 # 3rd order # Calculate SSR of Y1 SSR1 = np . sum ( np . square ( Y_res1 ) ) # Now calculate the F_stat (F_stat > 0 -> SSR1 < SSR0 ) F_stat = ( ( SSR0 - SSR1 ) / ( p1 - p0 ) ) / ( SSR1 / ( R - p1 ) ) # Now calculate critical F value F_crit = stats . f . ppf ( q = alpha , dfn = p1 - p0 , dfd = R - p1 ) # Now determine whether to accept ith component into model if F_stat > F_crit : # ith term is significant and should be included in model select [ i ] = 1 return select . reshape ( n , )