#include "Includes/posteriors.ibf";

if (_CATEGORY_VARIABLE_EVENT_[0] >= 0)
{
	_moment_matrix = {_sites, 6};
	
	_event_size	   = Columns (_CATEGORY_VARIABLE_EVENT_);
	
	for (_counter2 = 0; _counter2 < _sites; _counter2 = _counter2 + 1)
	{
		_prior  	 = 0;
		_posterior    = 0;
		
		for (_counter = 0; _counter < _event_size; _counter = _counter + 1)
		{
			_eidx = _CATEGORY_VARIABLE_EVENT_ [_counter];
			
			_prior     = _prior + _CATEGORY_VARIABLE_CDF_[0][_eidx];
			_posterior = _posterior +  _MARGINAL_MATRIX_[_eidx][_counter2];
		}
		
		_moment_matrix[_counter2][0] = _prior;
		_moment_matrix[_counter2][1] = _posterior;
		if (_prior>=1)
		{
			_moment_matrix[_counter2][2] = 1e100;		
		}
		else
		{
			_moment_matrix[_counter2][2] = _prior/(1-_prior);
		}
		if (_posterior>=1)
		{
			_moment_matrix[_counter2][3] = 1e100;		
		}
		else
		{
			_moment_matrix[_counter2][3] = _posterior/(1-_posterior);
		}
		_moment_matrix[_counter2][4] = _moment_matrix[_counter2][3]/_moment_matrix[_counter2][2];
		_moment_matrix[_counter2][5] = Log(_moment_matrix[_counter2][4]);
	}
	
	_labels = {{"Event Prior","Event Posterior", "Prior Odds", "Posterior Odds", "Bayes Factor","Log[Bayes Factor]",""}};


	_rowLabel = "Site";
	for (_counter2 = 1; _counter2 <= _sites; _counter2 = _counter2 + 1)
	{
		_rowLabel = _rowLabel + ";" + _counter2;
	}

	_labels [6] = _rowLabel;


	promptString = "Event [" + (_CATEGORY_VARIABLE_EVENT_ [0]+1);
	
	for (_counter = 1; _counter < _event_size; _counter = _counter + 1)
	{
		promptString = promptString + "," + (_CATEGORY_VARIABLE_EVENT_ [_counter]+1);
	}
	
	promptString = promptString + "] Info For " + _CATEGORY_VARIABLE_ID_;

	OpenWindow (CHARTWINDOW,{{promptString}
							   {"_labels"},
							   {"_moment_matrix"},
							   {"None"},
							   {""},
							   {""},
							   {""},
							   {""},
							   {""},
							   {"0"}},
							   "SCREEN_WIDTH-60;SCREEN_HEIGHT-50;30;50");
							   
	_labels = 0;
	_sites  = 0;
	_momentMatrix = 0;
}
else
{
	fprintf (stdout, "\n+-------------------------------------------------------+\n"
					   "|                EMPTY EVENT SELECTED                   |",
					 "\n+-------------------------------------------------------+\n");
					   
}
