pub fn ratio_events_greater_pval_n(
            num_events_one_baseline:usize,
            num_events_two_baseline:usize,
            num_baseline_group:usize,
            num_events_one_treatment:usize,
            num_events_two_treatment:usize,
            num_treatment_group:usize,
            num_samples:usize,
        ) -> Result<f64, &'static str>
        {
            if num_events_one_treatment == 0 && num_events_two_treatment == 0 {
                return Err("Err creating test statistic: Treatment event ratio 0/0 is uncomparable")
            }
            if num_events_one_baseline == 0 {
                return Err("Event one does not occur in baseline, assumption of poisson distribution is violated");
            }
            if num_events_two_baseline == 0 {
                return Err("Event two does not occur in baseline, assumption of poisson distribution is violated");
            }
            let t_stat:f64 = match (num_events_one_treatment,num_events_two_treatment)
            {
             // (0,0)=> num_events_one_treatment as f64 /num_events_two_treatment as f64  
             //       - num_events_one_baseline as f64  /num_events_two_baseline  as f64,
                (_,_)=> num_events_one_treatment as f64 /num_events_two_treatment as f64  
                      - num_events_one_baseline as f64  /num_events_two_baseline  as f64,
            };
            //we're going to try to handle infinities ... 
            //generate baseline distribution of size num_baseline_group + num_treatment_group
            //seperate and calculate # events 1 and 2 for both populations
            //
            let rate_one_baseline:f64 = num_events_one_baseline as f64 / num_baseline_group as f64;
            let rate_two_baseline:f64 = num_events_two_baseline  as f64/ num_baseline_group as f64;
            let p_one = rand_Poisson::new(rate_one_baseline).unwrap();
            let p_two = rand_Poisson::new(rate_two_baseline).unwrap();
            let p_val = (0..num_samples).into_par_iter().map(|_| 
                {
                let occ_b_one:f64 = p_one.sample_iter(&mut rand::thread_rng()).take(num_baseline_group).sum();
                let occ_b_two:f64 = p_two.sample_iter(&mut rand::thread_rng()).take(num_baseline_group).sum();
                let occ_t_one:f64 = p_one.sample_iter(&mut rand::thread_rng()).take(num_treatment_group).sum();
                let occ_t_two:f64 = p_two.sample_iter(&mut rand::thread_rng()).take(num_treatment_group).sum();
                let ti = occ_t_one / occ_t_two - occ_b_one/occ_b_two;
                if occ_t_two == 0.0 {
                    return 1.0/(num_samples as f64)
                }else if ti>t_stat{
                    return 1.0/(num_samples as f64)
                } 0.0
            }
            ).sum();
            Ok(p_val)
        }
/// Hypothesis test R1/R2 under condition 1 > R1/R2 without constraint 
/// and return the p-value.  where R1 = #events of type 1 / #trials and
/// R2 = #events of type 2 / #trials 
/// 
/// We assume two populations, one of which had some difference, and
/// we're trying to see if it affected the ratio of the occurances of
/// these two events.
/// 
/// We're using boostrap methods (computationally more expensive, but
/// not bad)
/// 
/// One caveat: If # events_1 and # events_2 under treatment are both 0
/// (neither events occurred under treatment), that is considered a
/// viable event and is compared to the occurances of 0/0 in baseline
/// samples.
Hypothesis test R1/R2 under condition 1 > R1/R2 without constraint
and return the p-value.  where R1 = #events of type 1 / #trials and
R2 = #events of type 2 / #trials

We assume two populations, one of which had some difference, and
we're trying to see if it affected the ratio of the occurances of
these two events.

We're using boostrap methods (computationally more expensive, but
not bad)

