{"id":3613,"date":"2023-07-16T13:19:31","date_gmt":"2023-07-16T13:19:31","guid":{"rendered":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/"},"modified":"2023-07-16T13:19:31","modified_gmt":"2023-07-16T13:19:31","slug":"coeficiente-de-correlacao-de-matthews-em-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/","title":{"rendered":"Como calcular o coeficiente de correla\u00e7\u00e3o de matthews em r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>O Coeficiente de Correla\u00e7\u00e3o de Matthews<\/strong> (MCC) \u00e9 uma m\u00e9trica que podemos usar para avaliar o desempenho de um <a href=\"https:\/\/statorials.org\/pt\/regressao-vs.-classificacao\/\" target=\"_blank\" rel=\"noopener\">modelo de classifica\u00e7\u00e3o<\/a> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">\u00c9 calculado da seguinte forma:<\/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;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>TP<\/strong> : N\u00famero de verdadeiros positivos<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>TN<\/strong> : N\u00famero de verdadeiros negativos<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FP<\/strong> : N\u00famero de falsos positivos<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>FN<\/strong> : N\u00famero de falsos negativos<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Esta m\u00e9trica \u00e9 particularmente \u00fatil quando as duas classes est\u00e3o desequilibradas, ou seja, uma classe aparece muito mais que a outra.<\/span><\/p>\n<p> <span style=\"color: #000000;\">O valor de MCC est\u00e1 entre -1 e 1 onde:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>-1<\/strong> indica discord\u00e2ncia total entre as aulas previstas e as aulas reais<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>0<\/strong> significa suposi\u00e7\u00f5es completamente aleat\u00f3rias<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>1<\/strong> indica concord\u00e2ncia completa entre as aulas previstas e as aulas reais<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Por exemplo, suponha que um analista esportivo use um <a href=\"https:\/\/statorials.org\/pt\/regressao-logistica-1\/\" target=\"_blank\" rel=\"noopener\">modelo de regress\u00e3o log\u00edstica<\/a> para prever se 400 jogadores diferentes de basquete universit\u00e1rio ser\u00e3o ou n\u00e3o convocados para a NBA.<\/span><\/p>\n<p> <span style=\"color: #000000;\">A seguinte matriz de confus\u00e3o resume as previs\u00f5es feitas pelo modelo:<\/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;\">Para calcular o MCC do modelo, podemos utilizar a seguinte f\u00f3rmula:<\/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;\">O coeficiente de correla\u00e7\u00e3o de Matthews \u00e9 <strong>0,7368<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este valor \u00e9 um pouco pr\u00f3ximo de um, indicando que o modelo est\u00e1 fazendo um trabalho decente ao prever se os jogadores ser\u00e3o convocados ou n\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\">O exemplo a seguir mostra como calcular o MCC para este cen\u00e1rio espec\u00edfico usando a fun\u00e7\u00e3o <strong>mcc()<\/strong> do pacote <b>mltools<\/b> em R.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo: Calculando o Coeficiente de Correla\u00e7\u00e3o de Matthews em R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como definir um vetor de classes previstas e um vetor de classes reais e, em seguida, calcular o coeficiente de correla\u00e7\u00e3o de Matthews usando a fun\u00e7\u00e3o <strong>mcc()<\/strong> do pacote <strong>mltools<\/strong> :<\/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;\">O coeficiente de correla\u00e7\u00e3o de Matthews \u00e9 <strong>0,7368<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Isso corresponde ao valor que calculamos manualmente anteriormente.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se quiser calcular o coeficiente de correla\u00e7\u00e3o de Matthews para uma matriz de confus\u00e3o, voc\u00ea pode usar o argumento <strong>confus\u00e3oM<\/strong> da seguinte forma:<\/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;\">Novamente, o coeficiente de correla\u00e7\u00e3o de Matthews \u00e9 <strong>0,7368.<\/strong><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outras tarefas comuns em R:<\/span><\/p>\n<p> Como realizar regress\u00e3o log\u00edstica em R<br \/> <a href=\"https:\/\/statorials.org\/pt\/curva-de-rocha-ggplot2\/\" target=\"_blank\" rel=\"noopener\">Como tra\u00e7ar uma curva ROC usando ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/pontuacao-f1-em-r\/\" target=\"_blank\" rel=\"noopener\">Como calcular a pontua\u00e7\u00e3o F1 em R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O Coeficiente de Correla\u00e7\u00e3o de Matthews (MCC) \u00e9 uma m\u00e9trica que podemos usar para avaliar o desempenho de um modelo de classifica\u00e7\u00e3o . \u00c9 calculado da seguinte forma: MCC = (TP*TN \u2013 FP*FN) \/ \u221a (TP+FP)(TP+FN)(TN+FP)(TN+FN) Ouro: TP : N\u00famero de verdadeiros positivos TN : N\u00famero de verdadeiros negativos FP : N\u00famero de falsos positivos [&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-3613","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R - Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R, com um exemplo.\" \/>\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\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R, com um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-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. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/\",\"url\":\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/\",\"name\":\"Como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-16T13:19:31+00:00\",\"dateModified\":\"2023-07-16T13:19:31+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R, com um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como calcular o coeficiente de correla\u00e7\u00e3o de matthews em r\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R - Estatologia","description":"Este tutorial explica como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R, com um exemplo.","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\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/","og_locale":"pt_PT","og_type":"article","og_title":"Como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R - Estatologia","og_description":"Este tutorial explica como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R, com um exemplo.","og_url":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-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. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/","url":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/","name":"Como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-16T13:19:31+00:00","dateModified":"2023-07-16T13:19:31+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como calcular o coeficiente de correla\u00e7\u00e3o de Matthews em R, com um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/coeficiente-de-correlacao-de-matthews-em-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como calcular o coeficiente de correla\u00e7\u00e3o de matthews em r"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/3613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=3613"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/3613\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=3613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=3613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=3613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}