def test_simeval(testdata): orig = Model(testdata / 'nonmem' / 'pheno.mod') base = Model(testdata / 'nonmem' / 'qa' / 'pheno_linbase.mod') simeval_res = read_results(testdata / 'nonmem' / 'qa' / 'simeval_results.json') cdd_res = read_results(testdata / 'nonmem' / 'qa' / 'cdd_results.json') calculate_results(orig, base, simeval_results=simeval_res, cdd_results=cdd_res)
def test_bootstrap(): orig = ModelfitResults(ofv=110, parameter_estimates=pd.Series({'TVCL': 0.75, 'TVV': 2.25})) res1 = ModelfitResults(ofv=100, parameter_estimates=pd.Series({'TVCL': 1.0, 'TVV': 2.0})) res2 = ModelfitResults(ofv=120, parameter_estimates=pd.Series({'TVCL': 1.5, 'TVV': 3.0})) class MyModel: pass orig_mod = MyModel() orig_mod.modelfit_results = orig res1_mod = MyModel() res1_mod.modelfit_results = res1 res2_mod = MyModel() res2_mod.modelfit_results = res2 boot = calculate_results([res1_mod, res2_mod], original_model=orig_mod) correct_statistics = pd.DataFrame( { 'mean': [1.25, 2.5], 'median': [1.25, 2.50], 'bias': [0.5, 0.25], 'stderr': [0.353553, 0.707107], 'RSE': [0.2828424, 0.2828424], }, index=['TVCL', 'TVV'], ) pd.testing.assert_frame_equal(boot.parameter_statistics, correct_statistics) # json round trip json = boot.to_json() obj = read_results(json) pd.testing.assert_frame_equal(obj.parameter_statistics, correct_statistics)
def results_report(args): """Subcommand to generate reports""" results_path = args.psn_dir / 'results.json' if not results_path.is_file(): error(FileNotFoundError(results_path)) from pharmpy.results import read_results res = read_results(results_path) res.create_report(args.psn_dir)
def results_print(args): """Subcommand to print any results""" if args.dir.is_dir(): path = args.dir / 'results.json' elif args.dir.is_file(): path = args.dir else: error(FileNotFoundError(str(args.dir))) from pharmpy.results import read_results res = read_results(path) print(res)
def test_bootstrap(): orig = ModelfitResults(ofv=110, parameter_estimates=pd.Series({ 'TVCL': 0.75, 'TVV': 2.25 })) res1 = ModelfitResults(ofv=100, parameter_estimates=pd.Series({ 'TVCL': 1.0, 'TVV': 2.0 })) res2 = ModelfitResults(ofv=120, parameter_estimates=pd.Series({ 'TVCL': 1.5, 'TVV': 3.0 })) class MyModel: pass orig_mod = MyModel() orig_mod.modelfit_results = orig res1_mod = MyModel() res1_mod.modelfit_results = res1 res2_mod = MyModel() res2_mod.modelfit_results = res2 boot = BootstrapResults(orig_mod, [res1_mod, res2_mod]) correct_statistics = pd.DataFrame( { 'mean': [110.0, 1.25, 2.5], 'bias': [0.0, 0.5, 0.25], 'stderr': [14.142136, 0.353553, 0.707107] }, index=['OFV', 'TVCL', 'TVV']) pd.testing.assert_frame_equal( boot.parameter_estimates, pd.DataFrame({ 'TVCL': [1.0, 1.5], 'TVV': [2.0, 3.0] })) pd.testing.assert_frame_equal(boot.statistics, correct_statistics) # json round trip json = boot.to_json() obj = read_results(json) pd.testing.assert_frame_equal(obj.statistics, correct_statistics)
def test_scm(testdata): orig = Model(testdata / 'nonmem' / 'pheno.mod') base = Model(testdata / 'nonmem' / 'qa' / 'pheno_linbase.mod') scm_res = read_results(testdata / 'nonmem' / 'qa' / 'scm_results.json') res = calculate_results(orig, base, scm_results=scm_res) correct = """,,dofv,coeff ETA(1),APGR,2.48792,-0.033334 ETA(1),WGT,0.48218,0.052342 ETA(2),APGR,0.59036,0.008371 ETA(2),WGT,0.00887,-0.003273 """ correct = pd.read_csv(StringIO(correct), index_col=[0, 1]) correct.index.set_names(['parameter', 'covariate'], inplace=True) pd.testing.assert_frame_equal(res.covariate_effects, correct, atol=1e-6) assert res.dofv['dofv']['covariates', 'ET1APGR-2', np.nan] == pytest.approx(2.48792) assert res.dofv['df']['covariates', 'ET1APGR-2', np.nan] == 1
def test_resmod(testdata): orig = Model(testdata / 'nonmem' / 'pheno.mod') base = Model(testdata / 'nonmem' / 'qa' / 'pheno_linbase.mod') resmod_res = read_results(testdata / 'nonmem' / 'qa' / 'resmod_results.json') res = calculate_results(orig, base, resmod_idv_results=resmod_res) assert list( res.residual_error['additional_parameters']) == [2, 2, 1, 1, 1, 1] assert list( res.residual_error['dOFV']) == [13.91, 8.03, 5.53, 3.34, 1.31, 0.03] assert res.residual_error.index.tolist() == [ (1, 'dtbs'), (1, 'time_varying'), (1, 'tdist'), (1, 'autocorrelation'), (1, 'IIV_on_RUV'), (1, 'power'), ] assert res.dofv['dofv']['residual_error_model', 'dtbs', 1] == pytest.approx(13.91)
def psn_qa_results(path): """Create qa results from a PsN qa run :param path: Path to PsN qa run directory :return: A :class:`QAResults` object """ path = Path(path) original_model = Model(path / 'linearize_run' / 'scm_dir1' / 'derivatives.mod') base_path = list(path.glob('*_linbase.mod'))[0] base_model = Model(base_path) fullblock_path = path / 'modelfit_run' / 'fullblock.mod' if fullblock_path.is_file(): fullblock_model = Model(fullblock_path) else: fullblock_model = None boxcox_path = path / 'modelfit_run' / 'boxcox.mod' if boxcox_path.is_file(): boxcox_model = Model(boxcox_path) else: boxcox_model = None tdist_path = path / 'modelfit_run' / 'tdist.mod' if tdist_path.is_file(): tdist_model = Model(tdist_path) else: tdist_model = None addetas_path = path / 'add_etas_run' / 'add_etas_linbase.mod' if addetas_path.is_file(): addetas_model = Model(addetas_path) else: addetas_model = None iov_path = path / 'modelfit_run' / 'iov.mod' if iov_path.is_file(): iov_model = Model(iov_path) else: iov_model = None frem_path = path / 'frem_run' / 'results.json' if frem_path.is_file(): frem_res = read_results(frem_path) else: frem_res = None cdd_path = path / 'cdd_run' / 'results.json' if cdd_path.is_file(): cdd_res = read_results(cdd_path) else: cdd_res = None scm_path = path / 'scm_run' / 'results.json' if scm_path.is_file(): scm_res = read_results(scm_path) else: scm_res = None args = psn_helpers.options_from_command(psn_helpers.psn_command(path)) if 'add_etas' not in args: etas_added_to = None else: etas_added_to = args['add_etas'].split(',') res = calculate_results( original_model, base_model, fullblock_model=fullblock_model, boxcox_model=boxcox_model, tdist_model=tdist_model, add_etas_model=addetas_model, iov_model=iov_model, etas_added_to=etas_added_to, frem_results=frem_res, cdd_results=cdd_res, scm_results=scm_res, ) return res