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<usize>,
pub out: Option<f64>,
pub outeq: Option<usize>,
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 a single data row
This struct represents the canonical fields needed to create pharmsol Events.
Consumers construct this from their source data (regardless of column names),
then call into_events() to get properly parsed
Events with full ADDL expansion, EVID handling, censoring, etc.
§Fields
All fields use Pmetrics conventions:
inputandouteqare 1-indexed (kept as-is, user must size arrays accordingly)evid: 0=observation, 1=dose, 4=reset/new occasionaddl: positive=forward in time, negative=backward in time
§Example
use pharmsol::data::parser::DataRow;
// Observation row
let obs = DataRow::builder("pt1", 1.0)
.evid(0)
.out(25.5)
.outeq(1)
.build();
// Dosing row with negative ADDL (doses before time 0)
let dose = DataRow::builder("pt1", 0.0)
.evid(1)
.dose(100.0)
.input(1)
.addl(-10) // 10 doses BEFORE time 0
.ii(12.0)
.build();
let events = dose.into_events().unwrap();
// Events at times: -120, -108, -96, ..., -12, 0
assert_eq!(events.len(), 11);Fields§
§id: StringSubject identifier (required)
time: f64Event time (required)
evid: i32Event 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<usize>Input compartment
out: Option<f64>Observed value (for EVID=0)
outeq: Option<usize>Output equation number
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
impl DataRow
pub fn builder(id: impl Into<String>, time: f64) -> DataRowBuilder
pub fn builder(id: impl Into<String>, time: f64) -> DataRowBuilder
pub fn into_events(self) -> Result<Vec<Event>, DataError>
pub fn into_events(self) -> Result<Vec<Event>, DataError>
Convert this row into pharmsol Events
This method contains all the complex parsing 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
§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
doseandinput; ifdur > 0, it’s an infusion
§Example
use pharmsol::data::parser::DataRow;
let row = DataRow::builder("pt1", 0.0)
.evid(1)
.dose(100.0)
.input(1)
.addl(2)
.ii(24.0)
.build();
let events = row.into_events().unwrap();
assert_eq!(events.len(), 3); // doses at 24, 48, and 0
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>
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
pub fn is_occasion_reset(&self) -> bool
Check if this row represents a new occasion (EVID=4)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DataRow
impl RefUnwindSafe for DataRow
impl Send for DataRow
impl Sync for DataRow
impl Unpin for DataRow
impl UnwindSafe for DataRow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Context for T
impl<T> Context for T
fn vector_from_element<V>(&self, len: usize, value: <V as VectorCommon>::T) -> Vwhere
V: Vector<C = Self>,
fn vector_from_vec<V>(&self, vec: Vec<<V as VectorCommon>::T>) -> Vwhere
V: Vector<C = Self>,
fn vector_zeros<V>(&self, len: usize) -> Vwhere
V: Vector<C = Self>,
fn dense_mat_zeros<V>(
&self,
rows: usize,
cols: usize,
) -> <V as DefaultDenseMatrix>::Mwhere
V: Vector<C = Self> + DefaultDenseMatrix,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.