Skip to main content

Data

Struct Data 

pub struct Data { /* private fields */ }
Expand description

The main data container for pharmacokinetic/pharmacodynamic data

Data is a collection of Subject instances, which themselves contain Occasion instances with Events. This structure represents the complete dataset for pharmacometric analysis.

§Examples

use pharmsol::*;

// Create subjects
let subject1 = Subject::builder("patient_001")
    .bolus(0.0, 100.0, 0)
    .observation(1.0, 5.0, 0)
    .build();
     
let subject2 = Subject::builder("patient_002")
    .bolus(0.0, 120.0, 0)
    .observation(1.0, 6.0, 0)
    .build();
     
// Create dataset with multiple subjects
let mut data = Data::new(vec![subject1]);
data.add_subject(subject2);

// Filter data
let filtered = data.filter_include(&["patient_001".to_string()]);

Implementations§

§

impl Data

pub fn to_pmetrics_csv_bytes(&self) -> Result<Vec<u8>, DataError>

Return the dataset as Pmetrics CSV bytes.

Occasions need not contain or start with a dose. Boundaries are written as EVID=3 (reset only), or EVID=4 when the first row is a dose. Empty occasions are preserved with an EVID=3 row at time zero. Covariate times without a dose or observation are written as EVID=2 rows. Doses expanded from ADDL/II input are written as individual rows.

Missing observations are written as OUT=-99; a real value of -99 cannot be represented.

pub fn write_pmetrics(&self, file: &File) -> Result<(), PharmsolError>

Replace the file contents with the bytes from Data::to_pmetrics_csv_bytes.

§

impl Data

pub fn from_pmetrics_csv_bytes(bytes: &[u8]) -> Result<Data, DataError>

Read Pmetrics CSV bytes into a dataset.

§

impl Data

pub fn new(subjects: Vec<Subject>) -> Data

Constructs a new Data object from a vector of Subjects

It is recommended to construct subjects using the [crate::data::builder::SubjectBuilder] to ensure proper data formatting.

§Arguments
  • subjects - Vector of Subjects to include in the dataset

pub fn subjects(&self) -> Vec<&Subject>

Get a vector of references to all subjects in the dataset

§Returns

Vector of references to all subjects

pub fn add_subject(&mut self, subject: Subject)

Add a subject to the dataset

§Arguments
  • subject - Subject to add to the dataset

pub fn get_subject(&self, id: &str) -> Option<&Subject>

Get a specific subject by ID

§Arguments
  • id - The ID of the subject to retrieve
§Returns

An Option containing a reference to the subject if found, or None if not found

pub fn get_subject_mut(&mut self, id: &str) -> Option<&mut Subject>

Get a mutable reference to a specific subject by ID

§Arguments
  • id - The ID of the subject to retrieve
§Returns

An Option containing a reference to the subject if found, or None if not found

pub fn filter_include(&self, include: &[String]) -> Data

Filter the dataset to include only subjects with specific IDs

§Arguments
  • include - Vector of subject IDs to include
§Returns

A new Data object containing only the specified subjects

pub fn filter_exclude(&self, exclude: Vec<String>) -> Data

Filter the dataset to exclude subjects with specific IDs

§Arguments
  • exclude - Vector of subject IDs to exclude
§Returns

A new Data object with the specified subjects excluded

pub fn expand(&self, idelta: f64, tad: f64) -> Data

Expand the dataset by adding observations at regular time intervals

This is useful for creating a dense grid of time points for simulations. Observations are only added if they don’t already exist at that time/outeq combination.

§Arguments
  • idelta - Time interval between added observations. Times are handled with microsecond resolution, so idelta must be at least 5e-7 (0.5 µs, which rounds up to 1 µs); any smaller positive value rounds to zero and the dataset is returned unchanged.
  • tad - Additional time to add after the last dose (time after dose)

The grid for each occasion starts at 0. If the occasion’s earliest event (dose or observation) is before 0, the grid instead starts at that event and continues from the next multiple of idelta, so the simulation still starts at the first real event and every later grid time is a multiple of idelta measured from t = 0. The grid ends at the last dose (or infusion end) of the occasion plus tad, inclusive.

§Returns

A new Data object with expanded observations

pub fn iter(&self) -> Iter<'_, Subject> ⓘ

Get an iterator over all subjects

§Returns

An iterator yielding references to subjects

pub fn iter_mut(&mut self) -> IterMut<'_, Subject> ⓘ

Get a mutable iterator over all subjects

§Returns

A mutable iterator yielding references to subjects

pub fn len(&self) -> usize

Get the number of subjects in the dataset

§Returns

The number of subjects

pub fn is_empty(&self) -> bool

Check if the dataset is empty

§Returns

true if there are no subjects, false otherwise

pub fn get_output_equations(&self) -> Vec<OutputLabel>

Get a vector of all unique output labels (outeq) across all subjects

Trait Implementations§

§

impl Clone for Data

§

fn clone(&self) -> Data

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Data

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Data

§

fn default() -> Data

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for Data

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Data, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Data

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl From<Subject> for Data

§

fn from(subject: Subject) -> Data

Convert a subject into a Data object

§

impl From<Vec<Subject>> for Data

§

fn from(subjects: Vec<Subject>) -> Data

