Archive for February, 2008
Remove / Delete Directory and Its Contents in Linux
(Note: Please see my latest posts at my new blog!)
rm -rf <DirectoryName>
This command will remove a directory and its contents without prompting you to make sure you want to delete each file in the directory. Substitute <DirectoryName> with the actual directory name.
5 comments February 20, 2008
Computing Chi-Squared P-Value from Contingency Table in Python
(Note: Please see my latest posts at my new blog!)
Update: Here is a link to notes from my Stats class that gives some background (starting on page 5): http://episun7.med.utah.edu/~alun/teach/stats/week05.pdf
To do this you need to have SciPy installed. Below is one way to do it. I’m sure there’s a more efficient way to do it. But this is working for me. Any feedback is welcome.
def computeContingencyTablePValue(*observedTuples):
if len(observedTuples) == 0: return None
for row in observedTuples:
if len(row) != len(observedTuples[0]): return None
rowSums = []
for row in observedTuples:
rowSums.append(float(sum(row)))
columnSums = []
for i in range(len(observedTuples[0])):
columnSum = 0.0
for row in observedTuples:
columnSum += row[i]
columnSums.append(float(columnSum))
grandTotal = float(sum(rowSums))
observedTestStatistic = 0.0
for i in range(len(observedTuples)):
for j in range(len(row)):
expectedValue = (rowSums[i]/grandTotal)*(columnSums[j]/grandTotal)*grandTotal
observedValue = float(observedTuples[i][j])
observedTestStatistic += ((observedValue - expectedValue)**2) / expectedValue
degreesFreedom = (len(columnSums) - 1) * (len(rowSums) - 1)
return scipy.stats.chisqprob(observedTestStatistic, degreesFreedom)
Add comment February 13, 2008