{"id":46,"date":"2026-03-03T09:38:33","date_gmt":"2026-03-03T09:38:33","guid":{"rendered":"https:\/\/gigz.pk\/r\/?post_type=lesson&#038;p=46"},"modified":"2026-04-01T11:44:53","modified_gmt":"2026-04-01T11:44:53","slug":"hypothesis-testing","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/r\/lesson\/hypothesis-testing\/","title":{"rendered":"Hypothesis Testing"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hypothesis testing is a fundamental statistical method used to make inferences about populations based on sample data. In R, you can perform various tests to check whether observed data support a specific assumption or hypothesis.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. Key Concepts in Hypothesis Testing<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Null Hypothesis (H\u2080):<\/strong> The default assumption, e.g., no difference or effect.<\/li>\n\n\n\n<li><strong>Alternative Hypothesis (H\u2081):<\/strong> The assumption that contradicts H\u2080, e.g., there is a difference or effect.<\/li>\n\n\n\n<li><strong>Significance Level (\u03b1):<\/strong> The probability threshold to reject H\u2080, commonly 0.05.<\/li>\n\n\n\n<li><strong>p-value:<\/strong> Probability of observing data as extreme as the sample, assuming H\u2080 is true.<\/li>\n\n\n\n<li><strong>Decision:<\/strong> Reject H\u2080 if p-value &lt; \u03b1; otherwise, fail to reject H\u2080.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. One-Sample t-Test<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Used to compare the sample mean against a known population mean.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Sample data<br>scores &lt;- c(90, 85, 88, 92, 80)# Test if mean equals 85<br>t.test(scores, mu = 85)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>t-statistic, degrees of freedom, p-value, confidence interval, and sample mean.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>3. Two-Sample t-Test<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Used to compare the means of two independent samples.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">group1 &lt;- c(90, 85, 88)<br>group2 &lt;- c(80, 82, 84)# Test if means are equal<br>t.test(group1, group2, var.equal = TRUE)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>4. Paired t-Test<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Used when samples are related, e.g., before-and-after measurements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">before &lt;- c(100, 102, 98, 95)<br>after &lt;- c(105, 100, 97, 96)t.test(before, after, paired = TRUE)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>5. Chi-Square Test<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Used for categorical data to test independence or goodness-of-fit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>a) Test for Independence<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">data &lt;- matrix(c(30, 10, 20, 40), nrow=2)<br>chisq.test(data)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>b) Test for Goodness-of-Fit<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">observed &lt;- c(50, 30, 20)<br>expected &lt;- c(40, 40, 20)<br>chisq.test(x = observed, p = expected\/sum(expected))<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>6. ANOVA (Analysis of Variance)<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Used to compare means across more than two groups.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">group &lt;- factor(c(\"A\",\"A\",\"B\",\"B\",\"C\",\"C\"))<br>score &lt;- c(90, 85, 88, 82, 95, 89)anova_result &lt;- aov(score ~ group)<br>summary(anova_result)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>7. Non-Parametric Tests<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Wilcoxon Test:<\/strong> Alternative to t-test when data is not normally distributed.<\/li>\n\n\n\n<li><strong>Kruskal-Wallis Test:<\/strong> Alternative to ANOVA for non-normal data.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">wilcox.test(group1, group2)<br>kruskal.test(score ~ group)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>8. Advantages of Hypothesis Testing<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Supports data-driven decision making<\/li>\n\n\n\n<li>Evaluates assumptions about populations<\/li>\n\n\n\n<li>Identifies statistically significant differences<\/li>\n\n\n\n<li>Forms the basis for inferential statistics<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Hypothesis testing in R allows you to make informed decisions about your data. By mastering tests like t-tests, chi-square tests, ANOVA, and non-parametric alternatives, you can evaluate assumptions, compare groups, and draw reliable conclusions from sample data. These techniques are essential for rigorous data analysis and scientific research.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/r\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">R Programming (R Lang) > Statistics with R > Hypothesis Testing<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775043763638\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":23,"template":"","class_list":["post-46","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Hypothesis Testing - Analyze Deep. Visualize Better. Build with R.<\/title>\n<meta name=\"description\" content=\"Learn how to perform t-test and ANOVA in R with examples. Master hypothesis testing, p-values, and compare group means effectively.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hypothesis Testing - Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"og:description\" content=\"Learn how to perform t-test and ANOVA in R with examples. Master hypothesis testing, p-values, and compare group means effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-01T11:44:53+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/lesson\\\/hypothesis-testing\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Hypothesis Testing - Analyze Deep. Visualize Better. Build with R.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\"},\"datePublished\":\"2026-03-03T09:38:33+00:00\",\"dateModified\":\"2026-04-01T11:44:53+00:00\",\"description\":\"Learn how to perform t-test and ANOVA in R with examples. Master hypothesis testing, p-values, and compare group means effectively.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/r\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R Programming (R Lang) > Statistics with R > Hypothesis Testing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/r\\\/\",\"name\":\"Analyze Deep. Visualize Better. Build with R.\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/r\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hypothesis Testing - Analyze Deep. Visualize Better. Build with R.","description":"Learn how to perform t-test and ANOVA in R with examples. Master hypothesis testing, p-values, and compare group means effectively.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Hypothesis Testing - Analyze Deep. Visualize Better. Build with R.","og_description":"Learn how to perform t-test and ANOVA in R with examples. Master hypothesis testing, p-values, and compare group means effectively.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Analyze Deep. Visualize Better. Build with R.","article_modified_time":"2026-04-01T11:44:53+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/r\/lesson\/hypothesis-testing\/","url":"https:\/\/gigz.pk\/","name":"Hypothesis Testing - Analyze Deep. Visualize Better. Build with R.","isPartOf":{"@id":"https:\/\/gigz.pk\/r\/#website"},"datePublished":"2026-03-03T09:38:33+00:00","dateModified":"2026-04-01T11:44:53+00:00","description":"Learn how to perform t-test and ANOVA in R with examples. Master hypothesis testing, p-values, and compare group means effectively.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/r\/"},{"@type":"ListItem","position":2,"name":"R Programming (R Lang) > Statistics with R > Hypothesis Testing"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/r\/#website","url":"https:\/\/gigz.pk\/r\/","name":"Analyze Deep. Visualize Better. Build with R.","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/r\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/lesson\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/media?parent=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}