{"id":870,"date":"2023-07-28T11:41:06","date_gmt":"2023-07-28T11:41:06","guid":{"rendered":"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/"},"modified":"2023-07-28T11:41:06","modified_gmt":"2023-07-28T11:41:06","slug":"teste-durbin-watson-em-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/","title":{"rendered":"Como realizar um teste durbin-watson em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Uma das<\/span> <a href=\"https:\/\/statorials.org\/pt\/suposicoes-de-regressao-linear\/\" target=\"_blank\" rel=\"noopener\">premissas da regress\u00e3o linear<\/a> <span style=\"color: #000000;\">\u00e9 que n\u00e3o h\u00e1 correla\u00e7\u00e3o entre os res\u00edduos. Em outras palavras, os res\u00edduos s\u00e3o considerados independentes.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Uma forma de determinar se esta suposi\u00e7\u00e3o \u00e9 atendida \u00e9 realizar um <a href=\"https:\/\/statorials.org\/pt\/teste-de-durbin-watson\/\" target=\"_blank\" rel=\"noopener\">teste de Durbin-Watson<\/a> , que \u00e9 usado para detectar a presen\u00e7a de autocorrela\u00e7\u00e3o nos res\u00edduos de uma <a href=\"https:\/\/statorials.org\/pt\/regressao-linear-python\/\" target=\"_blank\" rel=\"noopener\">regress\u00e3o<\/a> . Este teste usa as seguintes suposi\u00e7\u00f5es:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>H <sub>0<\/sub> (hip\u00f3tese nula):<\/strong> N\u00e3o h\u00e1 correla\u00e7\u00e3o entre os res\u00edduos.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>H <sub>A<\/sub> (hip\u00f3tese alternativa):<\/strong> Os res\u00edduos s\u00e3o autocorrelacionados.<\/span><\/p>\n<p> <span style=\"color: #000000;\">A estat\u00edstica de teste \u00e9 aproximadamente igual a 2*(1-r) onde r \u00e9 a autocorrela\u00e7\u00e3o amostral dos res\u00edduos. Assim, a estat\u00edstica do teste estar\u00e1 sempre entre 0 e 4 com a seguinte interpreta\u00e7\u00e3o:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Uma estat\u00edstica de teste de <strong>2<\/strong> indica que n\u00e3o h\u00e1 correla\u00e7\u00e3o serial.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Quanto mais pr\u00f3ximas as estat\u00edsticas do teste estiverem de <strong>0<\/strong> , mais evid\u00eancias haver\u00e1 de uma correla\u00e7\u00e3o serial positiva.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Quanto mais pr\u00f3ximas as estat\u00edsticas do teste estiverem de <strong>4<\/strong> , mais evid\u00eancias haver\u00e1 de uma correla\u00e7\u00e3o serial negativa.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Normalmente, valores estat\u00edsticos de teste entre 1,5 e 2,5 s\u00e3o considerados normais. Entretanto, valores fora dessa faixa podem indicar que a autocorrela\u00e7\u00e3o \u00e9 um problema.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial explica como realizar um teste Durbin-Watson em Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo: teste Durbin-Watson em Python<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte conjunto de dados que descreve os atributos de 10 jogadores de basquete:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">import<\/span> numpy <span style=\"color: #107d3f;\">as<\/span> np\n<span style=\"color: #107d3f;\">import<\/span> pandas <span style=\"color: #107d3f;\">as<\/span> pd\n\n<span style=\"color: #008080;\">#create dataset<\/span>\ndf = pd.DataFrame({'rating': [90, 85, 82, 88, 94, 90, 76, 75, 87, 86],\n                   'points': [25, 20, 14, 16, 27, 20, 12, 15, 14, 19],\n                   'assists': [5, 7, 7, 8, 5, 7, 6, 9, 9, 5],\n                   'rebounds': [11, 8, 10, 6, 6, 9, 6, 10, 10, 7]})\n\n<span style=\"color: #008080;\">#view dataset\n<\/span>df\n\n\trating points assists rebounds\n0 90 25 5 11\n1 85 20 7 8\n2 82 14 7 10\n3 88 16 8 6\n4 94 27 5 6\n5 90 20 7 9\n6 76 12 6 6\n7 75 15 9 10\n8 87 14 9 10\n9 86 19 5 7<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Suponha que ajustemos um modelo de regress\u00e3o linear m\u00faltipla usando <em>classifica\u00e7\u00e3o<\/em> como vari\u00e1vel de resposta e as outras tr\u00eas vari\u00e1veis como vari\u00e1veis preditoras:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> statsmodels.formula.api <span style=\"color: #107d3f;\">import<\/span> ols\n\n<span style=\"color: #008080;\">#fit multiple linear regression model\n<\/span>model = ols('rating ~ points + assists + rebounds', data=df). <span style=\"color: #3366ff;\">fit<\/span> ()\n\n<span style=\"color: #008080;\">#view model summary\n<\/span>print(model.summary())\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Podemos realizar um Watson Durbin usando a <a href=\"https:\/\/www.statsmodels.org\/stable\/generated\/statsmodels.stats.stattools.durbin_watson.html\" target=\"_blank\" rel=\"noopener\">fun\u00e7\u00e3o durbin_watson()<\/a> da biblioteca statsmodels para determinar se os res\u00edduos do modelo de regress\u00e3o s\u00e3o autocorrelacionados:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #107d3f;\">from<\/span> statsmodels.stats.stattools <span style=\"color: #107d3f;\">import<\/span> durbin_watson\n\n<span style=\"color: #008080;\">#perform Durbin-Watson test\n<\/span>durbin_watson(model.resid)\n\n2,392<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A estat\u00edstica de teste \u00e9 <strong>2.392<\/strong> . Como este valor est\u00e1 entre 1,5 e 2,5, consideramos que a autocorrela\u00e7\u00e3o n\u00e3o \u00e9 um problema neste modelo de regress\u00e3o.<\/span><\/p>\n<h3> <strong>Como lidar com a autocorrela\u00e7\u00e3o<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Se voc\u00ea rejeitar a hip\u00f3tese nula e concluir que a autocorrela\u00e7\u00e3o est\u00e1 presente nos res\u00edduos, voc\u00ea ter\u00e1 v\u00e1rias op\u00e7\u00f5es para corrigir esse problema se consider\u00e1-lo suficientemente s\u00e9rio:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>1.<\/strong> Para correla\u00e7\u00e3o serial positiva, considere adicionar defasagens da vari\u00e1vel dependente e\/ou independente ao modelo.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>2.<\/strong> Para correla\u00e7\u00e3o serial negativa, certifique-se de que nenhuma de suas vari\u00e1veis <em>esteja atrasada demais<\/em> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>3.<\/strong> Para correla\u00e7\u00e3o sazonal, considere adicionar dummies sazonais ao modelo.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uma das premissas da regress\u00e3o linear \u00e9 que n\u00e3o h\u00e1 correla\u00e7\u00e3o entre os res\u00edduos. Em outras palavras, os res\u00edduos s\u00e3o considerados independentes. Uma forma de determinar se esta suposi\u00e7\u00e3o \u00e9 atendida \u00e9 realizar um teste de Durbin-Watson , que \u00e9 usado para detectar a presen\u00e7a de autocorrela\u00e7\u00e3o nos res\u00edduos de uma regress\u00e3o . Este teste [&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-870","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 um teste Durbin-Watson em Python - Estatologia<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples sobre como realizar um teste Durbin-Watson 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-durbin-watson-em-python\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como realizar um teste Durbin-Watson em Python - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples sobre como realizar um teste Durbin-Watson em Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T11:41:06+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-durbin-watson-em-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/\",\"name\":\"Como realizar um teste Durbin-Watson em Python - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T11:41:06+00:00\",\"dateModified\":\"2023-07-28T11:41:06+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples sobre como realizar um teste Durbin-Watson em Python.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como realizar um teste durbin-watson 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 um teste Durbin-Watson em Python - Estatologia","description":"Uma explica\u00e7\u00e3o simples sobre como realizar um teste Durbin-Watson 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-durbin-watson-em-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como realizar um teste Durbin-Watson em Python - Estatologia","og_description":"Uma explica\u00e7\u00e3o simples sobre como realizar um teste Durbin-Watson em Python.","og_url":"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T11:41:06+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-durbin-watson-em-python\/","url":"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/","name":"Como realizar um teste Durbin-Watson em Python - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T11:41:06+00:00","dateModified":"2023-07-28T11:41:06+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples sobre como realizar um teste Durbin-Watson em Python.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como realizar um teste durbin-watson 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\/870","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=870"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/870\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}