0

I have a 4 by 4 tables. Rows corresponds to people group and columns are their decisions types. The ij of the table is the number of people type i who have decision type j.

                  decision 1  decision 2   decision 3   decision 4
people type 1      150          50            130          270       
people type 2      540          60            160          240
people type 3      530          70            170          230
people type 4      540          40            150          270

I would like to do a Tukey style proportion test which compares people type pairs. The expected output has to be a something like the following table.

                     p_value  
people type 1 & 2       X         
people type 1 & 3       X        
people type 1 & 4       X          
people type 2 & 3       X          
people type 2 & 4       X          
people type 3 & 4       X          
shayan
  • 11
  • 1

1 Answers1

0

Well since there is nothing named a "Tukey style proportion test", I can only assume you mean you would like adjusted p values because you are running multiple comparisons after a significant overall finding.

The rcompanion package has a function to allow you to do that and choose which one of the common r adjustment methods to use. My example uses holm

Input =("
People            'decision 1'  'decision 2'   'decision 3'   'decision 4'
'people type 1'      150          50            130          270       
'people type 2'      540          60            160          240
'people type 3'      530          70            170          230
'people type 4'      540          40            150          270")

your_data = as.matrix(read.table(textConnection(Input),
                              header=TRUE,
                              row.names=1))

your_data
#>               decision.1 decision.2 decision.3 decision.4
#> people type 1        150         50        130        270
#> people type 2        540         60        160        240
#> people type 3        530         70        170        230
#> people type 4        540         40        150        270

chisq.test(your_data)
#> 
#>  Pearson's Chi-squared test
#> 
#> data:  your_data
#> X-squared = 185.06, df = 9, p-value < 2.2e-16

library(rcompanion)

pairwiseNominalIndependence(your_data,
                            fisher = FALSE,
                            gtest  = FALSE,
                            chisq  = TRUE,
                            method = "holm")
#>                      Comparison  p.Chisq p.adj.Chisq
#> 1 people type 1 : people type 2 5.44e-29    3.26e-28
#> 2 people type 1 : people type 3 1.56e-28    7.80e-28
#> 3 people type 1 : people type 4 3.02e-28    1.21e-27
#> 4 people type 2 : people type 3 7.11e-01    7.11e-01
#> 5 people type 2 : people type 4 1.07e-01    2.14e-01
#> 6 people type 3 : people type 4 5.27e-03    1.58e-02
Chuck P
  • 3,862
  • 3
  • 9
  • 20
  • Thank you very much. What is the null hypothesis for each of the test? – shayan May 19 '20 at 19:34
  • **If it answered your question please check the answer.** For all chi square test of independence (a.k.a. association) the null hypothesis is that the relative proportions of one variable are independent of the second variable; in other words, the proportions at one variable are the same for different values of the second variable. In your example, the null hypothesis is that the proportion of people type n is equal to the proportion of people type m for the various decision types. – Chuck P May 19 '20 at 19:58