Source code for naginterfaces.library.examples.mv.discrim_group_ex

#!/usr/bin/env python3
"``naginterface.library.mv.discrim_group`` Python Example."

# NAG Copyright 2017-2019.

# pylint: disable=invalid-name

from naginterfaces.library import mv

[docs]def main(): """ Example for :func:`naginterfaces.library.mv.discrim_group`. Discriminant analysis. >>> main() naginterfaces.library.mv.discrim_group Python Example Results. Discriminant analysis for diagnosis of Cushing's syndrome. Obs Posterior Allocated Atypicality probabilities to group index 1 0.094 0.905 0.002 2 0.596 0.254 0.975 2 0.005 0.168 0.827 3 0.952 0.836 0.018 3 0.019 0.920 0.062 2 0.954 0.797 0.912 4 0.697 0.303 0.000 1 0.207 0.860 0.993 5 0.317 0.013 0.670 3 0.991 1.000 0.984 6 0.032 0.366 0.601 3 0.981 0.978 0.887 """ print('naginterfaces.library.mv.discrim_group Python Example Results.') print('Discriminant analysis for diagnosis of Cushing\'s syndrome.') # The observations: x = [ [1.1314, 2.4596], [1.0986, 0.2624], [0.6419, -2.3026], [1.3350, -3.2189], [1.4110, 0.0953], [0.6419, -0.9163], [2.1163, 0.0000], [1.3350, -1.6094], [1.3610, -0.5108], [2.0541, 0.1823], [2.2083, -0.5108], [2.7344, 1.2809], [2.0412, 0.4700], [1.8718, -0.9163], [1.7405, -0.9163], [2.6101, 0.4700], [2.3224, 1.8563], [2.2192, 2.0669], [2.2618, 1.1314], [3.9853, 0.9163], [2.7600, 2.0281], ] # The inclusions: isx = [1]*len(x[0]) # The groupings: ing = [ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, ] # The number of groups: ng = 3 d = mv.discrim( x, isx, ing, ng, ) # For the grouping computation: # Predictive approach: typ = 'Predictive' # Assuming unequal within-group var-covar matrices: equal = 'Unequal' # The form of the prior probabilities: priors = 'Equal' # The observations: x_g = [ [1.6292, -0.9163], [2.5572, 1.6094], [2.5649, -0.2231], [0.9555, -2.3026], [3.4012, -2.3026], [3.0204, -0.2231], ] # No priors need to be input: prior = [0.]*ng # Require atypicality indices: atiq = True dg = mv.discrim_group( typ, equal, priors, d.nig, d.gmn, d.gc, d.det, isx, x_g, prior, atiq, ) print( ' Obs Posterior Allocated' ' Atypicality' ) print(' probabilities to group index') for i, ig in enumerate(dg.iag): print( '{:6d}'.format(i+1) + ' '*5 + ''.join(['{:6.3f}']*ng).format(*dg.p[i, :]) + '{:6d}'.format(ig) + ' '*5 + ''.join(['{:6.3f}']*ng).format(*dg.ati[i, :]) )
if __name__ == '__main__': import doctest import sys sys.exit( doctest.testmod( None, verbose=True, report=False, optionflags=doctest.REPORT_NDIFF, ).failed )