示例#1
0
 def test_get_cod_data(self):
     return  # skip for now
     cf = data.get_cod_data(level=1)
     assert len(cf.cause) == 3 and cf.cause.dtype == 'S1'
     assert len(cf.est) == 3 and cf.est.dtype == 'float32'
     assert len(cf.lower) == 3 and cf.lower.dtype == 'float32'
     assert len(cf.upper) == 3 and cf.upper.dtype == 'float32'
示例#2
0
 def test_get_cod_data(self):
     return # skip for now
     cf = data.get_cod_data(level=1)
     assert len(cf.cause) == 3 and cf.cause.dtype == 'S1'
     assert len(cf.est) == 3 and cf.est.dtype == 'float32'
     assert len(cf.lower) == 3 and cf.lower.dtype == 'float32'
     assert len(cf.upper) == 3 and cf.upper.dtype == 'float32' 
示例#3
0
import sys
import pylab as pl 
import scipy.stats.mstats as st

# set parameters 
outdir = '/home/j/Project/Causes of Death/Under Five Deaths/CoD Correct Output'
indir = '/home/j/Project/Causes of Death/Under Five Deaths/CoD Correct Input Data' 
age, iso3, sex = sys.argv[1:4]
full_dir = '%s/v02_prep_%s' % (indir, iso3)

# get cause list 
causes = list(set([file.split('+')[1] for file in os.listdir(full_dir) if re.search(age, file)]))
causes.remove('HIV') # temporary until Miriam fixes the HIV files 

# gather data and fit model 
cf = data.get_cod_data(full_dir, causes, age, iso3, sex)
m, pi = models.fit_latent_simplex(cf) 

# calculate summary measures
N, T, J = pi.shape
mean = pi.mean(0)
lower = pl.array([[st.mquantiles(pi[:,t,j], 0.025)[0] for j in range(J)] for t in range(T)])
upper = pl.array([[st.mquantiles(pi[:,t,j], 0.975)[0] for j in range(J)] for t in range(T)])

# format summary and save
output = pl.np.core.records.fromarrays(mean.T, names=['%s_mean' % c for c in causes])
output = pl.rec_append_fields(output, ['%s_lower' % c for c in causes], lower.T)
output = pl.rec_append_fields(output, ['%s_upper' % c for c in causes], upper.T)
pl.rec2csv(output, '%s/%s+%s+%s+summary.csv' % (outdir, iso3, age, sex))

# format all sims and save 
示例#4
0
 def test_sim_cod_data(self):
     return  # skip for now
     cf = data.get_cod_data(level=1)
     X = data.sim_cod_data(10, cf)
     assert pl.shape(X) == (10, 3)
示例#5
0
 def test_sim_cod_data(self): 
     return # skip for now
     cf = data.get_cod_data(level=1)
     X = data.sim_cod_data(10, cf)
     assert pl.shape(X) == (10, 3)