In [1]:
from csvreader import read_patient_csv
from PyTCI.weights import leanbodymass
from matplotlib import pyplot
from patient_solver import solve_for_marsh, solve_for_schnider
import math
import statistics
import numpy
In [2]:
patients = read_patient_csv()
obese_patients = []
for patient in patients:
patient["bmi"] = leanbodymass.bmi(patient["height"], patient["weight"])
if patient["bmi"] >=35:
obese_patients.append(patient)
In [3]:
len(obese_patients)
Out[3]:
In [4]:
bmis = []
for person in obese_patients:
bmis.append(person["bmi"])
pyplot.hist(bmis)
Out[4]:
In [5]:
marsh_medians= []
marsh_bias = []
schnider_median = []
schnider_bias = []
mod_marsh_medians= []
mod_marsh_bias = []
mod_schnider_median = []
mod_schnider_bias = []
for patient in obese_patients:
res = solve_for_marsh(patient, [])
marsh_medians.append(res["median"])
marsh_bias.append(res["bias"])
res = solve_for_schnider(patient, [])
schnider_median.append(res["median"])
schnider_bias.append(res["bias"])
if patient["sex"] == 'm':
patient["weight"] = 1 * (patient["height"]-60)
else:
patient["weight"] = 1 * (patient["height"]-65)
res = solve_for_marsh(patient, [])
mod_marsh_medians.append(res["median"])
mod_marsh_bias.append(res["bias"])
res = solve_for_schnider(patient, [])
mod_schnider_median.append(res["median"])
mod_schnider_bias.append(res["bias"])
In [6]:
def returnmedian(a, b):
marsh_medians= []
for patient in obese_patients:
if patient["sex"] == 'm':
patient["weight"] = a * (patient["height"]-b)
else:
patient["weight"] = a * (patient["height"]-(b+5))
res = solve_for_marsh(patient, [])
marsh_medians.append(res["median"])
return round(statistics.mean(marsh_medians), 2)
In [7]:
base = [marsh_medians, marsh_bias, schnider_median, schnider_bias]
modified = [mod_marsh_medians, mod_marsh_bias, mod_schnider_median, mod_schnider_bias]
print("baseline")
for thing in base:
c = [i ** 2 for i in thing]
a = numpy.sqrt(c)
b = statistics.median(a)
print(b)
print("modified")
for thing in modified:
c = [i ** 2 for i in thing]
a = numpy.sqrt(c)
b = statistics.median(a)
print(b)
In [8]:
pyplot.figure()
pyplot.scatter(marsh_medians, marsh_bias, alpha=0.5)
pyplot.scatter(mod_marsh_medians, mod_marsh_bias, alpha=0.5)
pyplot.title('Marsh')
pyplot.xlabel('Median Error')
pyplot.ylabel('Bias')
# pyplot.axis([0, 2, -2, 2])
pyplot.figure()
pyplot.scatter(schnider_median, schnider_bias, alpha=0.5)
pyplot.scatter(mod_schnider_median, mod_schnider_bias, alpha=0.5)
pyplot.title('Schnider')
pyplot.xlabel('Median Error')
pyplot.ylabel('Bias')
# pyplot.axis([0, 2, -2, 2])
pyplot.show()
In [ ]:
alphas = numpy.linspace(0.5, 2, num=16)
betas = numpy.linspace(0, 150, num=16)
row = (f"{b:4}"for b in betas)
print('{:4}'.format('XXX') + ' '.join(row))
for a in alphas:
# print(*(f"{returnmedian(a, b):4}" for b in betas))
row = (f"{returnmedian(a, b):4}" for b in betas)
print(f"{a:4} " + ' '.join(row))
In [ ]: