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

Teradata Aster® R User GuideUpdate 3

Product
Aster R
Release Number
7.00.02.01
Published
December 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
fop1497542774450.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
fbp1477004286096
lifecycle
previous
Product Category
Software
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