Skip to main content

DataRow

Struct DataRow 

pub struct DataRow {
Show 16 fields pub id: String, pub time: f64, pub evid: i32, pub dose: Option<f64>, pub dur: Option<f64>, pub addl: Option<i64>, pub ii: Option<f64>, pub input: Option<InputLabel>, pub out: Option<f64>, pub outeq: Option<OutputLabel>, pub cens: Option<Censor>, pub c0: Option<f64>, pub c1: Option<f64>, pub c2: Option<f64>, pub c3: Option<f64>, pub covariates: HashMap<String, f64>,
}
Expand description

A format-agnostic representation of one input row.

DataRow collects the canonical fields needed to turn one external row into one or more Event values.

Build this type from your own column mapping or external schema, then call DataRow::into_events or [build_data] to assemble subjects and datasets.

A single row can expand into several events when ADDL and II are both present.

§Fields

All fields use the public labeling conventions:

  • input and outeq preserve the route and output labels from the source data
  • evid: 0=observation, 1=dose, 4=reset/new occasion
  • addl: positive=forward in time, negative=backward in time

§Example

use pharmsol::data::parser::DataRow;

let obs = DataRow::builder("pt1", 1.0)
    .evid(0)
    .out(25.5)
    .outeq("cp")
    .build();

let dose = DataRow::builder("pt1", 0.0)
    .evid(1)
    .dose(100.0)
    .input("iv")
    .addl(-10)
    .ii(12.0)
    .build();

let events = dose.into_events().unwrap();
assert_eq!(obs.outeq.as_ref().map(|label| label.as_str()), Some("cp"));
assert_eq!(events.len(), 11);

Fields§

§id: String

Subject identifier (required)

§time: f64

Event time (required)

§evid: i32

Event type: 0=observation, 1=dose, 4=reset/new occasion

§dose: Option<f64>

Dose amount (for EVID=1)

§dur: Option<f64>

Infusion duration (if > 0, dose is infusion; otherwise bolus)

§addl: Option<i64>

Additional doses count (positive=forward, negative=backward in time)

§ii: Option<f64>

Interdose interval for ADDL

§input: Option<InputLabel>

Input route label

§out: Option<f64>

Observed value (for EVID=0)

§outeq: Option<OutputLabel>

Output label

§cens: Option<Censor>

Censoring indicator

§c0: Option<f64>

Error polynomial coefficients

§c1: Option<f64>

Error polynomial coefficients

§c2: Option<f64>

Error polynomial coefficients

§c3: Option<f64>

Error polynomial coefficients

§covariates: HashMap<String, f64>

Covariate values at this time point

Implementations§

§

impl DataRow

pub fn builder(id: impl Into<String>, time: f64) -> DataRowBuilder

Create a builder for constructing one DataRow.

§Arguments
  • id - Subject identifier
  • time - Event time
§Example
use pharmsol::data::parser::DataRow;

let row = DataRow::builder("patient_001", 0.0)
    .evid(1)
    .dose(100.0)
    .input("depot")
    .build();

pub fn into_events(self) -> Result<Vec<Event>, DataError>

Convert this row into one or more Event values.

This method performs the row-level translation logic:

  • EVID interpretation (0=observation, 1=dose, 4=reset)
  • ADDL/II expansion (both positive and negative directions)
  • Infusion vs bolus detection based on DUR
  • Censoring and error polynomial handling
  • Preservation of public input and output labels
§ADDL Expansion

When addl and ii are both specified:

  • Positive ADDL: Additional doses are placed after the base time
    • Example: time=0, addl=3, ii=12 → doses at 12, 24, 36, then 0
  • Negative ADDL: Additional doses are placed before the base time
    • Example: time=0, addl=-3, ii=12 → doses at -36, -24, -12, then 0
§Returns

A vector of Events. A single row may produce multiple events when ADDL is used.

§Errors

Returns [DataError] if required fields are missing for the given EVID:

  • EVID=0: Requires outeq
  • EVID=1: Requires dose and input; if dur > 0, it’s an infusion
§Example
use pharmsol::data::parser::DataRow;

let row = DataRow::builder("pt1", 0.0)
    .evid(1)
    .dose(100.0)
    .input("iv")
    .addl(2)
    .ii(24.0)
    .build();

let events = row.into_events().unwrap();
assert_eq!(events.len(), 3);

let times: Vec<f64> = events.iter().map(|e| e.time()).collect();
assert_eq!(times, vec![24.0, 48.0, 0.0]);

pub fn covariates(&self) -> &HashMap<String, f64>

Get the covariate values for this row

Returns a reference to the HashMap of covariate name → value pairs.

pub fn is_occasion_reset(&self) -> bool

Check if this row represents a new occasion (EVID=4)

pub fn id(&self) -> &str

Get the subject ID

pub fn time(&self) -> f64

Get the event time

Trait Implementations§

§

impl Clone for DataRow

§

fn clone(&self) -> DataRow

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 DataRow

§

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

Formats the value using the given formatter. Read more
§

impl Default for DataRow

§

fn default() -> DataRow

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

Auto Trait Implementations§

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

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
§

impl<T> Context for T
where T: Clone + Default,

§

fn vector_from_element<V>(&self, len: usize, value: <V as VectorCommon>::T) -> V
where V: Vector<C = Self>,

§

fn vector_from_vec<V>(&self, vec: Vec<<V as VectorCommon>::T>) -> V
where V: Vector<C = Self>,

§

fn vector_zeros<V>(&self, len: usize) -> V
where V: Vector<C = Self>,

§

fn dense_mat_zeros<V>( &self, rows: usize, cols: usize, ) -> <V as DefaultDenseMatrix>::M
where V: Vector<C = Self> + DefaultDenseMatrix,

§

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> 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
§

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,

§

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

§

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

§

impl<T> SendAlias for T

§

impl<T> SyncAlias for T