pub struct Formula {
pub dependent: String,
pub independents: Vec<String>,
pub intercept: bool,
}Expand description
Represents a parsed formula in the form “y ~ x1 + x2 + … + xn”
§Interaction Terms (v0.3.0)
x1 * x2: Full interaction (expands to x1 + x2 + x1:x2)x1 : x2: Only the interaction term (x1 × x2)
§Categorical Variables (NEW in v0.4.0)
C(var): Categorical encoding (creates dummies, drops first level)
§Polynomial Terms (NEW in v0.4.0)
I(x^2): Polynomial terms (e.g., squared, cubed)
Fields§
§dependent: StringName of the dependent variable (left-hand side)
independents: Vec<String>Names of independent variables (right-hand side) May include:
- Regular variables: “x1”
- Interactions: “x1:x2”
- Categorical: “C(region)”
- Polynomials: “I(x^2)”
intercept: boolWhether to include an intercept (default: true)
Implementations§
Source§impl Formula
impl Formula
Sourcepub fn parse(formula: &str) -> Result<Formula, GreenersError>
pub fn parse(formula: &str) -> Result<Formula, GreenersError>
Parse a formula string in the R/Python style: “y ~ x1 + x2 + x3”
§Syntax
- Basic: “y ~ x1 + x2 + x3” (with intercept)
- No intercept: “y ~ x1 + x2 + x3 - 1” or “y ~ 0 + x1 + x2”
- Intercept only: “y ~ 1”
- Full interaction: “y ~ x1 * x2” (expands to x1 + x2 + x1:x2)
- Interaction only: “y ~ x1 : x2” (only the interaction term)
- Categorical: “y ~ C(region)” (creates dummies)
- Polynomial: “y ~ I(x^2)” or “y ~ I(x**2)” (power terms)
§Examples
use greeners_core::formula::Formula;
let f = Formula::parse("fte ~ tratado + t + effect").unwrap();
assert_eq!(f.dependent, "fte");
assert_eq!(f.independents, vec!["tratado", "t", "effect"]);
assert_eq!(f.intercept, true);
let f2 = Formula::parse("y ~ x1 + x2 - 1").unwrap();
assert_eq!(f2.intercept, false);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Formula
impl RefUnwindSafe for Formula
impl Send for Formula
impl Sync for Formula
impl Unpin for Formula
impl UnsafeUnpin for Formula
impl UnwindSafe for Formula
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
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> ⓘ
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 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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SendAlias for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.