{"id":3614,"date":"2023-07-16T13:19:31","date_gmt":"2023-07-16T13:19:31","guid":{"rendered":"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/"},"modified":"2023-07-16T13:19:31","modified_gmt":"2023-07-16T13:19:31","slug":"matthews-correlatiecoefficient-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/","title":{"rendered":"Hoe de matthews-correlatieco\u00ebffici\u00ebnt in r te berekenen"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Matthews Correlatie Co\u00ebffici\u00ebnt<\/strong> (MCC) is een metriek die we kunnen gebruiken om de prestaties van een <a href=\"https:\/\/statorials.org\/nl\/regressie-versus-classificatie\/\" target=\"_blank\" rel=\"noopener\">classificatiemodel<\/a> te evalueren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het wordt als volgt berekend:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>MCC<\/strong> = (TP*TN \u2013 FP*FN) \/ \u221a <span style=\"border-top: 1px solid black;\">(TP+FP)(TP+FN)(TN+FP)(TN+FN)<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">Goud:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>TP<\/strong> : Aantal echte positieven<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>TN<\/strong> : Aantal echte negatieven<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FP<\/strong> : Aantal valse positieven<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FN<\/strong> : Aantal valse negatieven<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Deze metriek is vooral handig wanneer de twee klassen niet in evenwicht zijn, dat wil zeggen dat de ene klasse veel meer voorkomt dan de andere.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De waarde van MCC ligt tussen -1 en 1 waarbij:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>-1<\/strong> geeft de totale onenigheid aan tussen voorspelde klassen en werkelijke klassen<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>0<\/strong> betekent volledig willekeurige gissingen<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>1<\/strong> geeft volledige overeenstemming aan tussen voorspelde klassen en werkelijke klassen<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Stel bijvoorbeeld dat een sportanalist een <a href=\"https:\/\/statorials.org\/nl\/logistische-regressie-1\/\" target=\"_blank\" rel=\"noopener\">logistisch regressiemodel<\/a> gebruikt om te voorspellen of 400 verschillende universiteitsbasketbalspelers wel of niet zullen worden opgeroepen voor de NBA.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De volgende verwarringsmatrix vat de voorspellingen van het model samen:<\/span> <\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-20693 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/equilibre1.png\" alt=\"\" width=\"430\" height=\"135\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Om de MCC van het model te berekenen, kunnen we de volgende formule gebruiken:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>MCC<\/strong> = (TP*TN \u2013 FP*FN) \/ \u221a <span style=\"border-top: 1px solid black;\">(TP+FP)(TP+FN)(TN+FP)(TN+FN)<\/span><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>MCC<\/strong> = (15*375-5*5) \/ \u221a <span style=\"border-top: 1px solid black;\">(15+5)(15+5)(375+5)(375+5)<\/span><\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>MCC<\/strong> = 0,7368<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">De Matthews-correlatieco\u00ebffici\u00ebnt blijkt <strong>0,7368<\/strong> te zijn.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze waarde ligt enigszins in de buurt van \u00e9\u00e9n, wat aangeeft dat het model goed presteert bij het voorspellen of spelers zullen worden opgeroepen of niet.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In het volgende voorbeeld ziet u hoe u MCC voor dit specifieke scenario kunt berekenen met behulp van de functie <strong>mcc()<\/strong> uit het <b>mltools-<\/b> pakket in R.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Voorbeeld: Berekening van de Matthews-correlatieco\u00ebffici\u00ebnt in R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">De volgende code laat zien hoe u een vector van voorspelde klassen en een vector van werkelijke klassen definieert, en vervolgens de Matthews-correlatieco\u00ebffici\u00ebnt berekent met behulp van de functie <strong>mcc()<\/strong> uit het <strong>mltools-<\/strong> pakket:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (mltools)\n\n<span style=\"color: #008080;\">#define vector of actual classes\n<\/span>actual &lt;- <span style=\"color: #008000;\">rep<\/span> (c(1, 0), <span style=\"color: #008000;\">times<\/span> =c(20, 380))\n\n<span style=\"color: #008080;\">#define vector of predicted classes\n<\/span>preds &lt;- <span style=\"color: #008000;\">rep<\/span> (c(1, 0, 1, 0), <span style=\"color: #008000;\">times<\/span> =c(15, 5, 5, 375))\n\n<span style=\"color: #008080;\">#calculate Matthews correlation coefficient\n<\/span>mcc(preds, actual)\n\n[1] 0.7368421\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">De Matthews-correlatieco\u00ebffici\u00ebnt is <strong>0,7368<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dit komt overeen met de waarde die we eerder handmatig hebben berekend.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als u de Matthews-correlatieco\u00ebffici\u00ebnt voor een verwarringsmatrix wilt berekenen, kunt u het <strong>verwarringM-<\/strong> argument als volgt gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (mltools)\n\n<span style=\"color: #008080;\">#create confusion matrix\n<\/span>conf_matrix &lt;- matrix(c(15, 5, 5, 375), nrow= <span style=\"color: #008000;\">2<\/span> )\n\n<span style=\"color: #008080;\">#view confusion matrix\n<\/span>conf_matrix\n\n     [,1] [,2]\n[1,] 15 5\n[2,] 5,375\n\n<span style=\"color: #008080;\">#calculate Matthews correlation coefficient for confusion matrix\n<\/span>mcc(confusionM = conf_matrix)\n\n[1] 0.7368421\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Opnieuw is de Matthews-correlatieco\u00ebffici\u00ebnt <strong>0,7368.<\/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> Hoe logistische regressie uit te voeren in R<br \/> <a href=\"https:\/\/statorials.org\/nl\/rotskromme-ggplot2\/\" target=\"_blank\" rel=\"noopener\">Hoe een ROC-curve te plotten met ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/f1-score-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe de F1-score in R te berekenen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Matthews Correlatie Co\u00ebffici\u00ebnt (MCC) is een metriek die we kunnen gebruiken om de prestaties van een classificatiemodel te evalueren. Het wordt als volgt berekend: MCC = (TP*TN \u2013 FP*FN) \/ \u221a (TP+FP)(TP+FN)(TN+FP)(TN+FN) Goud: TP : Aantal echte positieven TN : Aantal echte negatieven FP : Aantal valse positieven FN : Aantal valse negatieven Deze metriek [&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-3614","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 Matthews-correlatieco\u00ebffici\u00ebnt in R - Statorials te berekenen<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u de Matthews-correlatieco\u00ebffici\u00ebnt in R kunt berekenen.\" \/>\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\/matthews-correlatiecoefficient-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 Matthews-correlatieco\u00ebffici\u00ebnt in R - Statorials te berekenen\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u de Matthews-correlatieco\u00ebffici\u00ebnt in R kunt berekenen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-16T13:19:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/equilibre1.png\" \/>\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\/matthews-correlatiecoefficient-in-r\/\",\"url\":\"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/\",\"name\":\"Hoe de Matthews-correlatieco\u00ebffici\u00ebnt in R - Statorials te berekenen\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-16T13:19:31+00:00\",\"dateModified\":\"2023-07-16T13:19:31+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u de Matthews-correlatieco\u00ebffici\u00ebnt in R kunt berekenen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe de matthews-correlatieco\u00ebffici\u00ebnt 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 Matthews-correlatieco\u00ebffici\u00ebnt in R - Statorials te berekenen","description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u de Matthews-correlatieco\u00ebffici\u00ebnt in R kunt berekenen.","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\/matthews-correlatiecoefficient-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe de Matthews-correlatieco\u00ebffici\u00ebnt in R - Statorials te berekenen","og_description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u de Matthews-correlatieco\u00ebffici\u00ebnt in R kunt berekenen.","og_url":"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-16T13:19:31+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/equilibre1.png"}],"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\/matthews-correlatiecoefficient-in-r\/","url":"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/","name":"Hoe de Matthews-correlatieco\u00ebffici\u00ebnt in R - Statorials te berekenen","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-16T13:19:31+00:00","dateModified":"2023-07-16T13:19:31+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt aan de hand van een voorbeeld uitgelegd hoe u de Matthews-correlatieco\u00ebffici\u00ebnt in R kunt berekenen.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/matthews-correlatiecoefficient-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe de matthews-correlatieco\u00ebffici\u00ebnt 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\/3614","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=3614"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3614\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}