Question

How to stop Chi-Squared function from using null values?

  • 29 June 2022
  • 0 replies
  • 32 views

 

I would like to utilize the chi-squared built-in function to get p-values for each experiment (pivoted, in this example aa00 and aa01), when comparing expected vs observed values. However, if one experiment has more variants then the other (aa01 only has control and 1 variant), the chi-squared function thinks the null value is some input somehow and uses it in the calculation. 

The results are correct for aa00, but for aa01, it should be 0.014786. I assume that, as it is counting the null value of Variant 2 (that does not exist for aa01), it returns 0.051257 instead. I tried creating a dummy variable (non-null variant) and including an if statement within the chi-squared test, but it didn’t make any difference. 

 

It does work if I create a filter and filter only by aa01: 

 

But I would like to see all of them at the same time. 

 

Any tips on what could solve the issue?

 

 

Edit: The table calc I’m using is:


chisq_test(

${chi_square_example_dt.observed_measure},

${chi_square_example_dt.expected_measure}

)

 

If you want to reproduce the data, this is the view I’m using:
 

view: chi_square_example_dt {

derived_table: {

sql:

select 'aa00' as experimentId, 0 as variant, 188900 as observed, 188614 as expected,
union all
select 'aa00' as experimentId, 1 as variant, 187971 as observed, 188614 as expected,
union all
select 'aa00' as experimentId, 2 as variant, 188971 as observed, 188614 as expected,
union all
select 'aa01' as experimentId, 0 as variant, 177650 as observed, 176925 as expected,
union all
select 'aa01' as experimentId, 1 as variant, 176200 as observed, 176925 as expected


;;

}


dimension: experimentId {

type: string

sql: ${TABLE}.experimentId ;;

}


dimension: variant {

type: string

sql: ${TABLE}.variant ;;

}


measure: observed_measure {

type: sum

sql: ${TABLE}.observed ;;

}


measure: expected_measure {

type: sum

sql: ${TABLE}.expected ;;

}

}

 


0 replies

Be the first to reply!

Reply