function makeStats() {
  // Make stats based on procedure and state
  _.each(stats, function(stat, statGroup) {
    _.each(stat, function(s, field) {
      var stepRange;
      
      if (!s.values) {
        console.log('Issue with stat for group: ' + statGroup);
      }
      
      stats[statGroup].count = s.values.length;
      
      //stats[statGroup][field].sum = ss.sum(s.values);
      //stats[statGroup][field].min = ss.min(s.values);
      //stats[statGroup][field].max = ss.max(s.values);
      stats[statGroup][field].mean = ss.mean(s.values);
      stats[statGroup][field].median = ss.median(s.values);
      //stats[statGroup][field].mode = ss.mode(s.values);
      //stats[statGroup][field].variance = ss.variance(s.values);
      //stats[statGroup][field].standard_deviation = ss.standard_deviation(s.values);
      stats[statGroup][field].q25 = ss.quantile(s.values, 0.25);
      stats[statGroup][field].q75 = ss.quantile(s.values, 0.75);
      
      stepRange = outlierRange(s.values, stats[statGroup][field].q25, stats[statGroup][field].q75, stats[statGroup][field].median);
      stats[statGroup][field].stepL = stepRange[0];
      stats[statGroup][field].stepU = stepRange[1];
    });
  });
  
  // Make stats based on provider
  _.each(_.groupBy(charges, 'provider'), function(pCharges, provider) {
    _.each(_.union(stateStatsFilter, ['']), function(stat) {
      var values = [];
      var prefix = (stat) ? stat + '-' : '';
      
      // Average charged difference
      _.each(pCharges, function(c) {
        values.push(c.avgCovChg / stats[prefix + c.drg].avgCovChg.mean);
      });
      providers[provider].diff = providers[provider].diff || {};
      providers[provider].diff[prefix + 'AvgCovChg'] = ss.mean(values);
    });
  });
  
  // Figure out average provider diffs for MN
  _.each(_.union(stateStatsFilter, ['']), function(stat) {
    var values = [];
    var prefix = (stat) ? stat + '-' : '';
    
    _.each(providers, function(p) {
      values.push(p.diff[prefix + 'AvgCovChg']);
    });
    
    console.log('MN average provider charge percentage of ' + 
      ((prefix === '') ? 'US' : prefix) + ': ' + ss.mean(values));
  });
  
  // Figure out average procedure diffs for MN
  _.each(_.union(stateStatsFilter, ['']), function(stat) {
    var values = [];
    var prefix = (stat) ? stat + '-' : '';
    
    _.each(charges, function(c) {
      values.push(c.avgCovChg / stats[prefix + c.drg].avgCovChg.mean);
    });
    
    console.log('MN average procedure charge percentage of ' + 
      ((prefix === '') ? 'US' : prefix) + ': ' + ss.mean(values));
  });
  
  // Remove actual values
  _.each(stats, function(stat, statGroup) {
    _.each(stat, function(s, field) {
      delete stats[statGroup][field].values;
    });
  });
}
// Using the values we got from before make stats
Using the values we got from before make stats
Using the values we got from before make stats
function makeStats() {
  _.each(stats, function(stat, statGroup) {
    _.each(stat, function(s, field) {
      var stepRange;
      if (!s.values) {
        console.log('Issue with stat for group: ' + statGroup);
      }
      stats[statGroup].count = s.values.length;
      stats[statGroup][field].mean = ss.mean(s.values);
      stats[statGroup][field].median = ss.median(s.values);
      stats[statGroup][field].q25 = ss.quantile(s.values, 0.25);
      stats[statGroup][field].q75 = ss.quantile(s.values, 0.75);
      stepRange = outlierRange(s.values, stats[statGroup][field].q25, stats[statGroup][field].q75, stats[statGroup][field].median);
      stats[statGroup][field].stepL = stepRange[0];
      stats[statGroup][field].stepU = stepRange[1];
    });
  });
  _.each(_.groupBy(charges, 'provider'), function(pCharges, provider) {
    _.each(_.union(stateStatsFilter, ['']), function(stat) {
      var values = [];
      var prefix = (stat) ? stat + '-' : '';
      _.each(pCharges, function(c) {
        values.push(c.avgCovChg / stats[prefix + c.drg].avgCovChg.mean);
      });
      providers[provider].diff = providers[provider].diff || {};
      providers[provider].diff[prefix + 'AvgCovChg'] = ss.mean(values);
    });
  });
  _.each(_.union(stateStatsFilter, ['']), function(stat) {
    var values = [];
    var prefix = (stat) ? stat + '-' : '';
    _.each(providers, function(p) {
      values.push(p.diff[prefix + 'AvgCovChg']);
    });
    console.log('MN average provider charge percentage of ' + 
      ((prefix === '') ? 'US' : prefix) + ': ' + ss.mean(values));
  });
  _.each(_.union(stateStatsFilter, ['']), function(stat) {
    var values = [];
    var prefix = (stat) ? stat + '-' : '';
    _.each(charges, function(c) {
      values.push(c.avgCovChg / stats[prefix + c.drg].avgCovChg.mean);
    });
    console.log('MN average procedure charge percentage of ' + 
      ((prefix === '') ? 'US' : prefix) + ': ' + ss.mean(values));
  });
  _.each(stats, function(stat, statGroup) {
    _.each(stat, function(s, field) {
      delete stats[statGroup][field].values;
    });
  });
}
function makeStats ( ) { _ . each ( stats , function ( stat , statGroup ) { _ . each ( stat , function ( s , field ) { var stepRange ; if ( ! s . values ) { console . log ( 'Issue with stat for group: ' + statGroup ) ; } stats [ statGroup ] . count = s . values . length ; stats [ statGroup ] [ field ] . mean = ss . mean ( s . values ) ; stats [ statGroup ] [ field ] . median = ss . median ( s . values ) ; stats [ statGroup ] [ field ] . q25 = ss . quantile ( s . values , 0.25 ) ; stats [ statGroup ] [ field ] . q75 = ss . quantile ( s . values , 0.75 ) ; stepRange = outlierRange ( s . values , stats [ statGroup ] [ field ] . q25 , stats [ statGroup ] [ field ] . q75 , stats [ statGroup ] [ field ] . median ) ; stats [ statGroup ] [ field ] . stepL = stepRange [ 0 ] ; stats [ statGroup ] [ field ] . stepU = stepRange [ 1 ] ; } ) ; } ) ; _ . each ( _ . groupBy ( charges , 'provider' ) , function ( pCharges , provider ) { _ . each ( _ . union ( stateStatsFilter , [ '' ] ) , function ( stat ) { var values = [ ] ; var prefix = ( stat ) ? stat + '-' : '' ; _ . each ( pCharges , function ( c ) { values . push ( c . avgCovChg / stats [ prefix + c . drg ] . avgCovChg . mean ) ; } ) ; providers [ provider ] . diff = providers [ provider ] . diff || { } ; providers [ provider ] . diff [ prefix + 'AvgCovChg' ] = ss . mean ( values ) ; } ) ; } ) ; _ . each ( _ . union ( stateStatsFilter , [ '' ] ) , function ( stat ) { var values = [ ] ; var prefix = ( stat ) ? stat + '-' : '' ; _ . each ( providers , function ( p ) { values . push ( p . diff [ prefix + 'AvgCovChg' ] ) ; } ) ; console . log ( 'MN average provider charge percentage of ' + ( ( prefix === '' ) ? 'US' : prefix ) + ': ' + ss . mean ( values ) ) ; } ) ; _ . each ( _ . union ( stateStatsFilter , [ '' ] ) , function ( stat ) { var values = [ ] ; var prefix = ( stat ) ? stat + '-' : '' ; _ . each ( charges , function ( c ) { values . push ( c . avgCovChg / stats [ prefix + c . drg ] . avgCovChg . mean ) ; } ) ; console . log ( 'MN average procedure charge percentage of ' + ( ( prefix === '' ) ? 'US' : prefix ) + ': ' + ss . mean ( values ) ) ; } ) ; _ . each ( stats , function ( stat , statGroup ) { _ . each ( stat , function ( s , field ) { delete stats [ statGroup ] [ field ] . values ; } ) ; } ) ; }
Using the values we got from before make stats
Using the values we got from before make stats
// Make stats based on procedure and state //stats[statGroup][field].sum = ss.sum(s.values); //stats[statGroup][field].min = ss.min(s.values); //stats[statGroup][field].max = ss.max(s.values); //stats[statGroup][field].mode = ss.mode(s.values); //stats[statGroup][field].variance = ss.variance(s.values); //stats[statGroup][field].standard_deviation = ss.standard_deviation(s.values); // Make stats based on provider // Average charged difference // Figure out average provider diffs for MN // Figure out average procedure diffs for MN // Remove actual values