{"id":3974,"date":"2023-07-14T10:29:30","date_gmt":"2023-07-14T10:29:30","guid":{"rendered":"https:\/\/statorials.org\/nl\/r-cor-functie\/"},"modified":"2023-07-14T10:29:30","modified_gmt":"2023-07-14T10:29:30","slug":"r-cor-functie","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/r-cor-functie\/","title":{"rendered":"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten in r te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">U kunt de functie <strong>cor()<\/strong> in R gebruiken om correlatieco\u00ebffici\u00ebnten tussen variabelen te berekenen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dit zijn de meest gebruikelijke manieren om deze functie te gebruiken:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 1: bereken de Pearson-correlatieco\u00ebffici\u00ebnt tussen twee variabelen<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>cor(df$x, df$y)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gebruik de Pearson-correlatieco\u00ebffici\u00ebnt bij het berekenen van de correlatie tussen twee continue variabelen. (bijvoorbeeld lengte en gewicht)<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 2: Bereken de Pearson-correlatieco\u00ebffici\u00ebnt tussen alle numerieke variabelen in het dataframe<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>cor(df)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze methode retourneert een <a href=\"https:\/\/statorials.org\/nl\/hoe-een-correlatiematrix-te-lezen\/\" target=\"_blank\" rel=\"noopener\">correlatiematrix<\/a> die de Pearson-correlatieco\u00ebffici\u00ebnt bevat tussen elke paarsgewijze combinatie van numerieke variabelen in een dataframe.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 3: bereken de Spearman-correlatieco\u00ebffici\u00ebnt tussen twee variabelen<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>cor(df$x, df$y, method=' <span style=\"color: #ff0000;\">spearman<\/span> ')<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gebruik de correlatieco\u00ebffici\u00ebnt van Spearman bij het berekenen van de correlatie tussen twee gerangschikte variabelen. (bijv. rangschikking van de wiskunde-examenscore van een leerling versus de rangschikking van zijn wetenschapsexamenscore in een klas)<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 4: bereken de Kendall-correlatieco\u00ebffici\u00ebnt tussen twee variabelen<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>cor(df$x, df$y, method=' <span style=\"color: #ff0000;\">kendall<\/span> ')<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gebruik de correlatieco\u00ebffici\u00ebnt van Kendall als u de correlatie van Spearman wilt gebruiken, maar de steekproefomvang klein is en er veel verbanden zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende voorbeelden laten zien hoe je elke methode in de praktijk kunt gebruiken met het volgende dataframe in R dat het aantal uren aan studeren toont, het aantal afgelegde oefenexamens en het eindexamencijfer voor acht verschillende studenten:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (hours=c(1, 1, 3, 2, 4, 3, 5, 6),\n                 prac_exams=c(4, 3, 3, 2, 3, 2, 1, 4),\n                 score=c(69, 74, 74, 70, 89, 85, 99, 90))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  hours prac_exams score\n1 1 4 69\n2 1 3 74\n3 3 3 74\n4 2 2 70\n5 4 3 89\n6 3 2 85\n7 5 1 99\n8 6 4 90\n<\/span><\/span><\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Bereken de Pearson-correlatieco\u00ebffici\u00ebnt tussen twee variabelen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de functie <strong>cor()<\/strong> gebruikt om de Pearson-correlatieco\u00ebffici\u00ebnt tussen de <strong>uren-<\/strong> en <strong>scorevariabelen<\/strong> te berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Pearson correlation coefficient between hours and score<\/span>\ncor(df$hours, df$score)\n\n[1] 0.8600528\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De Pearson-correlatieco\u00ebffici\u00ebnt tussen <strong>uren<\/strong> en <strong>score<\/strong> bleek <strong>0,86 te zijn.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Houd er rekening mee dat als er NA-waarden in uw dataframe voorkomen, u het argument <strong>use=&#8217;complete.obs&#8216;<\/strong> kunt gebruiken om alleen de rijen te gebruiken waar geen NA-waarden zijn:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Pearson correlation coefficient and ignore any rows with NA<\/span>\ncor(df$hours, df$score, use=' <span style=\"color: #ff0000;\">complete.obs<\/span> ')<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Bereken de Pearson-correlatieco\u00ebffici\u00ebnt tussen alle numerieke variabelen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de functie <strong>cor()<\/strong> gebruikt om een correlatiematrix te maken die de Pearson-correlatieco\u00ebffici\u00ebnt bevat tussen alle numerieke variabelen in het gegevensframe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Pearson correlation coefficient between all numeric variables<\/span>\ncor(df)\n\n                hours prac_exams score\nhours 1.0000000 -0.1336063 0.8600528\nprac_exams -0.1336063 1.0000000 -0.3951028\nscore 0.8600528 -0.3951028 1.0000000\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Zo interpreteert u het resultaat:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">De Pearson-correlatieco\u00ebffici\u00ebnt tussen <strong>uren<\/strong> en <b>praktijkexamens<\/b> is <strong>-0,13<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Pearson-correlatieco\u00ebffici\u00ebnt tussen <strong>uren<\/strong> en <strong>score<\/strong> is <strong>0,86<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De Pearson-correlatieco\u00ebffici\u00ebnt tussen <b>praktijkexamens<\/b> en <strong>de score<\/strong> is <strong>-0,39<\/strong> .<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\"><strong>Opmerking<\/strong> : de Pearson-correlatieco\u00ebffici\u00ebnt tussen elke individuele variabele en zichzelf is altijd 1, daarom is elke waarde langs de diagonaal van de correlatiematrix 1.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld 3: Bereken de Spearman-correlatieco\u00ebffici\u00ebnt tussen twee variabelen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de functie <strong>cor()<\/strong> gebruikt om de Spearman-correlatieco\u00ebffici\u00ebnt tussen de variabelen <strong>hours<\/strong> en <b>prac_exams<\/b> te berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Spearman correlation coefficient between hours and prac_exams<\/span>\ncor(df$hours, df$prac_exams, method=' <span style=\"color: #ff0000;\">spearman<\/span> ')\n\n[1] -0.1250391\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De Spearman-correlatieco\u00ebffici\u00ebnt tussen <strong>uren<\/strong> en <b>praktijkexamens<\/b> blijkt <strong>-0,125 te zijn.<\/strong><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld 4: Bereken de Kendall-correlatieco\u00ebffici\u00ebnt tussen twee variabelen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u de functie <strong>cor()<\/strong> gebruikt om de Kendall-correlatieco\u00ebffici\u00ebnt tussen de variabelen <strong>hours<\/strong> en <b>prac_exams<\/b> te berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate Kendall's correlation coefficient between hours and prac_exams<\/span>\ncor(df$hours, df$prac_exams, method=' <span style=\"color: #ff0000;\">kendall<\/span> ')\n\n[1] -0.1226791\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De Kendall&#8217;s correlatieco\u00ebffici\u00ebnt tussen <strong>uren<\/strong> en <b>praktijkexamens<\/b> blijkt <strong>-0,123 te zijn.<\/strong><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in R kunt uitvoeren:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de glijdende correlatie in R te berekenen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/autocorrelatie-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe autocorrelatie in R te berekenen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/gedeeltelijke-correlatie-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de gedeeltelijke correlatie in R te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>U kunt de functie cor() in R gebruiken om correlatieco\u00ebffici\u00ebnten tussen variabelen te berekenen. Dit zijn de meest gebruikelijke manieren om deze functie te gebruiken: Methode 1: bereken de Pearson-correlatieco\u00ebffici\u00ebnt tussen twee variabelen cor(df$x, df$y) Gebruik de Pearson-correlatieco\u00ebffici\u00ebnt bij het berekenen van de correlatie tussen twee continue variabelen. (bijvoorbeeld lengte en gewicht) Methode 2: Bereken [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-3974","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten te berekenen in R - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie cor() gebruikt om correlatieco\u00ebffici\u00ebnten in R te berekenen, met verschillende voorbeelden.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/r-cor-functie\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten te berekenen in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de functie cor() gebruikt om correlatieco\u00ebffici\u00ebnten in R te berekenen, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/r-cor-functie\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-14T10:29:30+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/r-cor-functie\/\",\"url\":\"https:\/\/statorials.org\/nl\/r-cor-functie\/\",\"name\":\"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten te berekenen in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-14T10:29:30+00:00\",\"dateModified\":\"2023-07-14T10:29:30+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de functie cor() gebruikt om correlatieco\u00ebffici\u00ebnten in R te berekenen, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/r-cor-functie\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/r-cor-functie\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/r-cor-functie\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten in r te berekenen\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten te berekenen in R - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de functie cor() gebruikt om correlatieco\u00ebffici\u00ebnten in R te berekenen, met verschillende voorbeelden.","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:\/\/statorials.org\/nl\/r-cor-functie\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten te berekenen in R - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de functie cor() gebruikt om correlatieco\u00ebffici\u00ebnten in R te berekenen, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/r-cor-functie\/","og_site_name":"Statorials","article_published_time":"2023-07-14T10:29:30+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/r-cor-functie\/","url":"https:\/\/statorials.org\/nl\/r-cor-functie\/","name":"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten te berekenen in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-14T10:29:30+00:00","dateModified":"2023-07-14T10:29:30+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de functie cor() gebruikt om correlatieco\u00ebffici\u00ebnten in R te berekenen, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/r-cor-functie\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/r-cor-functie\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/r-cor-functie\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe cor() te gebruiken om correlatieco\u00ebffici\u00ebnten in r te berekenen"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=3974"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3974\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}