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.

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:

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:

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:

Description,

[Men (Actual)] as Men,

[Women (Actual)] as Women;

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:

Description,

[Men (Expected)] as Men,

[Women (Expected)] as Women;

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...

Creating the chi2-test chart function charts

Example: Sample 1

Do the following:

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.

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: In the expression, you could use the following expression instead:

Result:

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

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:

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:

p df Chi2
0.000308 2 16.2