# Examples of how to use chi2-test functions in the load script

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

This example uses a table containing the number of students achieving a grade (A-F) for two groups of students (I and II).

chi2-test example

| - | A | B | C | D | E | F |
| --- | --- | --- | --- | --- | --- | --- |
| I | 15 | 7 | 9 | 20 | 26 | 19 |
| II | 10 | 11 | 7 | 15 | 21 | 16 |

## Loading the sample data

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` `];`

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

You have now loaded the sample data.

## Loading the chi2-test function values

Now we will load the chi2-test values based on the sample data in a new table, grouped by Grp.

Do the following:

1. Select Edit Script in the toolbar and add the following to end of the script:

   `// Sample_1 data is pre-aggregated... Note: make sure you set your DecimalSep='.' at the top of the script.` `Chi2_table:` `LOAD
   Grp,
   ` `Chi2Test_chi2(Grp, Grade, Count) as chi2,
   ` `Chi2Test_df(Grp, Grade, Count) as df,
   ` `Chi2Test_p(Grp, Grade, Count) as p
   ` `resident Sample_1 group by Grp;`

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

You have now loaded the chi2-test values in a table named Chi2\_table.

## Results

You can view the resulting chi2-test values in the table viewer, they should look like this:

chi2-test results

| Grp | chi2 | df | p |
| --- | --- | --- | --- |
| I | 16.00 | 5 | 0.007 |
| II | 9.40 | 5 | 0.094 |