Пример #1
0
    def test_interval(self):
        data = [
            Datum(1, False),
            Datum(1, True),
            Datum(1, False),
            Datum(1, True)
        ]
        interval = Interval(0, 2)
        interval.data = data

        self.assertEqual(interval.get_censored(), 2)
Пример #2
0
def ct(t):
    """
    Censored @ time
    :param t: time
    :return: Datum object
    """
    return Datum(time=t, censored=True)
Пример #3
0
def dt(t):
    """
    Dead @ time
    :param t: time
    :return: Datum object
    """
    return Datum(time=t, censored=False)
Пример #4
0
    def test_computed_interval_numbers(self):
        data = [
            Datum(7, True, {'id': 55}),
            Datum(9, False, {'id': 11}),
            Datum(9, False, {'id': 12}),
            Datum(2, True, {'id': 54}),
            Datum(3, True, {'id': 19}),
            Datum(15, False, {'id': 19}),
            Datum(1, True, {'id': 92}),
            Datum(14, True, {'id': 33}),
            Datum(1, False, {'id': 44}),
            Datum(11, False, {'id': 21})
        ]
        analyzer = Analyzer(data)
        results = analyzer.compute()

        json_results = list(
            map(lambda interval: interval.to_json_dict(), results))
        pprint.pprint(json_results)

        self.assertEqual(len(results), 4)
        self.assertAlmostEqual(results[1].cumulative, 0.888888888)
        self.assertAlmostEqual(results[2].cumulative, 0.533333333)
Пример #5
0
def printjson(message):
    print(json.dumps({"message": message}))


data = []

try:
    for line in sys.stdin:
        # Read the participants line by line (ignoring newline character)
        participant = json.loads(line[:-1])

        # Build them into a list of Datums (data? :shrug: )
        time = participant.get('time')
        censored = participant.get('censored')
        kfid = participant.get('id')

        datum = Datum(time, censored, {'id': kfid})

        data.append(datum)

    # Do the computations!
    analyzer = Analyzer(data)
    results = analyzer.compute()
    json_results = list(map(lambda interval: interval.to_json_dict(), results))

    # Spit out the results
    printjson(json_results)
except Exception as e:
    printjson({'error': str(e)})
Пример #6
0
    def test_identical(self):
        """
        When curves are identical, pvalue should be exactly one.
        """
        data1 = [
            Datum(7, True, {'id': 55}),
            Datum(9, False, {'id': 11}),
            Datum(2, True, {'id': 54}),
            Datum(3, True, {'id': 19}),
            Datum(1, False, {'id': 4}),
            Datum(11, False, {'id': 21})
        ]
        analyzer1 = Analyzer(data1)
        results1 = analyzer1.compute()

        data2 = [
            Datum(7, True, {'id': 55}),
            Datum(9, False, {'id': 11}),
            Datum(2, True, {'id': 54}),
            Datum(3, True, {'id': 19}),
            Datum(1, False, {'id': 4}),
            Datum(11, False, {'id': 21})
        ]
        analyzer2 = Analyzer(data2)
        results2 = analyzer2.compute()

        test = LogRankTest([results1, results2])
        stats = test.compute()
        print(json.dumps(stats))

        self.assertEqual(stats['degreesFreedom'], 1)
        self.assertEqual(stats['pValue'], 1)
        self.assertAlmostEqual(stats['chiSquared'], 0, 2)