#=======================================================================
# Author: Donovan Parks
#
# Perform a post-hoc test by applying Welch's t-test to each pair of groups.
#
# Copyright 2011 Donovan Parks
#
# This file is part of STAMP.
#
# STAMP is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# STAMP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with STAMP.	If not, see <http://www.gnu.org/licenses/>.
#=======================================================================

import math

from stamp.plugins.multiGroups.AbstractPostHocTestPlugin import AbstractPostHocTestPlugin
from stamp.plugins.groups.statisticalTests.Welch import Welch

from scipy.stats import distributions

class WelchUncorrected(AbstractPostHocTestPlugin):
	'''
	Perform a post-hoc test by applying Welch's t-test to each pair of groups.
	'''
	
	def __init__(self, preferences):
		AbstractPostHocTestPlugin.__init__(self, preferences)
		self.name = 'Welch\'s (uncorrected)'
		self.welch = Welch(preferences)
	
	def run(self, data, coverage, groupNames):
		# calculate statistics for each pair of groups
		pValues = []
		effectSizes = []
		lowerCIs = []
		upperCIs = []
		labels = []
		postHocNote = ''
		for i in xrange(0, len(data)):
			for j in xrange(i+1, len(data)):
				pValueOneSided, pValueTwoSided, lowerCI, upperCI, dp, note = self.welch.run(data[i], data[j], [0.01]*len(data[i]), [0.01]*len(data[j]), '', coverage)
				
				pValues.append(pValueTwoSided)
				effectSizes.append(dp)
				lowerCIs.append(lowerCI)
				upperCIs.append(upperCI)
				if note != '':
					postHocNote = note

				labels.append(groupNames[i] + ' : ' + groupNames[j])
			
		return pValues, effectSizes, lowerCIs, upperCIs, labels, postHocNote

if __name__ == "__main__": 
	pass
