asgaros-forum
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6121health-check
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6121Fisher’s exact test is a non-parametric statistical test<\/a> that helps us determine whether a significant association exists between two categorical variables in a contingency table. This test is particularly useful when dealing with small sample sizes or when the assumptions of the chi-squared test are not met.<\/p>\n\n\n\n Fisher’s exact test<\/a> is often preferred over the chi-squared test when certain assumptions of the chi-squared test are not met. These assumptions include:<\/p>\n\n\n\n In Fisher’s exact test, the null hypothesis (H0) and alternative hypothesis (Ha) are defined as follows:<\/p>\n\n\n\n Null Hypothesis (H0):<\/strong> H0: There is no significant association between Variable A and Variable B.<\/em> (The variables are Independent)<\/p>\n\n\n\n Alternative Hypothesis (Ha):<\/strong> Ha: There is a significant association between Variable A and Variable B.<\/em> (The variables are dependent)<\/p>\n\n\n\n In practical terms, when conducting Fisher’s exact test, you evaluate whether the observed data deviates significantly from what would be expected under the assumption of no association (null hypothesis). If the p-value associated with the test is sufficiently small (typically below a chosen significance level, such as 0.05), you will reject the null hypothesis in favor of the alternative hypothesis, indicating a statistically significant association between the two categorical variables. Conversely, a larger p-value would lead to the acceptance of the null hypothesis, suggesting no significant association.<\/p>\n\n\n\n In this example, we’ll analyze the association between two categorical variables: “Gender” and “Preference for Tea or Coffee.” We want to determine if there is a significant association between gender and beverage preference.<\/p>\n\n\n\n Calculating expected frequencies is an integral part of performing Fisher’s exact test. It serves several important purposes:<\/p>\n\n\n\n To calculate the expected frequencies for a contingency table in the context of Fisher’s exact test, you can use the following formula:<\/p>\n\n\n\n Expected Frequency = (Row Total \u00d7 Column Total) \/ Grand Total<\/strong><\/em><\/p>\n\n\n\n Alternatively, to obtain the expected frequencies, use the chisq.test() function in conjunction with $expected:<\/strong><\/p>\n\n\n\n Output:<\/p>\n\n\n\n The code then extracts the p-value from the test result and checks if the association is statistically significant at the 0.05 significance level. The output will indicate whether there is a significant association between gender and beverage preference based on the p-value.<\/p>\n\n\n\n Introduction Fisher’s exact test is a non-parametric statistical test that helps us determine whether a significant association exists between two categorical variables in a contingency table. This test is particularly useful when dealing with small sample sizes or when the assumptions of the chi-squared test are not met. Fisher’s exact test is often preferred over […]<\/p>\n","protected":false},"author":1,"featured_media":2730,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[4,15],"tags":[],"class_list":["post-2715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r-programming","category-statistics"],"uagb_featured_image_src":{"full":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest.png",1920,1080,false],"thumbnail":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest-150x150.png",150,150,true],"medium":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest-300x169.png",300,169,true],"medium_large":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest-768x432.png",640,360,true],"large":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest-1024x576.png",640,360,true],"1536x1536":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest-1536x864.png",1536,864,true],"2048x2048":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest.png",1920,1080,false],"blogus-slider-full":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest.png",1280,720,false],"blogus-featured":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest.png",1024,576,false],"blogus-medium":["https:\/\/mbithiguide.com\/wp-content\/uploads\/2023\/09\/fishertest.png",676,380,false]},"uagb_author_info":{"display_name":"Benard Mbithi","author_link":"https:\/\/mbithiguide.com\/author\/benard-mbithi\/"},"uagb_comment_info":1,"uagb_excerpt":"Introduction Fisher’s exact test is a non-parametric statistical test that helps us determine whether a significant association exists between two categorical variables in a contingency table. This test is particularly useful when dealing with small sample sizes or when the assumptions of the chi-squared test are not met. Fisher’s exact test is often preferred over…","_links":{"self":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts\/2715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/comments?post=2715"}],"version-history":[{"count":9,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts\/2715\/revisions"}],"predecessor-version":[{"id":2731,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/posts\/2715\/revisions\/2731"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/media\/2730"}],"wp:attachment":[{"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/media?parent=2715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/categories?post=2715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mbithiguide.com\/wp-json\/wp\/v2\/tags?post=2715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
Hypothesis<\/h2>\n\n\n\n
The null hypothesis in Fisher’s exact test states no association or relationship between the two categorical variables being analyzed. In other words, it suggests that any observed differences in data distribution across the categories of the two variables are purely due to chance. Mathematically, it can be expressed as:<\/p>\n\n\n\n
The alternative hypothesis in Fisher’s exact test posits that there is a significant association or relationship between the two categorical variables. It suggests that the observed data distribution is not random chance but is influenced by a non-random relationship between the variables. Mathematically, it can be expressed as:<\/p>\n\n\n\nExample<\/h2>\n\n\n\n
Here’s a step-by-step guide to performing Fisher’s exact test in R:<\/h2>\n\n\n\n
Observed frequencies<\/h3>\n\n\n\n
# Step 1: Create a contingency table\n# Gender: 30 males, 40 females\n# Preference for Tea: 15 prefer tea, 25 prefer coffee\n\n# Create a data frame with the data\ndata <- data.frame(\n Gender = c(\"Male\", \"Female\"),\n Tea_Preference = c(15, 25),\n Coffee_Preference = c(30 - 15, 40 - 25)\n)\n\n# Print the data frame\nprint(data)<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
# Create a contingency table from the data\ncontingency_table <- matrix(\n c(data$Tea_Preference, data$Coffee_Preference),\n nrow = 2,\n dimnames = list(Gender = data$Gender, Preference = c(\"Tea\", \"Coffee\"))\n)\n\n# Visualize using Mosaic Plot\nmosaicplot(contingency_table, main = \"Mosaic Plot\", color = TRUE)\n\n<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
Expected frequencies<\/h3>\n\n\n\n
\n
# Calculate the row and column totals\nrow_totals <- rowSums(contingency_table)\ncol_totals <- colSums(contingency_table)\n\n# Calculate the grand total\ngrand_total <- sum(contingency_table)\n\n# Initialize a matrix for expected frequencies\nexpected_freq <- matrix(0, nrow = 2, ncol = 2)\n\n# Calculate expected frequencies for each cell\nfor (i in 1:2) {\n for (j in 1:2) {\n expected_freq[i, j] <- (row_totals[i] * col_totals[j]) \/ grand_total\n }\n}\n\n# Print the expected frequencies\nrownames(expected_freq) <- rownames(contingency_table)\ncolnames(expected_freq) <- colnames(contingency_table)\nprint(expected_freq)\n<\/pre>\n\n\n\n
#Expected frequencies\nchisq.test(contingency_table)$expected<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
# Step 2: Perform Fisher's exact test\n# We use the fisher.test() function to conduct the test\n\n# Perform Fisher's exact test\nfisher_result <- fisher.test(contingency_table)\n\n# Step 3: Interpret the results\n# Print the results\nprint(fisher_result)\n<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
# Extract the p-value from the result\np_value <- fisher_result$p.value\n\n# Check if the association is statistically significant (using a 0.05 significance level)\nif (p_value < 0.05) {\n cat(\"There is a significant association between Gender and Beverage Preference (p-value =\", p_value, \")\\n\")\n} else {\n cat(\"There is no significant association between Gender and Beverage Preference (p-value =\", p_value, \")\\n\")\n}<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
Additional Resources<\/strong><\/h2>\n\n\n\n
\n