I've got some data that looks like this:
allgroups = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
I want to calculate the sum of square between and within group, but I have no idea how to do this. I already calculated the mean, variance , and grand mean. From what I know the
sswithin = sum((variance-1)*size of each list)
ssbetween = sum(((mean-grandmean)**2)*size of each list)
Here is my code:
def avg(allgroups): #Average List
return [float(sum(i))/len(i) for i in allgroups]
def variance(allgroups): #Variance List
return [sum((x - sum(group) / len(group)) ** 2 for x in group) / (len(group) - 1) for group in allgroups]
def calcavg(allgroups): #Grand Average
return float(sum(avg(allgroups)) / len(avg(allgroups)))
def size(allgroups): #Size of the sameples in list
return [len(group) for group in allgroups]
TheAvg=avg(allgroups)
print(TheAvg)
Variance=variance(allgroups)
print(Variance)
calcAvg=calcavg(allgroups)
print(calcAvg)
sizeSample=size(allgroups)
print(sizeSample)
I will be grateful for any help. P/S: I can't use any library for this problem such as numpy or statistic.

