#!/bin/bash

# This script runs the binomial test on two labelings.  The number of
# trials is the number of cases where one labeling is better than the
# other. The number of successes is the number of times labeling 2
# is better than labeling 1. The p-value is the probability of
# getting as many or more successes assuming probability of success is
# 0.5 under the binomial distribution, multiplied by 2 for a
# two-tailed test.

BASELINE=$1
SYSTEM=$2

if [[ -z $BASELINE || -z $SYSTEM ]]
then
    echo "USAGE:"
    echo "  test-binom.sh LABELING-BASELINE LABELING-SYSTEM"
    exit 1
fi

temp=`mktemp`
paste -d' ' <(cat $BASELINE | rev | cut -f1,2 -d' ' | rev) \
            <(cat $SYSTEM | rev | cut -f1 -d' ' | rev)  > $temp
binom.R $temp

rm $temp
