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

727d5bea-05f2-427e-9da5-23c0f7d967e8.png

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: 

11b307b4-476e-47e6-9ef3-1be8f1985e14.png

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 0 230
0 REPLIES 0
Top Labels in this Space