{"id":840,"date":"2023-07-28T14:09:15","date_gmt":"2023-07-28T14:09:15","guid":{"rendered":"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/"},"modified":"2023-07-28T14:09:15","modified_gmt":"2023-07-28T14:09:15","slug":"teste-mcnemars-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/","title":{"rendered":"Como realizar o teste mcnemar em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>O teste de McNemar<\/strong> \u00e9 usado para determinar se h\u00e1 diferen\u00e7a estatisticamente significativa nas propor\u00e7\u00f5es entre dados pareados.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial explica como realizar o teste McNemar em Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo: o teste McNemar em Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Digamos que os pesquisadores queiram saber se um determinado v\u00eddeo de marketing pode mudar a opini\u00e3o das pessoas sobre uma determinada lei. Eles entrevistaram 100 pessoas para descobrir se apoiam ou n\u00e3o a lei. Em seguida, eles mostram o v\u00eddeo de marketing para todas as 100 pessoas e as pesquisam novamente ap\u00f3s a conclus\u00e3o do v\u00eddeo.<\/span><\/p>\n<p> <span style=\"color: #000000;\">A tabela a seguir mostra o n\u00famero total de pessoas que apoiaram a lei antes e depois de assistir ao v\u00eddeo:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<th><\/th>\n<th colspan=\"2\"> <span style=\"color: #000000;\">V\u00eddeo antes do marketing<\/span><\/th>\n<\/tr>\n<tr>\n<td> <span style=\"color: #000000;\">V\u00eddeo ap\u00f3s marketing<\/span><\/td>\n<td> <span style=\"color: #000000;\"><strong>Apoiar<\/strong><\/span><\/td>\n<td> <span style=\"color: #000000;\"><strong>N\u00e3o aguento<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td> <span style=\"color: #000000;\"><strong>Apoiar<\/strong><\/span><\/td>\n<td> <span style=\"color: #000000;\">30<\/span><\/td>\n<td> <span style=\"color: #000000;\">40<\/span><\/td>\n<\/tr>\n<tr>\n<td> <span style=\"color: #000000;\"><strong>N\u00e3o aguento<\/strong><\/span><\/td>\n<td> <span style=\"color: #000000;\">12<\/span><\/td>\n<td> <span style=\"color: #000000;\">18<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> <span style=\"color: #000000;\">Para determinar se houve diferen\u00e7a estatisticamente significativa na propor\u00e7\u00e3o de pessoas que apoiaram a lei antes e depois de assistir ao v\u00eddeo, podemos realizar o teste de McNemar.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Etapa 1: crie os dados.<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Primeiro, criaremos uma tabela para armazenar nossos dados:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>data = [[30, 40],\n         [12, 18]]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Passo 2: Realize o teste de McNemar<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">A seguir, podemos usar a <a href=\"https:\/\/www.statsmodels.org\/dev\/generated\/statsmodels.stats.contingency_tables.mcnemar.html\" target=\"_blank\" rel=\"noopener\">fun\u00e7\u00e3o mcnemar()<\/a> da biblioteca python statsmodels, que usa a seguinte sintaxe:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>mcnemar(matriz, exato=Verdadeiro, corre\u00e7\u00e3o=Verdadeiro)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>tabela:<\/strong> Uma tabela de conting\u00eancia quadrada<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>exato:<\/strong> se exato for verdadeiro, ent\u00e3o a distribui\u00e7\u00e3o binomial ser\u00e1 usada. Se correto for falso, ent\u00e3o a distribui\u00e7\u00e3o qui-quadrado ser\u00e1 usada<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>corre\u00e7\u00e3o:<\/strong> se verdadeiro, uma corre\u00e7\u00e3o de continuidade \u00e9 usada. Normalmente, essa corre\u00e7\u00e3o geralmente \u00e9 aplicada quando o n\u00famero de c\u00e9lulas da tabela \u00e9 menor que 5.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como usar esta fun\u00e7\u00e3o em nosso exemplo espec\u00edfico:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">from<\/span> statsmodels.stats.contingency_tables <span style=\"color: #008000;\">import<\/span> mcnemar\n\n<span style=\"color: #008080;\">#McNemar's Test with no continuity correction<\/span>\nprint(mcnemar(data, exact=False))\n\npvalue 0.000181\nstatistic 14.019\n\n<span style=\"color: #008080;\">#McNemar's Test with continuity correction<\/span>\nprint(mcnemar(data, exact=False, correction=False))\n\npvalue 0.000103\nstatistic 15,077<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Em ambos os casos \u2013 aplicada ou n\u00e3o a corre\u00e7\u00e3o de continuidade \u2013 o valor p do teste \u00e9 inferior a 0,05.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Isto significa que em ambos os casos rejeitar\u00edamos a hip\u00f3tese nula e concluir\u00edamos que a propor\u00e7\u00e3o de pessoas que apoiaram a lei antes e depois de verem o v\u00eddeo de marketing era estatisticamente diferente.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O teste de McNemar \u00e9 usado para determinar se h\u00e1 diferen\u00e7a estatisticamente significativa nas propor\u00e7\u00f5es entre dados pareados. Este tutorial explica como realizar o teste McNemar em Python. Exemplo: o teste McNemar em Python Digamos que os pesquisadores queiram saber se um determinado v\u00eddeo de marketing pode mudar a opini\u00e3o das pessoas sobre uma determinada [&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-840","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 realizar o teste McNemar em Python \u2013 Estatologia<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples de como realizar o teste McNemar em Python.\" \/>\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\/teste-mcnemars-python\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como realizar o teste McNemar em Python \u2013 Estatologia\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples de como realizar o teste McNemar em Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T14:09:15+00:00\" \/>\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\/teste-mcnemars-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/\",\"name\":\"Como realizar o teste McNemar em Python \u2013 Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T14:09:15+00:00\",\"dateModified\":\"2023-07-28T14:09:15+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples de como realizar o teste McNemar em Python.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como realizar o teste mcnemar em python\"}]},{\"@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 realizar o teste McNemar em Python \u2013 Estatologia","description":"Uma explica\u00e7\u00e3o simples de como realizar o teste McNemar em Python.","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\/teste-mcnemars-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como realizar o teste McNemar em Python \u2013 Estatologia","og_description":"Uma explica\u00e7\u00e3o simples de como realizar o teste McNemar em Python.","og_url":"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T14:09:15+00:00","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\/teste-mcnemars-python\/","url":"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/","name":"Como realizar o teste McNemar em Python \u2013 Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T14:09:15+00:00","dateModified":"2023-07-28T14:09:15+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples de como realizar o teste McNemar em Python.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/teste-mcnemars-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/teste-mcnemars-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como realizar o teste mcnemar em python"}]},{"@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\/840","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=840"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/840\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}