{"id":1637,"date":"2023-07-25T13:50:04","date_gmt":"2023-07-25T13:50:04","guid":{"rendered":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/"},"modified":"2023-07-25T13:50:04","modified_gmt":"2023-07-25T13:50:04","slug":"breusch-godfrey-teste-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/","title":{"rendered":"Como realizar um teste breusch-godfrey em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um dos <a href=\"https:\/\/statorials.org\/pt\/suposicoes-de-regressao-linear\/\" target=\"_blank\" rel=\"noopener\">principais pressupostos da regress\u00e3o linear<\/a> \u00e9 que n\u00e3o h\u00e1 correla\u00e7\u00e3o entre os res\u00edduos, ou seja, os res\u00edduos s\u00e3o independentes.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para testar a autocorrela\u00e7\u00e3o de primeira ordem, podemos realizar um <a href=\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/\" target=\"_blank\" rel=\"noopener\">teste de Durbin-Watson<\/a> . No entanto, se quisermos testar a autocorrela\u00e7\u00e3o em ordens superiores, precisamos realizar um <strong>teste de Breusch-Godfrey<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este teste usa as seguintes <a href=\"https:\/\/statorials.org\/pt\/teste-de-hipotese-1\/\" target=\"_blank\" rel=\"noopener\">suposi\u00e7\u00f5es<\/a> :<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>H <sub>0<\/sub> (hip\u00f3tese nula):<\/strong> N\u00e3o h\u00e1 autocorrela\u00e7\u00e3o de ordem menor ou igual a <em>p<\/em> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong><sub>HA<\/sub> (hip\u00f3tese alternativa):<\/strong> Existe uma autocorrela\u00e7\u00e3o de certa ordem menor ou igual a <em>p<\/em> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">A estat\u00edstica de teste segue uma distribui\u00e7\u00e3o qui-quadrado com <em>p<\/em> graus de liberdade.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se o <a href=\"https:\/\/statorials.org\/pt\/p-valores-significancia-estatistica\/\" target=\"_blank\" rel=\"noopener\">valor p<\/a> que corresponde a esta estat\u00edstica de teste estiver abaixo de um certo n\u00edvel de signific\u00e2ncia (por exemplo, 0,05), ent\u00e3o podemos rejeitar a hip\u00f3tese nula e concluir que existe uma autocorrela\u00e7\u00e3o entre os res\u00edduos numa certa ordem inferior ou igual a <em>p<\/em> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para realizar um teste Breusch-Godfrey em Python, voc\u00ea pode usar a fun\u00e7\u00e3o <strong>acorr_breusch_godfrey()<\/strong> da biblioteca <b>statsmodels<\/b> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">O exemplo passo a passo a seguir explica como realizar o teste Breusch-Godfrey em Python.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Etapa 1: crie os dados<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Primeiro, vamos criar um conjunto de dados contendo duas vari\u00e1veis preditoras (x1 e x2) e uma vari\u00e1vel de resposta (y).<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> pandas <span style=\"color: #008000;\">as<\/span> pd<\/span>\n\n#create dataset<\/span>\ndf = pd. <span style=\"color: #3366ff;\">DataFrame<\/span> ({' <span style=\"color: #ff0000;\">x1<\/span> ': [3, 4, 4, 5, 8, 9, 11, 13, 14, 16, 17, 20],\n                   ' <span style=\"color: #ff0000;\">x2<\/span> ': [7, 7, 8, 8, 12, 4, 5, 15, 9, 17, 19, 19],\n                    ' <span style=\"color: #ff0000;\">y<\/span> ': [24, 25, 25, 27, 29, 31, 34, 34, 39, 30, 40, 49]})\n\n<span style=\"color: #008080;\">#view first five rows of dataset\n<\/span>df. <span style=\"color: #3366ff;\">head<\/span> ()\n\n\tx1 x2 y\n0 3 7 24\n1 4 7 25\n2 4 8 25\n3 5 8 27\n4 8 12 29\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Passo 2: Ajustar um modelo de regress\u00e3o<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Ent\u00e3o podemos ajustar um <a href=\"https:\/\/statorials.org\/pt\/regressao-linear-multipla\/\" target=\"_blank\" rel=\"noopener\">modelo de regress\u00e3o linear m\u00faltipla<\/a> usando x1 e x2 como vari\u00e1veis preditoras e y como <a href=\"https:\/\/statorials.org\/pt\/respostas-explicativas-das-variaveis\/\" target=\"_blank\" rel=\"noopener\">vari\u00e1vel de resposta<\/a> .<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">import<\/span> statsmodels. <span style=\"color: #3366ff;\">api<\/span> <span style=\"color: #008000;\">as<\/span> sm\n\n<span style=\"color: #008080;\">#define response variable\n<\/span>y = df[' <span style=\"color: #ff0000;\">y<\/span> ']\n\n<span style=\"color: #008080;\">#define predictor variables\n<\/span>x = df[[' <span style=\"color: #ff0000;\">x1<\/span> ', ' <span style=\"color: #ff0000;\">x2<\/span> ']]\n\n<span style=\"color: #008080;\">#add constant to predictor variables\n<\/span>x = sm. <span style=\"color: #3366ff;\">add_constant<\/span> (x)\n\n<span style=\"color: #008080;\">#fit linear regression model\n<\/span>model = sm. <span style=\"color: #3366ff;\">OLS<\/span> (y,x). <span style=\"color: #3366ff;\">fit<\/span> ()\n<\/strong><\/span><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Passo 3: Realize o teste Breusch-Godfrey<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">A seguir, realizaremos o teste de Breusch-Godfrey para testar a autocorrela\u00e7\u00e3o entre os res\u00edduos na ordem <em>p<\/em> . Para este exemplo, escolheremos <em>p<\/em> = 3.<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> statsmodels. <span style=\"color: #3366ff;\">stats<\/span> . <span style=\"color: #3366ff;\">diagnosis<\/span> <span style=\"color: #008000;\">as<\/span> dg\n<\/span>\n#perform Breusch-Godfrey test at order <em>p<\/em> = 3\n<span style=\"color: #000000;\"><span style=\"color: #993300;\">print<\/span> (dg. <span style=\"color: #3366ff;\">acorr_breusch_godfrey<\/span> (model, nlags= <span style=\"color: #008000;\">3<\/span> ))\n\n(8.70314827, 0.0335094873, 5.27967224, 0.0403980576)\n<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">O primeiro valor da sa\u00edda representa a estat\u00edstica de teste e o segundo valor representa o valor p correspondente.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Do resultado podemos ver o seguinte:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Estat\u00edstica de teste X <sup>2<\/sup> = <strong>8,7031<\/strong><\/span><\/li>\n<li> <span style=\"color: #000000;\">Valor P = <strong>0,0335<\/strong><\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Como este valor p \u00e9 inferior a 0,05, podemos rejeitar a hip\u00f3tese nula e concluir que existe uma autocorrela\u00e7\u00e3o entre os res\u00edduos de ordem menor ou igual a 3.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Como lidar com a autocorrela\u00e7\u00e3o<\/strong><\/span><\/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<ul data-slot-rendered-dynamic=\"true\">\n<li> <span style=\"color: #000000;\">Para correla\u00e7\u00e3o serial positiva, considere adicionar defasagens da vari\u00e1vel dependente e\/ou independente ao modelo.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Para correla\u00e7\u00e3o serial negativa, certifique-se de que nenhuma de suas vari\u00e1veis esteja <em>atrasada demais<\/em> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">Para correla\u00e7\u00e3o sazonal, considere adicionar dummies sazonais ao modelo.<\/span><\/li>\n<\/ul>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pt\/regressao-linear-python\/\" target=\"_blank\" rel=\"noopener\">Um guia completo para regress\u00e3o linear em Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/teste-durbin-watson-em-python\/\" target=\"_blank\" rel=\"noopener\">Como realizar um teste Durbin-Watson em Python<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/teste-de-caixa-ljung-python\/\" target=\"_blank\" rel=\"noopener\">Como realizar um teste Ljung-Box em Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um dos principais pressupostos da regress\u00e3o linear \u00e9 que n\u00e3o h\u00e1 correla\u00e7\u00e3o entre os res\u00edduos, ou seja, os res\u00edduos s\u00e3o independentes. Para testar a autocorrela\u00e7\u00e3o de primeira ordem, podemos realizar um teste de Durbin-Watson . No entanto, se quisermos testar a autocorrela\u00e7\u00e3o em ordens superiores, precisamos realizar um teste de Breusch-Godfrey . Este teste usa [&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-1637","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 de Breusch-Godfrey em Python - Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como realizar um teste Breusch-Godfrey em Python, 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\/breusch-godfrey-teste-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 de Breusch-Godfrey em Python - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como realizar um teste Breusch-Godfrey em Python, com um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T13:50:04+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=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/\",\"name\":\"Como realizar um teste de Breusch-Godfrey em Python - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-25T13:50:04+00:00\",\"dateModified\":\"2023-07-25T13:50:04+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como realizar um teste Breusch-Godfrey em Python, com um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como realizar um teste breusch-godfrey 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 de Breusch-Godfrey em Python - Estatologia","description":"Este tutorial explica como realizar um teste Breusch-Godfrey em Python, 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\/breusch-godfrey-teste-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como realizar um teste de Breusch-Godfrey em Python - Estatologia","og_description":"Este tutorial explica como realizar um teste Breusch-Godfrey em Python, com um exemplo.","og_url":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/","og_site_name":"Statorials","article_published_time":"2023-07-25T13:50:04+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/","url":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/","name":"Como realizar um teste de Breusch-Godfrey em Python - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-25T13:50:04+00:00","dateModified":"2023-07-25T13:50:04+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como realizar um teste Breusch-Godfrey em Python, com um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/breusch-godfrey-teste-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como realizar um teste breusch-godfrey 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\/1637","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=1637"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/1637\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=1637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=1637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=1637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}