Skip to main content Skip to complementary content

Examples of how to use chi2-test functions in charts

The chi2-test functions are used to find values associated with chi squared statistical analysis. This section describes how to build charts using sample data to find the values of the chi-squared distribution test functions available in QlikView. Please refer to the individual chi2-test chart function topics for descriptions of syntax and arguments.

Loading the data for the samples

There are three sets of sample data describing three different statistical samples to be loaded into the script.

Do the following:

  1. Create a new document.
  2. Select Edit Script in the toolbar and enter the following to the script:

    // Sample_1 data is pre-aggregated... Note: make sure you set your DecimalSep='.' at the top of the script.

    Sample_1:

    LOAD * inline [

    Grp,Grade,Count

    I,A,15

    I,B,7

    I,C,9

    I,D,20

    I,E,26

    I,F,19

    II,A,10

    II,B,11

    II,C,7

    II,D,15

    II,E,21

    II,F,16

    ];

    // Sample_2 data is pre-aggregated: If raw data is used, it must be aggregated using count()...

    Sample_2:

    LOAD * inline [

    Sex,Opinion,OpCount

    1,2,58

    1,1,11

    1,0,10

    2,2,35

    2,1,25

    2,0,23 ] (delimiter is ',');

    // Sample_3a data is transformed using the crosstable statement...

    Sample_3a:

    crosstable(Gender, Actual) LOAD

    Description,

    [Men (Actual)] as Men,

    [Women (Actual)] as Women;

    LOAD * inline [

    Men (Actual),Women (Actual),Description

    58,35,Agree

    11,25,Neutral

    10,23,Disagree ] (delimiter is ',');

    // Sample_3b data is transformed using the crosstable statement...

    Sample_3b:

    crosstable(Gender, Expected) LOAD

    Description,

    [Men (Expected)] as Men,

    [Women (Expected)] as Women;

    LOAD * inline [

    Men (Expected),Women (Expected),Description

    45.35,47.65,Agree

    17.56,18.44,Neutral

    16.09,16.91,Disagree ] (delimiter is ',');

    // Sample_3a and Sample_3b will result in a (fairly harmless) Synthetic Key...

  3. Save the script and click Reload to load the data.

Creating the chi2-test chart function charts

Example: Sample 1

Do the following:

  1. Add a table box to the sheet and add Grp, Grade, and Count as dimensions.

    This table shows the sample data.

  2. Add straight table with the following calculated dimension:

    ValueList('p','df','Chi2')

    This uses the synthetic dimensions function to create labels for the dimensions with the names of the three chi2-test functions.

  3. Add the following expression:

    IF(ValueList('p','df','Chi2')='p',Chi2Test_p(Grp,Grade,Count),

    IF(ValueList('p','df','Chi2')='df',Chi2Test_df(Grp,Grade,Count),

    Chi2Test_Chi2(Grp,Grade,Count)))

    This has the effect of putting the resulting value of each chi2-test function in the table next to its associated synthetic dimension.

  4. Set the number format setting of the expression to Number and Precision to 3.
Tip noteIn the expression, you could use the following expression instead:
Pick(Match(ValueList('p','df','Chi2'),'p','df','Chi2'),Chi2Test_p(Grp,Grade,Count),Chi2Test_df(Grp,Grade,Count),Chi2Test_Chi2(Grp,Grade,Count))

Result:

The resulting table for the chi2-test functions for the Sample 1 data will contain the following values:

Example results
p df Chi2
0.820 5 2.21

Example: Sample 2

Do the following:

  1. Add another table box to the sheet with Sex, Opinion, and OpCount as dimensions.
  2. Make a copy of the results straight table from Sample 1 using the Copy to Clipboard:/Object and Paste Sheet Object commands. Edit the expression and replace the arguments in all three chi2-test functions with the names of the fields used in the Sample 2 data, for example: Chi2Test_p(Sex,Opinion,OpCount).

Result:

The resulting table for the chi2-test functions for the Sample 2 data will contain the following values:

Example results
p df Chi2
0.000309 2 16.2

Example: Sample 3

Do the following:

  1. Create one more table box and one more straight table in the same way as in the examples for Sample 1 and Sample 2 data. In the table box, use the following fields as dimensions: Gender, Description, Actual, and Expected.
  2. In the results straight table, use the names of the fields used in the Sample 3 data, for example: Chi2Test_p(Gender,Description,Actual,Expected).

Result:

The resulting table for the chi2-test functions for the Sample 3 data will contain the following values:

Example results
p df Chi2
0.000308 2 16.2

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!

Join the Analytics Modernization Program

Remove banner from view

Modernize without compromising your valuable QlikView apps with the Analytics Modernization Program. Click here for more information or reach out: ampquestions@qlik.com