R: Chi-Squared Distribution
Code Only
|
Code with Rweb Output
|
### required to use function chisq.detail
library(TeachingDemos) ### required to use function xchisq.test library(mosaic) ### For this example, we will be using the respiratory data ### set, this data set comes from the HSAUR library library(HSAUR); data(respiratory); attach(respiratory) head(respiratory) data.table=table(treatment, sex) data.table xchisq.test(data.table) ### From mosaic library chisq.detail(data.table) ### From TeachingDemos Library chisq.test(data.table) ### Plain Chisq.test - Not that useful |
> ### required to use function chisq.detail
> library(TeachingDemos) > > ### required to use function xchisq.test > library(mosaic) > > ### For this example, we will be using the respiratory data > ### set, this data set comes from the HSAUR library > library(HSAUR); data(respiratory); attach(respiratory) > > head(respiratory) centre treatment sex age status month subject 1 1 placebo female 46 poor 0 1 112 1 placebo female 46 poor 1 1 223 1 placebo female 46 poor 2 1 334 1 placebo female 46 poor 3 1 445 1 placebo female 46 poor 4 1 2 1 placebo female 28 poor 0 2 > > data.table=table(treatment, sex) > > data.table sex treatment female male placebo 200 85 treatment 240 30 > > xchisq.test(data.table) ### From mosaic library Pearson's Chi-squared test with Yates' continuity correction data: data.table X-squared = 28.4287, df = 1, p-value = 9.721e-08 200 85 (225.95) ( 59.05) [ 2.98] [11.40] <-1.73> < 3.38> 240 30 (214.05) ( 55.95) [ 3.14] [12.03] < 1.77> <-3.47> key: observed (expected) [contribution to X-squared] <residual> > > chisq.detail(data.table) ### From TeachingDemos Library observed expected female male Total placebo 200 85 285 225.95 59.05 treatment 240 30 270 214.05 55.95 Total 440 115 555 Cell Contributions female male placebo 2.98 + 11.40 + treatment 3.14 + 12.03 = 29.56 df = 1 P-value = 0 > > chisq.test(data.table) ### Plain Chisq.test - Not that useful Pearson's Chi-squared test with Yates' continuity correction data: data.table X-squared = 28.4287, df = 1, p-value = 9.721e-08 |