Chi-Square with tabulated data 2 by 2 table?
652774Jul 5 2012 — edited Jul 6 2012Hi- I'm looking at stats_crosstab to get a chi-square value and do not understand how to get it in with my data. What I want is the equivalant of this SAS crosstab:
Table of provider_or_peer by column
provider_or_peer column
Frequency ‚
Expected ‚
Deviation ‚
Cell Chi-Square‚
Percent ‚
Row Pct ‚
Col Pct ‚ 1‚ 2‚ Total
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
provider ‚ 1 ‚ 18 ‚ 19
‚ 0.9509 ‚ 18.049 ‚
‚ 0.0491 ‚ -0.049 ‚
‚ 0.0025 ‚ 0.0001 ‚
‚ 0.10 ‚ 1.77 ‚ 1.86
‚ 5.26 ‚ 94.74 ‚
‚ 1.96 ‚ 1.86 ‚
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
peer ‚ 50 ‚ 950 ‚ 1000
‚ 50.049 ‚ 949.95 ‚
‚ -0.049 ‚ 0.0491 ‚
‚ 481E-7 ‚ 253E-8 ‚
‚ 4.91 ‚ 93.23 ‚ 98.14
‚ 5.00 ‚ 95.00 ‚
‚ 98.04 ‚ 98.14 ‚
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ
Total 51 968 1019
5.00 95.00 100.00
the chi-square value in this case winds up being
Chi-Square 1 0.0027 0.9584
But the input data has the frequencies rather than the original values, so the input data looks like this:
provider_
or_peer column value
provider 1 1
provider 2 18
peer 1 50
peer 2 950
In SAS the code to get the chi-square from this data is this:
proc freq data=test3 order=data;
weight value;
tables provider_or_peer*column / chisq expected deviation CELLCHI2;
run;
But what I'm not seeing in Oracle stats_crosstab is how to get the value in for data setup like this; it takes two expressions and one value type, so I don't know how to get it to work on data like this- or is there a way to transform my data to get it to work?
For instance I see this question posted on the forums:
*********
In the following code, query 1 provides the correct answer and query 2 provides an incorrect answer. Any ideas?
-- query 1
select stats_crosstab (patient_unit, group_name, 'CHISQ_OBS') chisquare,
stats_crosstab (patient_unit, group_name) pvalue
, count(*)
from seps_random_pop srp;
-- query 2
select stats_crosstab (patient_unit, group_name, 'CHISQ_OBS') chisquare,
stats_crosstab (patient_unit, group_name) pvalue
from seps_random_pop srp;
*************
-Mary