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 |
-
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
-
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)
-
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)}
-
Apply the function to an R data frame.
fisher.test.p(data)
[1] 0.07889075
-
Apply the function to a virtual data frame.
aa.apply(tadf.fisher.data, MARGIN = c(), fisher.test.p )
[1] 0.07889075