Home > database > ensemble_qid_x_qid_chi2.m

ensemble_qid_x_qid_chi2

PURPOSE ^

Calculates Pearson's chi-squared goodness of fit test for data in an ensemble_qid_x_qid_table

SYNOPSIS ^

function an_st = ensemble_qid_x_qid_chi2(data,params)

DESCRIPTION ^

 Calculates Pearson's chi-squared goodness of fit test for data in an ensemble_qid_x_qid_table
 
 this script could probably be a bit fancier, but at the moment provides
 simple functionality to calculate goodness of fit between two qids tabulated
 using ensemble_qid_x_qid_table.m

 see also http://en.wikipedia.org/wiki/Pearson%27s_chi-square_test

 ARGUMENTS
  data - the results of ensemble_qid_x_qid_table
  params - at this point, nothing from params is used in this script
 RETURNS
  an_st -

 FB 11/20/2007

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function an_st = ensemble_qid_x_qid_chi2(data,params)
0002 
0003 % Calculates Pearson's chi-squared goodness of fit test for data in an ensemble_qid_x_qid_table
0004 %
0005 % this script could probably be a bit fancier, but at the moment provides
0006 % simple functionality to calculate goodness of fit between two qids tabulated
0007 % using ensemble_qid_x_qid_table.m
0008 %
0009 % see also http://en.wikipedia.org/wiki/Pearson%27s_chi-square_test
0010 %
0011 % ARGUMENTS
0012 %  data - the results of ensemble_qid_x_qid_table
0013 %  params - at this point, nothing from params is used in this script
0014 % RETURNS
0015 %  an_st -
0016 %
0017 % FB 11/20/2007
0018 
0019 an_st = {};
0020 na = 0;
0021 
0022 dcols = set_var_col_const(data{1}.vars);
0023 eqxq_tbls = data{1}.data{dcols.count};
0024 
0025 il = length(eqxq_tbls(:,1,1));
0026 jl = length(eqxq_tbls(1,:,1));
0027 
0028 df = (il-1)*(jl-1);
0029 chi2 = 0;
0030 
0031 ctbl = zeros(il,jl);
0032 ctbli = zeros(il);
0033 ctblj = zeros(jl);
0034 cttl = sum(sum(sum(eqxq_tbls)));
0035 
0036 for ii=1:il
0037     ctbli(ii) = sum(sum(eqxq_tbls(ii,:,:)));
0038     for ij=1:jl
0039         ctblj(ij) = sum(sum(eqxq_tbls(:,ij,:)));
0040         ctbl(ii,ij) = sum(eqxq_tbls(ii,ij,:));
0041         chi2e = (ctbli(ii)*ctblj(ij))/cttl;
0042         chi2 = chi2 + (ctbl(ii,ij)-chi2e)^2/chi2e;
0043     end
0044 end
0045 
0046 na=na+1;
0047 an_st{na} = init_analysis_struct;
0048 an_st{na}.type = 'ensemble_qid_x_qid_chi2';
0049 an_st{na}.vars = {'chi2','df'};
0050 an_cols = set_var_col_const(an_st{na}.vars);
0051 an_st{na}.data = {};
0052 an_st{na}.data{an_cols.chi2} = chi2;
0053 an_st{na}.data{an_cols.df} = df;
0054 
0055 function an_st = init_analysis_struct
0056   an_st.type = '';
0057   an_st.vars = {};
0058   an_st.data = {};
0059   an_st.meta = [];
0060

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003