Login    Register

XLeratorDB/statistics Documentation

CHISQN


CHISQN

Updated: 6 August 2010

Use CHISQN to calculate the chi-square (χ2) statistic for normalized tables. This function calculates the chi-square statistic by finding the difference between each observed and theoretical frequency for each possible outcome, squaring them, dividing each by the theoretical frequency, and taking the sum of the results. A second important part of determining the test statistic is to define the degrees of freedom of the test: this is essentially the number of squares errors involving the observed frequencies adjusted for the effect of using some of those observations to define the expected frequencies.
 
CHISQN automatically calculates the expected results.
 
The value of the chi-square statistic is:

 

Where
                r              is the number of rows
                c              is the number of columns
                O             is the Observed result
                E              is the Expected result
Syntax
SELECT [wctStatistics].[wct].[CHISQN] (
  <@Actual_range_TableName, nvarchar(4000),>
 ,<@Key1Columnname, nvarchar(4000),>
 ,<@Key2ColumnName, nvarchar(4000),>
 ,<@DataColumnName, nvarchar(4000),>
 ,<@GroupedColumnName, nvarchar(4000),>
 ,<@GroupedColumnValue, sql_variant,>)
Arguments
@Actual_range_TableName
the name, as text, of the table or view that contains the observed values to be used in the calculation.
@Key1ColumnName
the name, as text, of the first column in the normalized table or view specified by @Actual_range_TableName that identifies the actual, or observed, results to be used in the calculation.
@Key2ColumnName
the name, as text, of the second column in the normalized table or view specified by @Actual_range_TableName that identifies the actual, or observed, values to be used in the calculation.
@GroupedColumnName
the name, as text, of the column in the table or view specified by @Actual_range_TableName which will be used for grouping the results.
@GroupedColumnValue
the column value to do the grouping on.
Return Types
float
Remarks
·         CHISQN is designed for normalized tables. For de-normalized tables, use the CHISQ function.
·         CHISQN automatically calculates the expected values. If you want to enter the expected values use the CHISQN2 function.
·         For queries that are more complex, consider using the CHISQN_q function.
·         No GROUP BY is required for this function even though it produces aggregated results.
Examples
In this hypothetical situation, we want to determine if there is an association between population density and the preference for a sport from among baseball, football, and basketball. We will use the CHISQ function to calculate the chi-squared statistic.
CREATE TABLE #chin(
      [Sport]           [varchar] (20) NOT NULL,
      [Locale]    [varchar] (20) NOT NULL,
      [Result]    [float] NOT NULL
)
INSERT INTO #CHIN VALUES ('Basketball', 'Rural', 28)
INSERT INTO #CHIN VALUES ('Basketball', 'Suburban', 35)
INSERT INTO #CHIN VALUES ('Basketball', 'Urban', 54)
INSERT INTO #CHIN VALUES ('Baseball', 'Rural', 60)
INSERT INTO #CHIN VALUES ('Baseball', 'Suburban', 43)
INSERT INTO #CHIN VALUES ('Baseball', 'Urban', 35)
INSERT INTO #CHIN VALUES ('Football', 'Rural', 52)
INSERT INTO #CHIN VALUES ('Football', 'Suburban', 48)
INSERT INTO #CHIN VALUES ('Football', 'Urban', 28)
 
SELECT wct.CHISQN(
 '#chin'
,'Sport'
,'Locale'
,'Result'
,''
,NULL)
This produces the following result
----------------------
22.451703426585
 

(1 row(s) affected)



  Comments
Add Comment
No Comments Yet


 |  View Topic History  |
Copyright 2010 WestClinTech LLC         Privacy Policy        Terms of Service