{"id":1163,"date":"2023-07-27T10:53:00","date_gmt":"2023-07-27T10:53:00","guid":{"rendered":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/"},"modified":"2023-07-27T10:53:00","modified_gmt":"2023-07-27T10:53:00","slug":"rollende-correlatie-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/","title":{"rendered":"Hoe de glijdende correlatie in r te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Rolling correlaties<\/strong> zijn correlaties tussen twee tijdreeksen over een glijdend venster. Een van de voordelen van dit soort correlatie is dat u de correlatie tussen twee tijdreeksen in de loop van de tijd kunt visualiseren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt berekenen.<\/span><\/p>\n<h3> <strong>Hoe u rollende correlaties in R kunt berekenen<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we het volgende gegevensframe hebben dat het totale aantal verkochte producten voor twee verschillende producten ( <em>x<\/em> en <em>y<\/em> ) weergeeft over een periode van 15 maanden:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data<\/span>\ndata &lt;- data.frame(month=1:15,\n                   x=c(13, 15, 16, 15, 17, 20, 22, 24, 25, 26, 23, 24, 23, 22, 20),\n                   y=c(22, 24, 23, 27, 26, 26, 27, 30, 33, 32, 27, 25, 28, 26, 28))\n\n<span style=\"color: #008080;\">#view first six rows\n<\/span>head(data)\n\n  month xy\n1 1 13 22\n2 2 15 24\n3 3 16 23\n4 4 15 27\n5 5 17 26\n6 6 20 26<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Om een rollende correlatie in R te berekenen, kunnen we de <a href=\"https:\/\/www.rdocumentation.org\/packages\/zoo\/versions\/1.8-8\/topics\/rollapply\" target=\"_blank\" rel=\"noopener noreferrer\">functie rollapply()<\/a> uit het <strong>zoo-<\/strong> pakket gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze functie gebruikt de volgende syntaxis:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>rollapply(gegevens, breedte, FUN, by.column=TRUE)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>data:<\/strong> naam van het dataframe<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>breedte:<\/strong> geheel getal dat de breedte van het venster voor glijdende correlatie specificeert<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FUN:<\/strong> De functie die moet worden toegepast.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>by.column:<\/strong> Geeft aan of de functie afzonderlijk op elke kolom moet worden toegepast. Dit is standaard WAAR, maar om een voortschrijdende correlatie te berekenen moeten we specificeren dat deze ONWAAR is.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">U kunt deze functie als volgt gebruiken om de driemaandelijkse voortschrijdende correlatie van de omzet tussen product <em>x<\/em> en product <em>y<\/em> te berekenen:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate 3-month rolling correlation between sales for <em>x<\/em> and <em>y<\/em><\/span>\nrollapply(data, width=3, <span style=\"color: #3366ff;\">function<\/span> (x) cor(x[,2],x[,3]), by.column= <span style=\"color: #008000;\">FALSE<\/span> )\n\n [1] 0.6546537 -0.6933752 -0.2401922 -0.8029551 0.8029551 0.9607689\n [7] 0.9819805 0.6546537 0.8824975 0.8170572 -0.9449112 -0.3273268\n[13] -0.1889822\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze functie retourneert de correlatie tussen de verkoop van twee producten in de afgelopen drie maanden. Bijvoorbeeld:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">De correlatie van de omzet in de maanden 1-3 was <strong>0,6546537<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De verkoopcorrelatie in de maanden 2-4 was <strong>-0,6933752.<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\">De verkoopcorrelatie in de maanden 3-5 was <strong>-0,2401922.<\/strong><\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Enzovoort.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen deze formule eenvoudig aanpassen om de voortschrijdende correlatie voor een andere tijdsperiode te berekenen. De volgende code laat bijvoorbeeld zien hoe u de zesmaandelijkse voortschrijdende correlatie van de verkopen tussen de twee producten berekent:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate 6-month rolling correlation between sales for <em>x<\/em> and <em>y<\/em><\/span>\nrollapply(data, width=6, <span style=\"color: #3366ff;\">function<\/span> (x) cor(x[,2],x[,3]), by.column= <span style=\"color: #008000;\">FALSE<\/span> )\n\n [1] 0.5587415 0.4858553 0.6931033 0.7564756 0.8959291 0.9067715 0.7155418\n [8] 0.7173740 0.7684468 0.4541476\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze functie retourneert de correlatie tussen de twee productverkopen in de afgelopen zes maanden. Bijvoorbeeld:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">De correlatie van de omzet in de maanden 1-6 was <strong>0,5587415<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">De verkoopcorrelatie in de maanden 2-7 was <strong>0,4858553.<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\">De verkoopcorrelatie in de maanden 3-8 was <strong>0,6931033.<\/strong><\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Enzovoort.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Opmerkingen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Houd de volgende punten in gedachten bij het gebruik van de functie rollapply():<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">De <strong>breedte<\/strong> (dat wil zeggen het vervolgkeuzevenster) moet gelijk zijn aan of groter dan 3 om correlaties te kunnen berekenen.<\/span><\/li>\n<li> <span style=\"color: #000000;\">In de bovenstaande formules hebben we cor(x[,2],x[3]) gebruikt omdat de twee kolommen waar we de correlaties tussen wilden berekenen zich op positie <strong>2<\/strong> en <strong>3<\/strong> bevonden. Pas deze cijfers aan als de kolommen waarin u ge\u00efnteresseerd bent zich op verschillende posities bevinden.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\"><strong>Gerelateerd:<\/strong><\/span> <a href=\"https:\/\/statorials.org\/nl\/rollende-correlatie-excel\/\" target=\"_blank\" rel=\"noopener noreferrer\">Hoe u de Rolling Correlatie in Excel kunt berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rolling correlaties zijn correlaties tussen twee tijdreeksen over een glijdend venster. Een van de voordelen van dit soort correlatie is dat u de correlatie tussen twee tijdreeksen in de loop van de tijd kunt visualiseren. In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt berekenen. Hoe u rollende correlaties in R kunt [&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-1163","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 de rollende correlatie in R - Statorials te berekenen<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt 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\/rollende-correlatie-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe de rollende correlatie in R - Statorials te berekenen\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt berekenen, met verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T10:53:00+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=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/\",\"name\":\"Hoe de rollende correlatie in R - Statorials te berekenen\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-27T10:53:00+00:00\",\"dateModified\":\"2023-07-27T10:53:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt berekenen, met verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de glijdende correlatie 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 de rollende correlatie in R - Statorials te berekenen","description":"In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt 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\/rollende-correlatie-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de rollende correlatie in R - Statorials te berekenen","og_description":"In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt berekenen, met verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-27T10:53:00+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/","url":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/","name":"Hoe de rollende correlatie in R - Statorials te berekenen","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-27T10:53:00+00:00","dateModified":"2023-07-27T10:53:00+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u rollende correlaties in R kunt berekenen, met verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/rollende-correlatie-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de glijdende correlatie 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\/1163","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=1163"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/1163\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=1163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=1163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=1163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}