compute_F = function( group_names, data, use_F1=TRUE ){ # # Compute the F_1 or F_2 metric expressing the distance of group means from the grand mean. # ugroups = unique( group_names ) ng = length(ugroups) x_bar_dot_dot = mean( data ) # the grand mean x_bar_i_dot = rep( NA, ng ) for( gi in 1:ng ){ d = data[ group_names == ugroups[gi] ] x_bar_i_dot[gi] = mean(d) } if( use_F1 ){ F = sum( abs( x_bar_i_dot - x_bar_dot_dot ) ) }else{ F = sum( ( x_bar_i_dot - x_bar_dot_dot )^2 ) } return(F) }