add.test: Apply a test to a Contingency Tables object

Description Usage Arguments Details Value See Also Examples

View source: R/contingency.tables.R

Description

Applies and adds a test to a contingency.tables object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
add.test(tables,name,htests,types=c("asymptotic","monte.carlo","exact"))

add.chi.squared(tables, simulate.p.value = FALSE, B = 10000)

add.likelihood.ratio(tables, conservative = FALSE, simulate.p.value = FALSE, B = 10000)

add.fishers.exact(tables, simulate.p.value = FALSE, B = 10000)

add.correlation(tables,method=c("spearman","kendall"))

add.kruskal(tables,nominal=c("both","rows","cols"))

Arguments

tables

An object of class contingency.tables

name

Name of the test

htests

A function or list of functions which take a matrix as it's argument and returns an object of class htest

types

A character vector with the same number of items as htests, indicating what type of test was done

conservative

Should a conservative p-value be computed. i.e. One with a continuity correction for asymptotic tests and not using the mid p-value for exact and approximate tests

simulate.p.value

If TRUE p-values will be computed via monte carlo simulation

B

the number of samples for the monte carlo simulation

method

the type of correlation

nominal

Should the rows or columns be considered nominal.

Details

add.test applies a supplied list of tests to all of the tables in tables.

add.chi.squared is a wrapper function applying the chisq.test function to each table. add.likelihood.ratio is a wrapper function applying the likelihood.test function to each table. add.fishers.exact is a wrapper function applying the fisher.test function to each table. add.correlation is a wrapper function applying the cor.test function to each table. add.kruskal is a wrapper function applying the kruskal.test function to each table.

Value

A contingency.tables object identical to tables, but with the test applied to each table.

See Also

add.cross.strata.test likelihood.test cor.test kruskal.test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5))
tables<-contingency.tables(
	row.vars=a,
	col.vars=b,
	stratum.var=c,data=dat)
tables<-add.chi.squared(tables,simulate.p.value=TRUE,B=10000)
tables<-add.likelihood.ratio(tables)
tables<-add.fishers.exact(tables)
tables<-add.correlation(tables,method='kendall')
tables<-add.kruskal(tables)
tables<-add.mantel.haenszel(tables)
print(tables)
remove(tables)

Example output

Loading required package: ggplot2
Loading required package: JGR
Loading required package: rJava
Loading required package: JavaGD
OpenJDK 64-Bit Server VM warning: Can't detect primordial thread stack location - find_vma failed

Please type JGR() to launch console. Platform specific launchers (.exe and .app) can also be obtained at http://www.rforge.net/JGR/files/.


Loading required package: car
Loading required package: carData
Loading required package: MASS
Registered S3 methods overwritten by 'lme4':
  method                          from
  cooks.distance.influence.merMod car 
  influence.merMod                car 
  dfbeta.influence.merMod         car 
  dfbetas.influence.merMod        car 


