Repository navigation
Releases: matthiaskoenig/pkpdutils
Release list
1.3.0
Release notes for pkpdutils 1.3.0
Minor release of pkpdutils which compares the non-compartmental analysis against the public benchmark suite of the NonCompart validation report (#103): all eight scenarios (theophylline and indomethacin, intravenous bolus, 0.25 h infusion and extravascular dose, linear and linear-up / log-down trapezoids) against the published Phoenix WinNonlin output and against PKNCA 0.12.1 and NonCompart 0.8.4 run on the same data, plus analytical profiles with an exact answer. Every parameter of every subject agrees with all three tools, to the digits the published tables carry. The comparison found one important difference, now fixed: the area of an extravascular dose whose first sample comes after the dose. The new pkpdutils.crosswalk writes and reads the result tables of the three tools, and every result carries the predicted variants of the extrapolated parameters.
Important fixes
- The area of an extravascular single dose starts at the dose. A curve whose first sample comes after the dose now gets a zero inserted at the dose time for the areas (never for the terminal regression), as for an infusion and as Phoenix WinNonlin, PKNCA and NonCompart all do. Up to 1.2.0 the area of such a curve started at its first sample, which was deliberately left out of the zero rule in 1.2.0; the benchmark shows that every reference tool applies it, and without it
auc_last,auc_all,auc_inf_obs,aumc_*,mrt,cl_f,vz_fand the extrapolated fractions of the extravascular indomethacin profiles were up to 13 % off. A curve with a sample at the dose (the theophylline study) is unchanged.partial_aucand the urine analysis already applied the rule; the documentation ofnca_urinedescribed it. - The NCA figure shades the area the analysis computed.
plot_nca,plot_nca_gridanddraw_nca_panelshadeAUC(0-tlast)from the dose, with the value the analysis inserts there (the back-extrapolatedC0after a bolus, 0 after an infusion or an extravascular dose) and a dotted segment to the first sample; before, the shading started at the first sample and left out the area the reported number contains.
Breaking changes
auc_last,auc_all,auc_inf_obs,auc_inf_pred,aumc_last,aumc_inf,mrt,thalf_eff,cl_f,vz_f,auc_extrap_fraction, the dose normalized areas and everything computed from them (summaries, ratios, bioequivalence, the uncertainty) change for an extravascular single dose curve whose first sample is after the dose; see "Important fixes". A BLQ value at the dose which a rule drops leaves the same gap and is filled with the same zero.- Every
NCAResultof a single dose analysis carries the new variables below, soto_dataframe,to_ppand the tables have more columns.
Non-compartmental analysis
- The predicted variants of Phoenix WinNonlin and PKNCA, from the value of the terminal regression at
tlast(clast_pred):aumc_inf_pred,mrt_pred,cl_pred/cl_f_pred,vz_pred/vz_f_pred,vss_pred,auc_inf_pred_dn,auc_extrap_fraction_predandauc_back_extrap_fraction_pred; andaumc_extrap_fraction,aumc_extrap_fraction_predandmrt_last, the mean residence time to the last measurable value. The mean residence times of an infusion are corrected by half its duration. Their CDISC codes (AUMCIFP,MRTEVIFP/MRTIBIFP/MRTICIFP,CLP,CLFP,VZP,VZFP,VSSP,AUCIFPD,AUCPEP,AUCPBEP,AUMCPEO,AUMCPEP,MRTEVLST/MRTIBLST/MRTICLST) are extracted from the same NCI EVS terminology file as the others, and the fractions are written as percentages in the PP domain.
Data formats
pkpdutils.crosswalk, the result tables of other tools:to_winnonlin/write_winnonlin/read_winnonlin(the "Final Parameters Pivoted" table of Phoenix WinNonlin),to_pknca_results/write_pknca_results/read_pknca_results(the long table ofas.data.frame(pk.nca(...))) andto_noncompart/write_noncompart/read_noncompart(the table ofNonCompart::tblNCA), with the name mapsWINNONLIN_NAMES,PKNCA_NAMES,NONCOMPART_NAMESand their route dependent parts. The writers export the percentages of the tools, the readers return the variables ofpkpdutilswith fractions, so a published result compares column by column.Timecourses.from_dataframe(dose_duration=...)reads the infusion duration from a column, constant per sample or one per dose withdose_time.
Validation
docs/benchmark_datasets.md: the eight scenarios with every setting indocs/data/benchmarks/scenarios.csv, the code of the comparison, the largest deviation per parameter and tool, the exported tables and the analytical profiles (the exact monoexponential bolus and the convergence of the trapezoid on a Bateman curve). Every table is the printed output of the code above it, pasted byscripts/benchmark_datasets.py;tests/docs/test_benchmark_datasets.pyfails when the page is stale andtests/nca/test_benchmark_datasets.pyasserts the agreement within 1e-8.docs/data/benchmarks/holds the theophylline and indomethacin datasets (moved fromtests/data/validation/), the eight WinNonlin tables of the report unchanged and the PKNCA and NonCompart results, whichscripts/benchmark_datasets.Rrecomputes.
Python
- Python 3.15 is supported and tested on Linux, macOS and Windows (#104).
Documentation
- The snippets of the documentation may read the directories of
docs/data/as well. - The pages whose output depends on the extravascular zero (the quickstart, the workflows, NCA, uncertainty, bioequivalence, data formats, units, urinary excretion) and the example figures are regenerated.
1.2.0
Release notes for pkpdutils 1.2.0
Minor release of pkpdutils which closes the gaps a survey of the other non-compartmental analysis tools found: the parameters and rules the guidances name, acceptance criteria and exclusions, a published validation against Phoenix WinNonlin and PKNCA, the steady state completion, urinary excretion and sparse sampling, analytes and routes per sample with the CDISC parameter map, the replicate designs and reference scaled limits of bioequivalence with power and sample size, the study report, and the figures a reviewer asks for. The console renders the tables of the package, the NCA figure reports every value with its interval, and the drug-drug interaction figure shades the classes.
Breaking changes
Timecourses.substanceandTimecourses.routeraise aValueErrorfor a batch whose samples differ; the coordinatessubstanceandroutecarry the values then.Timecourses.from_timecoursesbuilds those coordinates for a mixed list instead of raising.read_adncareadsADUR(the infusion durations,duration_col) andNRRLT(the nominal times,nominal_time_col); passNonefor either to restore the old reading.read_pkncareads adurationcolumn when the dose table has one.- A batch carrying an
lloqcoordinate (everyread_adncabatch withALLOQ) is analysed against that limit under the default options; setNCAOptions.blqexplicitly or drop the coordinate for the old numbers. - Every
NCAResultcarries the boolean variablesacceptedandexcluded(andexcluded_reasononce a sample is excluded), soto_dataframehas more columns;summarize,summary_table,sample,ddi_tableandbioequivalenceskip excluded samples by default (include_excluded=Truekeeps them).BEResult.to_dataframecarries acarryovercolumn. - An intravenous infusion whose first sample is after the dose starts at 0 at the dose time, and its terminal regression starts after the end of the infusion (the rules of Phoenix WinNonlin);
auc_last,aumc_last,auc_inf_obs,mrt,vss,lambda_zand what reads them change for such a curve. The extravascular half of the zero rule is deliberately not applied. tlagis 0 rather thanNaNfor an extravascular curve whose first sample is already measurable.- The last dosing interval of a profile whose last sample falls short of
tauby at mostNCAOptions.tau_tolerance(10 %) is completed with the terminal regression instead ofNaNandINCOMPLETE_INTERVAL;tau_tolerance=0.0restores the old behaviour. accumulation_ratio(steady_state, single_dose)returns a dataset withaccumulation_ratioandstationarity_ratio.- The delta method treats
auc_tau,cmin_ss,cmax_ss,ctroughandcavgas terminal dependent when the interval can be completed. plot_ncareturns a figure of three axes (the parameter table is the third);annotate=Falsegives the two bare panels. The default colors of every figure follow the Okabe-Ito palette.ParameterSampleraises aValueErrorforvaluesgiven together with a summary field (mean,sd,n,geomean,geocv), which were kept but never read, and forlabelsorcoordson summary data (#74).ParameterResult.sample,to_quantities,flagsandNCAResult.excluderaise aValueErrornaming the indexer for a name which is not a sample dimension, fordimgiven as an indexer as well and for a label which is not on its dimension, instead of theKeyErrorof xarray; a coordinate along a sample dimension (period=1) is no indexer ofsampleany more, select the subset from the batch before the analysis (#70).- A sample dimension or a coordinate of a batch named like a dimension the result adds (
parameter,parameter_andpointof a fit,intervalandcandidateof an NCA) raises aValueErrorinstead of being overwritten, and so does abycoordinate or a sample dimension ofsummary_tablenamed like a column of the table (#72). - The process pool of the fit starts its workers with
forkserver(spawnon macOS and Windows) on every python version,pkpdutils.parallel.PROCESS_START_METHOD; on python 3.13 on Linux a pooled fit (n_workers > 1) now needs a model the workers can import, as on python 3.14 (#74).
Non-compartmental analysis
- New parameters:
tlag,auc_all,aumc_all,clast_pred,auc_back_extrap_fraction,aumc_back_extrap_fraction, the dose normalizedauc_last_dn,auc_all_dn,auc_tau_dn,cavg_dn,cmax_ss_dn,c0_dnandNCAResult.dose_normalized(parameters),thalf_eff(the effective half-lifeln 2 * MRT),fluctuation_tau,swing_tau,ptr,accumulation_ratio_cmax_obs,accumulation_ratio_cmin_obs,accumulation_ratio_ctrough_obs,auc_tau_extrap_fraction,lambda_z_t_last,lambda_z_span. - BLQ rules:
BLQRuleswith the positional axis (first,middle,last) or the tmax axis, the actionsDROP,KEEP,ZERO,LLOQ,HALF_LLOQor a number, and the presetsBLQRules.ich_m13a(),BLQRules.pkanalix(),BLQRules.pumas();Timecourse.lloqper sample;C0Method.NONEand the variablec0_method. - Acceptance criteria (
Acceptance,Acceptance.pkanalix(), the flagNOT_ACCEPTED), exclusions (NCAResult.exclude), named partial areas (NCAOptions.partial_aucs, the flagPARTIAL_EXTRAPOLATED), terminal windows per sample (TerminalPhase.windows,NCAResult.terminal_windows()), the candidate windows (TerminalPhase.keep_candidates). - The tables of a regulatory report (
pkpdutils.nca.report):M13A_STATISTICS,acceptability_table,methods_line. - Time to steady state (
pkpdutils.nca.tss) and bioavailability (pkpdutils.nca.bioavailability). - Urinary excretion (
pkpdutils.nca.urine:Excretion,nca_urinewith the renal clearance) and sparse sampling (pkpdutils.nca.sparse:nca_sparsewith the Bailer estimator, its standard error and degrees of freedom,sparse_mean). - Analytes and routes per sample: parent and metabolite in one batch (
analytes=on the readers,metabolite_ratio), an intravenous reference and an oral test in one batch. - Validation: the analysis reproduces Phoenix WinNonlin to machine precision on the indomethacin dataset and to the printed digits on the theophylline dataset, and PKNCA to 1e-7 per subject;
docs/validation.md,tests/nca/test_validation.py,scripts/validation.py.
Data formats and units
pkpdutils.cdisc: thePKPARMCDmap parsed from the NCI EVS SDTM terminology,to_pp/write_ppwriting the PP domain withPKUNITspellings.ParameterResult.to_units({...})andNCAOptions.unitsconvert a result to the reporting units.write_pkncaandwrite_adncaas the inverse of the readers;nominal_timecarried by a batch (from_arrays,from_dataframe, ADNCANRRLT).
Statistics and reporting
- Bioequivalence: the replicate designs (
Design.REPLICATE, EMA Method A), the reference scaled limits (scaling="ema" | "fda" | "fda_nti" | "ema_nti"), the carryover check (carryover_table,bioequivalence(carryover=)), the tmax comparison (hodges_lehmann), power and sample size (pkpdutils.stats.power). - The study report (
pkpdutils.report:Report,study_report) as a self-contained HTML or markdown. - The console renders the tables of the package (
pkpdutils.console.print_table,rich_table, a result through the rich protocol);summary_table(unit_style="short")andsummary_table(digits={...}).
Figures
- The NCA figure reports every value on the plot with its interval and a confidence band of the terminal regression, with a third panel listing the parameters;
plot_terminal_windows,plot_study_curves,plot_excretion,plot_sparse, the partial area shading ofplot_nca;plot_ratioshades the classes of an interaction;save_figurewrites PNG, SVG and TIFF from one stem.
Fixes
compare(paired=True, test="wilcoxon")takes the medians of the effect from the remaining pairs, not from every finite value of either sample, so a subject with a missing value on one side no longer shifts the effect (#69).plot_parameterswithlog_y=Truedraws the box of a group from the same positive values as its points, a group with a non-positive value is marked with its arithmetic mean under its own legend entry, and the legend sits in room made above the data instead of covering an interval (#71).- The fit keeps data beyond the range of double precision to its row: no floating-point warning escapes the guess, the search, the covariance, the statistics or the bootstrap, the exceptions of
terminal_guessandBateman.derivedare gone, and a row whose sum of squares, covariance or statistics overflow isNaNand flagged with the newFitFlag.OVERFLOW(#73). - The process pool of the fit no longer forks next to the threads of the NCA on python 3.13, which could deadlock and warned
This process is multi-threaded, use of fork() may lead to deadlocks(#74). - The plot functions draw into the axes of a subfigure (
fig.subfigures) and return the figure holding it. - The glossary gives every row one unit or one unit per name.
Documentation
- The pages
bioequivalence.md,ddi.md,urine.md,sparse.md,validation.md,reporting.md, the further reading ofreferences.md, the survey and the design of the round indocs/superpowers/. - The citation of the package (
CITATION.cff,.zenodo.json,README.md,docs/index.md) names König as its only author (#98).
Your pkpdutils team
1.1.0
Release notes for pkpdutils 1.1.0
Minor release of pkpdutils with dosing protocols, the multiple dose analysis and the exchange formats of pharmacokinetic data, followed by a cleanup and usability round: bug fixes, a faster batch path, consistent signatures, the tables and figures a publication prints, and documentation whose every snippet runs. The release breaks the 1.0.0 API where consistency demanded it; every change is listed below with the call to adapt.
Dosing protocols, multiple dosing and exchange formats
Dosingis the dosing protocol of a curve:amounts,times,durations(infusions), oneunitand oneroute, built withDosing.single(dose),Dosing.from_doses(doses)orDosing.regimen(dose, interval, n_doses);Timecourse.dosingholds it,Timecourse.dosereads the first dose back,relative_to_dose(which="first" | "last")shifts a curve and its protocol.- A batch (
Timecourses) carries the protocol of every sample over the dimensiondose_index(dose_amount,dose_time,dose_duration,NaNpadded);n_doses,first_dose_*,last_dose_*anddosing_of(**indexers)read it back. - The non-compartmental analysis of a multiple dose curve computes the parameters of every dosing interval (
interval_*variables over the dimensioninterval,NCAResult.intervals()as a table) and the steady state parameters of the last complete interval (auc_tau,cmax_ss,cmin_ss,ctrough,cavg,fluctuation,swing,accumulation_ratio,cl_ss); the point parameters are computed from the last dose on. FlagsINCOMPLETE_INTERVAL(the last interval is not covered by the data) andEXTRAPOLATED_TROUGH(the trough of a bolus interval was regressed).NCAOptions.tauanalyses a curve given with its last dose only;superpositionandaccumulation_ratiopredict the steady state from a single dose. pkpdutils.io:read_events/Timecourses.from_eventsandwrite_events/Timecourses.to_events(NONMEM and Monolix event records withEVID,AMT,DV,MDV,ADDL/II,SS,RATE/TINF, covariates as coordinates),read_pknca/Timecourses.from_pknca(the two PKNCA tables) andread_adnca/Timecourses.from_adnca(CDISC ADaM ADNCA). Every reader returns one batch with one sample dimension, the protocol of every subject and the covariates as coordinates.- Figures: the dose lines of a protocol in
plot_timecourse, the shadedAUC(0-tau)of a multiple dose result in the NCA panel,plot_intervalsof theinterval_*variables against the interval number.
Breaking changes of this part:
NCAOptions.regimenis removed. A repeated administration is given as theDosingprotocol of the timecourse (Dosing.regimen(dose, interval, n_doses),DosingRegimen.dosing()), and a curve given with its last dose only is analysed withNCAOptions.tau.superposition(timecourse, dosing)takes aDosingprotocol or aDosingRegimen; the predicted curve carries the protocol and no label.Timecourse.doseis a read-only property, the first dose ofTimecourse.dosing; the protocol is replaced withmodel_copy(update={"dosing": Dosing.single(dose)}), not withupdate={"dose": ...}.- A
Timecoursesdataset carries the dose dimensiondose_index:dose_amount,dose_timeanddose_durationare 2-D over(*sample_dims, dose_index); the 1-D view of a single dose batch isfirst_dose_amount/first_dose_timeandlast_dose_amount/last_dose_time. A sample dimension nameddose_indexis rejected. - A multiple dose analysis reports
cl,cl_f,vz,vz_f,vss,auc_inf_dnandcmax_dnasNaN, since the slice after the last dose carries the exposure of the earlier doses;auc_inf_obs,auc_inf_pred,aumc_infandmrtdescribe the decline after the last dose. - The clearance at steady state of an extravascular route is
cl_ss_f, notcl_ss. read_eventsandread_pkncarequire theroutekeyword: a batch has one route and the two formats carry none.
Breaking changes of the cleanup round
nca,nca_single,partial_aucandsuperpositiontakeoptionsas a keyword, asfitdoes:nca(batch, options=NCAOptions(...));t_endofsuperpositionfollowsoptionsin the signature and is a keyword as well.FitResultreportsp_cvas a fraction instead of a percentage; a table or a figure which printed it directly multiplies by 100 (the tables of the package do it themselves).- Every
plot_*function takesax/axesandstyleas keywords, and a logarithmic axis islog_x/log_yinstead oflog;plot_dose_proportionalitytakes theProportionalityResultwhichproportionality_testnow returns instead of its former tuple. read_events,read_pkncaandread_adncaname their column keywords*_col(id_col,time_col,dv_col,amt_col, ...);groupsofread_pkncaiscovariates.Timecourses.n_workersandNCAOptions.n_workers:Noneis automatic (the pool only above the size threshold) and1is serial; pass a number to force that many workers.stats.effects_from_arraysusesEffectKind.HEDGES_Gby default, like the other entry points; passkind=for another one.- The readers and
Timecourses.from_dataframeraiseValueErrornaming the sample instead of a pydanticValidationError: a sample with fewer than two time points, aNaNtime, duplicate times or a dose which is not a valid protocol is caught by the batch itself, which no longer builds oneTimecourseper sample. Timecourses.from_dataframerejects a value which is neither missing nor a number with aValueErrornaming the sample and the column; a non-numerictimecolumn raised aTypeErrorfrom pandas before, and a non-numeric dose column withdose_timewas read as a missing dose.ParameterResult.summarizeno longer reports_sd,_se,_ci_low,_ci_high,_geomeanand_geocvfor the discrete parameters (tmax,tlast,tau, the counts and the diagnostics of the terminal regression); they keepx,x_median,x_q25,x_q75andx_n.plot_timecourseno longer takesaxpositionally;plot_foresttakesexpbeforeaxandstyle;draw_nca_panel(timecourse, values, flags, *, log_y, title, ax, style)takes its data first,axas a keyword, and returns theAxesinstead ofNone.plot_goodness_of_fit:logis replaced bylog_xandlog_y, which scale and mask the two axes on their own.plot_bland_altman:logis renamedlog_ratio, since it selects the statistic (the log ratio against the log mean) and not only the scale of an axis.plot_nca,plot_nca_gridandplot_fittakeaxes, the panels to draw into; thelogofplot_nca_gridislog_y, and so is thelogofplot_parameters.plot_dose_proportionalityandplot_bland_altmantakeax.write_eventsnames its column keywords*_collike the readers, soidno longer shadows the builtin.read_adncaandread_pkncagaincovariates; the ADNCA column keywordssubject,param,value,value_unit,time_first,time_ref,dose,dtypeandlloqaresubject_col,param_col,value_col,value_unit_col,time_first_col,time_ref_col,dose_col,dtype_colandlloq_col; the PKNCAsubjectissubject_col.stats.multiple_comparison(p_values, *, method=...)andstats.effects_from_arrays(estimates, variances, *, labels=..., kind=..., ci_level=...)take their options by keyword.stats.substrate_sensitivity(auc_ratio, *, thresholds=None)takes the thresholds as an optional keyword (the FDA ones by default) instead of a required positional argument.compare_models(models, x, y):ydefaults toNoneandxalso takes aTimecourseor aTimecourses, in which casey,sd,dims,coords,x_unitandy_unitmust not be given.- The result of the NCA carries the variables
lambda_z_t_lastandlambda_z_spanand the flagNCAFlag.SPAN_LOW(1024);pkpdutils.nca.terminal.TerminalFitgains the fieldt_lastaftert_first, so a positional construction of it has to be adapted. ParameterResult.summarizereportsx_minandx_maxfor every parameter andx_cvfor every non-discrete one, and reduces the point variables ofsummarized_point_variables(theinterval_*parameters of a multiple dose analysis, which it dropped before) over the sample dimension, keeping theirintervaldimension.pkpdutils.result.SUMMARY_SUFFIXESholds_minand_max, so a fit model whose parameter or derived name ends in one of them (e_max,c_min) is rejected by the reserved suffix guard ofpkpdutils.fit.engineand has to be spelledemax,cmin.plot_timecourse(by=...)colors the curves by group and writes one legend entry per group, where it used to give every sample its own color and entry with the group value as its label; a figure of more thanmax_legend(12) entries gets no legend at all. The function gainsfacetand, with it,axes.plot_ncadraws the legend on the linear panel only,plot_nca_gridonce for the figure (into the first panel when the caller suppliesaxes); its panel titles aredose = 50 mg, individual = s1instead of50.0|s1, and itsncolsis clamped to the number of samples, so a batch of one sample no longer produces a figure of three panels.draw_nca_panelgainslegend.plot_ratioandplot_forestannotate the rows withestimate [low, high](and the weight of a study) by default and widen the x axis to hold the column;annotate=Falserestores the bare figure.plot_ratiogainslabelsfor the row names.- A curve with an infusion is drawn with the window of the infusion (a shaded span from the dose time to the end of the dose) in
plot_timecourseanddraw_nca_panel; the NCA panel marks the dose it analyses alone, since it starts at that dose. - The figures label an axis whose unit is the canonical long form of pint with the short symbols instead (
trough [mg/l], not `trough [milligram...
1.0.0
Release notes for pkpdutils 1.0.0
pkpdutils 1.0.0 is a rewrite of pkdb-analysis as a library for the pharmacokinetic and pharmacodynamic analysis of timecourses and parameters, without any dependency on PK-DB. The package, the repository and the documentation carry the new name: pypi.org/project/pkpdutils, github.com/matthiaskoenig/pkpdutils, matthiaskoenig.github.io/pkpdutils. pkdb-analysis stays available on PyPI at 0.3.1 and receives no further releases.
Breaking changes
- The package is
pkpdutils;pkdb_analysisis gone. Everything PK-DB specific was removed: the client (PKData,PKFilter, queries, the environment variables), the reports (LaTeX, Jekyll, interactive plots, tables, spreadsheets), the Gaussian process kernels, the circos plots and the caffeine utilities. PK-DB access is the job of the PK-DB tooling, not of this library. - The pharmacokinetic analysis moved from
pkdb_analysis.pk.pharmacokinetics.TimecoursePKtopkpdutils.ncaon a new data model (Timecourse,Timecourses,Dose,Route,DosingRegimen), with new parameter names and new default methods; see the migration note below. - Python 3.13 or newer is required (3.13 and 3.14 are tested on Linux, macOS and Windows). The dependencies are
numpy,scipy,pandas,xarray,pint,pydantic,matplotlibandrich;requests,depinfo,coloredlogs,openpyxl,XlsxWriter,pyyaml,gspread-pandas,altair,seaborn,scikit-learnandIPythonare no longer needed. - The library does not configure logging and does not print;
pkpdutils.log.enable_rich_logging()is the opt-in for scripts.
Features
- Data model (
pkpdutils.timecourse):Timecoursefor one curve with units, uncertainties (sd,se,n), aDosewith aRouteand metadata;Timecoursesas anxarray.Datasetover atimedimension and any sample dimensions, built from timecourses, data frames, arrays or a simulation dataset;DosingRegimenfor steady state. - Units (
pkpdutils.units): one pint registry, quantities at the boundaries, result units derived from the units of the input. - Non-compartmental analysis (
pkpdutils.nca): exposure, peak, terminal phase, clearance and volume parameters of concentration curves and the descriptive parameters of effect curves, for iv bolus, iv infusion and extravascular dosing, single dose and steady state (with superposition), vectorized over a batch with an optional process pool; the terminal phase by best adjusted R², last n points, all points after tmax or a manual window; linear, linear-up/log-down and log trapezoids; integer flags per sample; results asNCAResult, anxarray.Datasetwithattrs["units"]per variable. - Uncertainty (
pkpdutils.nca.uncertainty): parametric bootstrap and delta method for group timecourses (mean with SD or SE and n),summarizeover the individuals with the same variables, partial areas. - Curve fitting (
pkpdutils.fit): mono-, bi- and tri-exponential, Bateman, Emax, sigmoid Emax, Imax, linear, log-linear, power and allometric models; least squares in a scaled parameter space from Latin hypercube starts, standard errors from the Jacobian, t intervals, delta method for derived parameters, residual bootstrap, AIC/AICc/BIC and Akaike weights (compare_models), the confidence interval criterion of dose proportionality (proportionality_test);fit_timecourse,fit_timecoursesandfit_table. - Statistics on parameters (
pkpdutils.stats):ParameterSamplefrom a result or from published summary statistics;compare(Student, Welch and paired t, Mann-Whitney, Wilcoxon, permutation, effect sizes) andmultiple_comparison(Holm, Bonferroni, Benjamini-Hochberg); the geometric mean ratio (ratio); average bioequivalence by the two one-sided tests for parallel, paired and 2x2 crossover designs (bioequivalence,tost); the FDA/EMA classification of drug-drug interactions (ddi_classification,substrate_sensitivity); fixed effect and DerSimonian-Laird random effects meta-analysis with heterogeneity statistics (meta_analysis). - Figures (
pkpdutils.plot): timecourses, the NCA diagnostic figure and grid, fits with residuals, goodness of fit, Bland-Altman, dose proportionality, parameter distributions, ratio plots against bioequivalence limits or interaction thresholds, forest plots. Functions return theFigureand never show it. - Documentation: a user guide per topic with concepts, math, parameter tables, API examples and references, the API reference from the docstrings, runnable examples in
examples/, and thellms.txtfiles for agents. - Tooling: uv, hatchling, ruff, ty, tox, pre-commit, bump-my-version, Zensical; pull requests into
developwith the checkstests,ruff,tyanddocs; releases by tag with trusted publishing to PyPI.
Known gaps and decisions
- The parameter aliases
kelandauc_infof the design document are not provided; the names arelambda_zandauc_inf_obs/auc_inf_pred. cmax_halfandtmax_halfare computed for extravascular dosing only;exclude_cmax=Falseleaves the start of the terminal window unrestricted;cmax_ss(the maximum within one dosing interval) drives fluctuation and swing; a bolus with pre-dose samples interpolates the value at the dose time forauc_tau.- A
Timecoursesbatch has one route; batches with mixed routes are analysed separately. - Fitted parameters are reported in the raw units of the data (no normalization of volumes and clearances); the information criteria count the residual variance as an estimated parameter (
K = k + 1); the exponential phases are ordered by decreasing rate; the residual bootstrap centers and inflates the residuals and falls back to the Jacobian intervals withFitFlag.BOOTSTRAP_FALLBACKwhen fewer than two replicates converge;plot_fitdraws no bootstrap band. comparereportsci_low/ci_highand the effect sizes with every test; the rank tests report the difference or ratio of the medians without an interval; samples of one value or without variance give NaN statistics rather than an error.bioequivalencetakes two results and a sample dimension; the 2x2 crossover is the period-difference analysis of Chow and Liu, which equals the ANOVA with sequence, period and subject effects, and is verified against an ordinary least squares fit with subject effects rather than against a textbook data set.ddi_classificationclassifies on the AUC ratio and reports the Cmax ratio; the EMA thresholds equal the FDA ones.- The meta-analysis pools
Studyobjects (meta_analysis_bygroups them by category); the variance of Hedges' g isJ² var(d); the regression reference is the BCG example of the R package metafor. - Compartmental and ODE models, population modelling, covariate model building and report generation are out of scope.
Migration from pkdb-analysis
TimecoursePK becomes a Timecourse and a call of nca_single; a batch of curves is a Timecourses and a call of nca:
from pkpdutils import Dose, Route, Timecourse, nca_single
from pkpdutils.plot import plot_nca
tc = Timecourse(
time=time,
value=concentration,
time_unit="hr",
unit="mg/l",
dose=Dose(amount=100, unit="mg", route=Route.ORAL, time=0.0),
substance="caffeine",
)
result = nca_single(tc)
result.to_quantities()["auc_inf_obs"] # pint quantity
result.to_dataframe() # one row with every parameter
plot_nca(tc, result) # the diagnostic figure of TimecoursePK.figure()TimecoursePK.pk (0.3.1) |
NCAResult (1.0.0) |
|---|---|
auc |
auc_last |
aucinf |
auc_inf_obs (observed last value) and auc_inf_pred (predicted) |
tmax, cmax |
tmax, cmax |
tmaxhalf, cmaxhalf |
tmax_half, cmax_half (extravascular dosing) |
kel |
lambda_z |
thalf |
thalf |
slope, intercept, r_value, std_err |
lambda_z, lambda_z_intercept, lambda_z_r2, lambda_z_stderr (lambda_z_r2_adj, lambda_z_n_points, lambda_z_t_first are new) |
p_value, max_idx |
dropped |
vd |
vz (iv) or vz_f (extravascular) |
vdss |
vss |
cl |
cl (iv) or cl_f (extravascular) |
dose |
dose_amount of the batch; auc_inf_dn, cmax_dn are the dose normalized values |
info() |
to_dataframe(), to_quantities(), flags() |
figure() |
plot_nca(timecourse, result) |
The defaults changed: the terminal phase is chosen by the best adjusted R² of at least three points after cmax, and the area uses the linear-up/log-down trapezoid. The numbers of 0.3.1 are reproduced with
from pkpdutils.nca import AUCMethod, NCAOptions, TerminalMethod, TerminalPhase
options = NCAOptions(
auc_method=AUCMethod.LINEAR,
terminal=TerminalPhase(method=TerminalMethod.ALL_AFTER_TMAX),
)
result = nca_single(tc, options)which is what tests/nca/test_reference.py checks against the frozen results of 0.3.1.
The effect analysis of pkdb_analysis.reports.effect_analysis (OutputPair, fixed_effect, random_effects) is pkpdutils.stats.meta (effect_size, fixed_effect, random_effects, meta_analysis); the pairs are Study(label, control, treatment) objects built from ParameterSample values or summary statistics.
Your pkpdutils team
0.3.1
Release notes for pkdb-analysis 0.3.1
We are pleased to release the next version of sbmlutils including the
following changes:
- warnings to info on pharmacokinetics calculation
- support python 3.10, 3.11, 3.12, 3.13
- updated build system with uv and ruff
- fixed tests
Your pkdb-analysis team
0.2.2
Release notes for pkdb-analysis 0.2.2
New features
Fixes
- updated dependencies for compatibility with
sbmlutilsandsbmlsim - cleanup code and tests
- bugfixes
Deprecated features
0.2.1
Release notes for pkdb-analysis 0.2.1
New features
Fixes
- updated dependencies for compatibility with
sbmlutilsandsbmlsim - cleanup code and tests
- bugfixes
Deprecated features
0.2.0
0.1.6
Release notes for pkdb-analysis 0.1.6
New features
- python 3.8 support
- github actions CI-CD
- isort and black support
- tox testing support
Fixes
Deprecated features
- travis CI
pkdb-analysis-v0.1.6a2
version bump for release