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.


February 20, 2008 at 6:43 pm 36 comments

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):

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:

  columnSums = []
  for i in range(len(observedTuples[0])):
    columnSum = 0.0
  for row in observedTuples:
    columnSum += row[i]

  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)

February 13, 2008 at 10:46 pm 3 comments