Note Non-JGR console detected:
	Deducer is best used from within JGR (http://jgr.markushelbig.org/).
	To Bring up GUI dialogs, type deducer().

Warning message:
In chisq.test(x, correct = FALSE) :
  Chi-squared approximation may be incorrect
================================================================================

               ==================================================               
                      ========== Table: a by b ==========                      

                       | -- Stratum = FALSE --
                       | b 
                     a |    FALSE  |     TRUE  | Row Total | 
-----------------------|-----------|-----------|-----------|
       FALSE  Count    |        4  |        9  |       13  | 
              Row %    |   30.769% |   69.231% |   59.091% | 
              Column % |   57.143% |   60.000% |           | 
              Total %  |   18.182% |   40.909% |           | 
-----------------------|-----------|-----------|-----------|
        TRUE  Count    |        3  |        6  |        9  | 
              Row %    |   33.333% |   66.667% |   40.909% | 
              Column % |   42.857% |   40.000% |           | 
              Total %  |   13.636% |   27.273% |           | 
-----------------------|-----------|-----------|-----------|
          Column Total |        7  |       15  |       22  | 
              Column % |   31.818% |   68.182% |           | 

                       | -- Stratum = TRUE --
                       | b 
                     a |    FALSE  |     TRUE  | Row Total | 
-----------------------|-----------|-----------|-----------|
       FALSE  Count    |       24  |       29  |       53  | 
              Row %    |   45.283% |   54.717% |   67.949% | 
              Column % |   68.571% |   67.442% |           | 
              Total %  |   30.769% |   37.179% |           | 
-----------------------|-----------|-----------|-----------|
        TRUE  Count    |       11  |       14  |       25  | 
              Row %    |   44.000% |   56.000% |   32.051% | 
              Column % |   31.429% |   32.558% |           | 
              Total %  |   14.103% |   17.949% |           | 
-----------------------|-----------|-----------|-----------|
          Column Total |       35  |       43  |       78  | 
              Column % |   44.872% |   55.128% |           | 



                               Large Sample                                
                          Test Statistic    DF p-value | Effect Size est.  
Stratum = FALSE    Chi Squared 0.016        1  0.899   |                   
                    Likelihood 0.016        1  0.899   |                   
                 Fishers Exact                         |                   
         kendall's Correlation -0.124          0.901   | tau         -0.027
      Kruskal-W (nominal rows) 0.015        1  0.901   |                   
      Kruskal-W (nominal cols) 0.015        1  0.901   |                   
 Stratum = TRUE    Chi Squared 0.011        1  0.915   |                   
                    Likelihood 0.011        1  0.915   |                   
                 Fishers Exact                         |                   
         kendall's Correlation 0.106           0.916   | tau         0.012 
      Kruskal-W (nominal rows) 0.011        1  0.916   |                   
      Kruskal-W (nominal cols) 0.011        1  0.916   |                   
                                                  
                          Test Lower (%) Upper (%)
Stratum = FALSE    Chi Squared                    
                    Likelihood                    
                 Fishers Exact                    
         kendall's Correlation                    
      Kruskal-W (nominal rows)                    
      Kruskal-W (nominal cols)                    
 Stratum = TRUE    Chi Squared                    
                    Likelihood                    
                 Fishers Exact                    
         kendall's Correlation                    
      Kruskal-W (nominal rows)                    
      Kruskal-W (nominal cols)                    
------------------------------
                               Monte Carlo           
                          Test Statistic   DF p-value
Stratum = FALSE    Chi Squared 0.016          1      
                    Likelihood                       
                 Fishers Exact                       
         kendall's Correlation                       
      Kruskal-W (nominal rows)                       
      Kruskal-W (nominal cols)                       
 Stratum = TRUE    Chi Squared 0.011          1      
                    Likelihood                       
                 Fishers Exact                       
         kendall's Correlation                       
      Kruskal-W (nominal rows)                       
      Kruskal-W (nominal cols)                       
------------------------------
                               Exact               
                          Test Statistic DF p-value
Stratum = FALSE    Chi Squared                     
                    Likelihood                     
                 Fishers Exact              1      
         kendall's Correlation                     
      Kruskal-W (nominal rows)                     
      Kruskal-W (nominal cols)                     
 Stratum = TRUE    Chi Squared                     
                    Likelihood                     
                 Fishers Exact              1      
         kendall's Correlation                     
      Kruskal-W (nominal rows)                     
      Kruskal-W (nominal cols)                     
------------------------------






                Large Sample                                               
           Test Statistic    DF p-value | Effect Size       est.  Lower (%)
Mantel-Haenszel 0.001        1  0.972   | common odds ratio 1.015 0.435 () 
                         
           Test Upper (%)
Mantel-Haenszel 2.368 () 
---------------





================================================================================

Deducer documentation built on May 2, 2019, 8:35 a.m.

Related to add.test in Deducer...