Convert a vector of subjects into a Data object

§

impl IntoIterator for Data

§

fn into_iter(self) -> <Data as IntoIterator>::IntoIter

Consumes the data and yields owned subjects

§

type Item = Subject

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Subject>

Which kind of iterator are we turning this into?
§

impl<'a> IntoIterator for &'a Data

§

fn into_iter(self) -> <&'a Data as IntoIterator>::IntoIter

Iterate immutably over all subjects in the dataset

§

type Item = &'a Subject

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Subject>

Which kind of iterator are we turning this into?
§

impl<'a> IntoIterator for &'a mut Data

§

fn into_iter(self) -> <&'a mut Data as IntoIterator>::IntoIter

Iterate mutably over all subjects in the dataset

§

type Item = &'a mut Subject

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, Subject>

Which kind of iterator are we turning this into?
§

impl NCA for Data

§

fn nca(&self, options: &NCAOptions) -> Result<NCAResult, NCAError>

NCA on the first occasion (the common case). Returns a single result.
§

fn nca_all(&self, options: &NCAOptions) -> Vec<Result<NCAResult, NCAError>>

NCA on all occasions. Returns a Vec of results.
§

impl NCAPopulation for Data

§

fn nca_grouped(&self, options: &NCAOptions) -> Vec<SubjectNCAResult>

Perform NCA and return results grouped by subject Read more
§

impl ObservationMetrics for Data

§

fn auc_blq( &self, outeq: usize, method: &AUCMethod, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Calculate AUC from time 0 to Tlast with explicit BLQ handling
§

fn auc_interval_blq( &self, outeq: usize, start: f64, end: f64, method: &AUCMethod, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Calculate partial AUC over a time interval with explicit BLQ handling
§

fn cmax_blq( &self, outeq: usize, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Get Cmax with explicit BLQ handling
§

fn tmax_blq( &self, outeq: usize, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Get Tmax with explicit BLQ handling
§

fn clast_blq( &self, outeq: usize, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Get Clast with explicit BLQ handling
§

fn tlast_blq( &self, outeq: usize, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Get Tlast with explicit BLQ handling
§

fn aumc_blq( &self, outeq: usize, method: &AUCMethod, blq_rule: &BLQRule, ) -> Vec<Result<f64, MetricsError>>

Calculate AUMC with explicit BLQ handling
§

fn auc( &self, outeq: usize, method: &AUCMethod, ) -> Vec<Result<f64, MetricsError>>

Calculate AUC from time 0 to Tlast
§

fn auc_interval( &self, outeq: usize, start: f64, end: f64, method: &AUCMethod, ) -> Vec<Result<f64, MetricsError>>

Calculate partial AUC over a time interval
§

fn cmax(&self, outeq: usize) -> Vec<Result<f64, MetricsError>>

Get Cmax
§

fn tmax(&self, outeq: usize) -> Vec<Result<f64, MetricsError>>

Get Tmax
§

fn clast(&self, outeq: usize) -> Vec<Result<f64, MetricsError>>

Get Clast
§

fn tlast(&self, outeq: usize) -> Vec<Result<f64, MetricsError>>

Get Tlast
§

fn aumc( &self, outeq: usize, method: &AUCMethod, ) -> Vec<Result<f64, MetricsError>>

Calculate AUMC
§

fn auc_first( &self, outeq: usize, method: &AUCMethod, ) -> Result<f64, MetricsError>

Calculate AUC for the first occasion
§

fn cmax_first(&self, outeq: usize) -> Result<f64, MetricsError>

Get Cmax for the first occasion
§

fn tmax_first(&self, outeq: usize) -> Result<f64, MetricsError>

Get Tmax for the first occasion
§

fn clast_first(&self, outeq: usize) -> Result<f64, MetricsError>

Get Clast for the first occasion
§

fn tlast_first(&self, outeq: usize) -> Result<f64, MetricsError>

Get Tlast for the first occasion
§

fn aumc_first( &self, outeq: usize, method: &AUCMethod, ) -> Result<f64, MetricsError>

Calculate AUMC for the first occasion
§

fn auc_interval_first( &self, outeq: usize, start: f64, end: f64, method: &AUCMethod, ) -> Result<f64, MetricsError>

Calculate partial AUC for the first occasion
§

fn auc_blq_first( &self, outeq: usize, method: &AUCMethod, blq_rule: &BLQRule, ) -> Result<f64, MetricsError>

Calculate AUC for the first occasion with explicit BLQ handling
§

fn cmax_blq_first( &self, outeq: usize, blq_rule: &BLQRule, ) -> Result<f64, MetricsError>

Get Cmax for the first occasion with explicit BLQ handling
§

fn auc_interval_blq_first( &self, outeq: usize, start: f64, end: f64, method: &AUCMethod, blq_rule: &BLQRule, ) -> Result<f64, MetricsError>

Calculate partial AUC for the first occasion with explicit BLQ handling
§

impl Serialize for Data

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Data

§

impl RefUnwindSafe for Data

§

impl Send for Data

§

impl Sync for Data

§

impl Unpin for Data

§

impl UnsafeUnpin for Data

§

impl UnwindSafe for Data

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SendAlias for T

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<T> SyncAlias for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more