{"id":47,"date":"2026-03-03T09:39:36","date_gmt":"2026-03-03T09:39:36","guid":{"rendered":"https:\/\/gigz.pk\/r\/?post_type=lesson&#038;p=47"},"modified":"2026-04-01T11:47:50","modified_gmt":"2026-04-01T11:47:50","slug":"correlation-and-regression-analysis","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/r\/lesson\/correlation-and-regression-analysis\/","title":{"rendered":"Correlation and Regression Analysis"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Correlation and regression are key statistical techniques used to analyze relationships between variables. Correlation measures the strength and direction of a relationship, while regression allows prediction of one variable based on another.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. Correlation Analysis<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Correlation quantifies the linear relationship between two continuous variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>a) Pearson Correlation<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Measures linear correlation between two variables. Values range from -1 to 1.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Sample data<br>x &lt;- c(10, 20, 30, 40, 50)<br>y &lt;- c(15, 25, 35, 45, 55)# Pearson correlation<br>cor(x, y, method = \"pearson\")<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>b) Spearman Correlation<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Non-parametric correlation used for ranked or non-normal data.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cor(x, y, method = \"spearman\")<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>c) Correlation Matrix<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For multiple variables, use <code>cor()<\/code> on a data frame:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data &lt;- data.frame(<br>  height = c(150, 160, 170, 180),<br>  weight = c(50, 60, 65, 75),<br>  age = c(25, 30, 35, 40)<br>)cor(data)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. Simple Linear Regression<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Linear regression predicts the value of a dependent variable (Y) based on an independent variable (X).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Sample data<br>x &lt;- c(1, 2, 3, 4, 5)<br>y &lt;- c(2, 4, 5, 4, 5)# Fit regression model<br>model &lt;- lm(y ~ x)<br>summary(model)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Output includes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Coefficients (intercept and slope)<\/li>\n\n\n\n<li>R-squared value (goodness of fit)<\/li>\n\n\n\n<li>p-values for significance of coefficients<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Plotting Regression Line<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">plot(x, y, main = \"Simple Linear Regression\", xlab = \"X\", ylab = \"Y\")<br>abline(model, col = \"red\", lwd = 2)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>3. Multiple Linear Regression<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Predict a dependent variable using multiple independent variables.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data &lt;- data.frame(<br>  Y = c(50, 60, 65, 80, 90),<br>  X1 = c(1, 2, 3, 4, 5),<br>  X2 = c(2, 3, 4, 5, 6)<br>)model_multi &lt;- lm(Y ~ X1 + X2, data = data)<br>summary(model_multi)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>4. Checking Assumptions of Regression<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Linearity:<\/strong> Relationship between X and Y is linear<\/li>\n\n\n\n<li><strong>Normality:<\/strong> Residuals should be normally distributed<\/li>\n\n\n\n<li><strong>Homoscedasticity:<\/strong> Constant variance of residuals<\/li>\n\n\n\n<li><strong>Independence:<\/strong> Observations should be independent<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">par(mfrow = c(2, 2))<br>plot(model)  # Diagnostic plots<br>par(mfrow = c(1, 1))<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>5. Advantages of Correlation and Regression<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand relationships between variables<\/li>\n\n\n\n<li>Predict outcomes using regression models<\/li>\n\n\n\n<li>Quantify the strength and direction of associations<\/li>\n\n\n\n<li>Inform decision-making and strategy based on data<\/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\">Correlation and regression analysis in R are essential tools for understanding and modeling relationships between variables. Correlation measures the strength and direction of relationships, while regression allows prediction and quantifies effects. Mastering these techniques enables deeper insights, data-driven predictions, and effective analysis of complex datasets.<\/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 > Correlation and Regression Analysis<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775044050916\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775044050710\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":24,"template":"","class_list":["post-47","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>Correlation and Regression Analysis - Analyze Deep. Visualize Better. Build with R.<\/title>\n<meta name=\"description\" content=\"Learn how to perform correlation and linear regression in R with examples. Master Pearson, Spearman, simple, and multiple regression models.\" \/>\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=\"Correlation and Regression Analysis - Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"og:description\" content=\"Learn how to perform correlation and linear regression in R with examples. Master Pearson, Spearman, simple, and multiple regression models.\" \/>\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:47:50+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\\\/correlation-and-regression-analysis\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Correlation and Regression Analysis - Analyze Deep. Visualize Better. Build with R.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\"},\"datePublished\":\"2026-03-03T09:39:36+00:00\",\"dateModified\":\"2026-04-01T11:47:50+00:00\",\"description\":\"Learn how to perform correlation and linear regression in R with examples. Master Pearson, Spearman, simple, and multiple regression models.\",\"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 > Correlation and Regression Analysis\"}]},{\"@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":"Correlation and Regression Analysis - Analyze Deep. Visualize Better. Build with R.","description":"Learn how to perform correlation and linear regression in R with examples. Master Pearson, Spearman, simple, and multiple regression models.","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":"Correlation and Regression Analysis - Analyze Deep. Visualize Better. Build with R.","og_description":"Learn how to perform correlation and linear regression in R with examples. Master Pearson, Spearman, simple, and multiple regression models.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Analyze Deep. Visualize Better. Build with R.","article_modified_time":"2026-04-01T11:47:50+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\/correlation-and-regression-analysis\/","url":"https:\/\/gigz.pk\/","name":"Correlation and Regression Analysis - Analyze Deep. Visualize Better. Build with R.","isPartOf":{"@id":"https:\/\/gigz.pk\/r\/#website"},"datePublished":"2026-03-03T09:39:36+00:00","dateModified":"2026-04-01T11:47:50+00:00","description":"Learn how to perform correlation and linear regression in R with examples. Master Pearson, Spearman, simple, and multiple regression models.","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 > Correlation and Regression Analysis"}]},{"@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\/47","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=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}