7.00.02.01 - Example 4b: Fisher's Exact Test - Aster R

Teradata Aster® R User GuideUpdate 3

prodname
Aster R
vrm_release
7.00.02.01
created_date
December 2017
category
Programming Reference
User Guide
featnum
B700-1033-700K
This example uses Fisher's exact test to analyze hypothetical data comparing two treatments. The input data is shown here.
  Treatment 1 Treatment 2
Improvement 15 10
No improvement 3 9
  1. Apply the R function fisher.test to the data.
    data <- matrix(c(15, 3, 10, 9), nrow = 2)
    fisher.test(data)
            Fisher's Exact Test for Count Data 
    data:  data
    p-value = 0.07889
    alternative hypothesis: true odds ratio is not equal to 1
    95 percent confidence interval:
      0.8112471 31.0118500
    sample estimates:
    odds ratio 
       4.313649 
  2. Create a virtual data frame based on this data.
    ta.dropTable("fisher_data", schemaName = "public")
    
    tadf.fisher.data <- as.ta.data.frame(data, table = "fisher_data", schemaName = "public", tableType = "dimension", row.names = TRUE)
  3. Create an R function that finds and reports the p-value resulting from the function fisher.test.
    fisher.test.p <- function(x){ 
      p_value     <- fisher.test(x)$p.value
      return(p_value)}
  4. Apply the function to an R data frame.
    fisher.test.p(data)
    [1] 0.07889075
  5. Apply the function to a virtual data frame.
    aa.apply(tadf.fisher.data, MARGIN = c(), fisher.test.p )
    [1] 0.07889075