One caveat: If # events_1 and # events_2 under treatment are both 0
(neither events occurred under treatment), that is considered a
viable event and is compared to the occurances of 0/0 in baseline
samples.
Hypothesis test R1 / R2 under condition 1 > R1 / R2 without constraint and return the p - value . where R1 = #events of type 1 / #trials and R2 = #events of type 2 / #trials We assume two populations one of which had some difference and we ' re trying to see if it affected the ratio of the occurances of these two events . We ' re using boostrap methods ( computationally more expensive but not bad ) One caveat : If # events_1 and # events_2 under treatment are both 0 ( neither events occurred under treatment ) that is considered a viable event and is compared to the occurances of 0 / 0 in baseline samples .
pub fn ratio_events_greater_pval_n(
            num_events_one_baseline:usize,
            num_events_two_baseline:usize,
            num_baseline_group:usize,
            num_events_one_treatment:usize,
            num_events_two_treatment:usize,
            num_treatment_group:usize,
            num_samples:usize,
        ) -> Result<f64, &'static str>
        {
            if num_events_one_treatment == 0 && num_events_two_treatment == 0 {
                return Err("Err creating test statistic: Treatment event ratio 0/0 is uncomparable")
            }
            if num_events_one_baseline == 0 {
                return Err("Event one does not occur in baseline, assumption of poisson distribution is violated");
            }
            if num_events_two_baseline == 0 {
                return Err("Event two does not occur in baseline, assumption of poisson distribution is violated");
            }
            let t_stat:f64 = match (num_events_one_treatment,num_events_two_treatment)
            {
             // (0,0)=> num_events_one_treatment as f64 /num_events_two_treatment as f64  
             //       - num_events_one_baseline as f64  /num_events_two_baseline  as f64,
                (_,_)=> num_events_one_treatment as f64 /num_events_two_treatment as f64  
                      - num_events_one_baseline as f64  /num_events_two_baseline  as f64,
            };
            //we're going to try to handle infinities ... 
            //generate baseline distribution of size num_baseline_group + num_treatment_group
            //seperate and calculate # events 1 and 2 for both populations
            //
            let rate_one_baseline:f64 = num_events_one_baseline as f64 / num_baseline_group as f64;
            let rate_two_baseline:f64 = num_events_two_baseline  as f64/ num_baseline_group as f64;
            let p_one = rand_Poisson::new(rate_one_baseline).unwrap();
            let p_two = rand_Poisson::new(rate_two_baseline).unwrap();
            let p_val = (0..num_samples).into_par_iter().map(|_| 
                {
                let occ_b_one:f64 = p_one.sample_iter(&mut rand::thread_rng()).take(num_baseline_group).sum();
                let occ_b_two:f64 = p_two.sample_iter(&mut rand::thread_rng()).take(num_baseline_group).sum();
                let occ_t_one:f64 = p_one.sample_iter(&mut rand::thread_rng()).take(num_treatment_group).sum();
                let occ_t_two:f64 = p_two.sample_iter(&mut rand::thread_rng()).take(num_treatment_group).sum();
                let ti = occ_t_one / occ_t_two - occ_b_one/occ_b_two;
                if occ_t_two == 0.0 {
                    return 1.0/(num_samples as f64)
                }else if ti>t_stat{
                    return 1.0/(num_samples as f64)
                } 0.0
            }
            ).sum();
            Ok(p_val)
        }
pub fn ratio_events_greater_pval_n ( num_events_one_baseline : usize , num_events_two_baseline : usize , num_baseline_group : usize , num_events_one_treatment : usize , num_events_two_treatment : usize , num_treatment_group : usize , num_samples : usize , ) -> Result < f64 , & ' static str > { if num_events_one_treatment == 0 && num_events_two_treatment == 0 { return Err ( " " ) } if num_events_one_baseline == 0 { return Err ( " " ) ; } if num_events_two_baseline == 0 { return Err ( " " ) ; } let t_stat : f64 = match ( num_events_one_treatment , num_events_two_treatment ) { // (0,0)=> num_events_one_treatment as f64 /num_events_two_treatment as f64   //       - num_events_one_baseline as f64  /num_events_two_baseline  as f64, ( _ , _ ) => num_events_one_treatment as f64 / num_events_two_treatment as f64 - num_events_one_baseline as f64 / num_events_two_baseline as f64 , } ; //we're going to try to handle infinities ...  //generate baseline distribution of size num_baseline_group + num_treatment_group //seperate and calculate # events 1 and 2 for both populations // let rate_one_baseline : f64 = num_events_one_baseline as f64 / num_baseline_group as f64 ; let rate_two_baseline : f64 = num_events_two_baseline as f64 / num_baseline_group as f64 ; let p_one = rand_Poisson :: new ( rate_one_baseline ) . unwrap ( ) ; let p_two = rand_Poisson :: new ( rate_two_baseline ) . unwrap ( ) ; let p_val = ( 0 .. num_samples ) . into_par_iter ( ) . map ( | _ | { let occ_b_one : f64 = p_one . sample_iter ( & mut rand :: thread_rng ( ) ) . take ( num_baseline_group ) . sum ( ) ; let occ_b_two : f64 = p_two . sample_iter ( & mut rand :: thread_rng ( ) ) . take ( num_baseline_group ) . sum ( ) ; let occ_t_one : f64 = p_one . sample_iter ( & mut rand :: thread_rng ( ) ) . take ( num_treatment_group ) . sum ( ) ; let occ_t_two : f64 = p_two . sample_iter ( & mut rand :: thread_rng ( ) ) . take ( num_treatment_group ) . sum ( ) ; let ti = occ_t_one / occ_t_two - occ_b_one / occ_b_two ; if occ_t_two == 0.0 { return 1.0 / ( num_samples as f64 ) } else if ti > t_stat { return 1.0 / ( num_samples as f64 ) } 0.0 } ) . sum ( ) ; Ok ( p_val ) }
Hypothesis test R1/R2 under condition 1 > R1/R2 without constraint
and return the p-value.
Hypothesis test R1 / R2 under condition 1 > R1 / R2 without constraint and return the p - value .
num_events_one_baseline
usize
num_events_two_baseline
usize
num_baseline_group
usize
num_events_one_treatment
usize
num_events_two_treatment
usize
num_treatment_group
usize
num_samples
usize
num_events_one_baseline
usize
num_events_two_baseline
usize
num_baseline_group
usize
num_events_one_treatment
usize
num_events_two_treatment
usize
num_treatment_group
usize
num_samples
usize