{"id":1618,"date":"2023-07-25T15:30:37","date_gmt":"2023-07-25T15:30:37","guid":{"rendered":"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/"},"modified":"2023-07-25T15:30:37","modified_gmt":"2023-07-25T15:30:37","slug":"r-quantil-por-grupo","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/","title":{"rendered":"Como calcular quantis por grupo em r (com exemplos)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Nas estat\u00edsticas, <strong>os quantis<\/strong> s\u00e3o valores que dividem um conjunto de dados classificados em grupos iguais.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para calcular quantis agrupados por uma determinada vari\u00e1vel em R, podemos usar as seguintes fun\u00e7\u00f5es do pacote <a href=\"https:\/\/dplyr.tidyverse.org\/\" target=\"_blank\" rel=\"noopener\">dplyr<\/a> em R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#define quantiles of interest\n<\/span>q = c(.25, .5, .75)\n\n<span style=\"color: #008080;\">#calculate quantiles by grouping variable\n<\/span>df %&gt;%\n  group_by(grouping_variable) %&gt;%\n  summarize(quant25 = <span style=\"color: #3366ff;\">quantile<\/span> (numeric_variable, probs = q[1]), \n            quant50 = <span style=\"color: #3366ff;\">quantile<\/span> (numeric_variable, probs = q[2]),\n            quant75 = <span style=\"color: #3366ff;\">quantile<\/span> (numeric_variable, probs = q[3]))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como usar essa sintaxe na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplos: Quantis por grupo em R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como calcular quantis do n\u00famero de vit\u00f3rias agrupadas por equipe para um conjunto de dados em R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\">library<\/span> (dplyr)\n\n<span style=\"color: #008080;\">#create data\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',\n                        'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B',\n                        'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C'),\n                 wins=c(2, 4, 4, 5, 7, 9, 13, 13, 15, 15, 14, 13,\n                        11, 9, 9, 8, 8, 16, 19, 21, 24, 20, 19, 18))\n\n<span style=\"color: #008080;\">#view first six rows of data<\/span>\nhead(df)\n\n  team wins\n1 TO 2\n2 to 4\n3 to 4\n4 to 5\n5 TO 7\n6 to 9\n\n<span style=\"color: #008080;\">#define quantiles of interest\n<\/span>q = c(.25, .5, .75)\n\n<span style=\"color: #008080;\">#calculate quantiles by grouping variable\n<\/span>df %&gt;%\n  group_by(team) %&gt;%\n  summarize(quant25 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[1]), \n            quant50 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[2]),\n            quant75 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[3]))\n\n  team quant25 quant50 quant75           \n1 to 4 6 10  \n2 B 9 12 14.2\n3 C 17.5 19 20.2\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Observe que tamb\u00e9m podemos especificar qualquer n\u00famero de quantis que desejarmos:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define quantiles of interest\n<\/span>q = c(.2, .4, .6, .8)\n\n<span style=\"color: #008080;\">#calculate quantiles by grouping variable\n<\/span>df %&gt;%\n  group_by(team) %&gt;%\n  summarize(quant20 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[1]), \n            quant40 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[2]),\n            quant60 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[3]),\n            quant80 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = q[4]))\n\n  team quant20 quant40 quant60 quant80\n              \n1 to 4 4.8 7.4 11.4\n2 B 9 10.6 13.2 14.6\n3 C 16.8 18.8 19.2 20.6\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Voc\u00ea tamb\u00e9m pode optar por calcular um \u00fanico quantil por grupo. Por exemplo, veja como calcular o percentil 90 do n\u00famero de vit\u00f3rias de cada equipe:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#calculate 90th percentile of wins by team\n<\/span>df %&gt;%\n  group_by(team) %&gt;%\n  summarize(quant90 = <span style=\"color: #3366ff;\">quantile<\/span> (wins, probs = <span style=\"color: #008000;\">0.9<\/span> ))\n\n   team quant90\n     \n1 to 13  \n2 B 15  \n3 C 21.9\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pt\/quartis-em-r\/\" target=\"_blank\" rel=\"noopener\">Como calcular quartis em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/decis-em-r\/\" target=\"_blank\" rel=\"noopener\">Como calcular decis em R<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/percentis-em-r\/\" target=\"_blank\" rel=\"noopener\">Como calcular percentis em R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nas estat\u00edsticas, os quantis s\u00e3o valores que dividem um conjunto de dados classificados em grupos iguais. Para calcular quantis agrupados por uma determinada vari\u00e1vel em R, podemos usar as seguintes fun\u00e7\u00f5es do pacote dplyr em R: library (dplyr) #define quantiles of interest q = c(.25, .5, .75) #calculate quantiles by grouping variable df %&gt;% group_by(grouping_variable) [&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-1618","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 quantis por grupo em R (com exemplos)<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como calcular quantis por grupo em R, com v\u00e1rios exemplos.\" \/>\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\/r-quantil-por-grupo\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como calcular quantis por grupo em R (com exemplos)\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como calcular quantis por grupo em R, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T15:30:37+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\/r-quantil-por-grupo\/\",\"url\":\"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/\",\"name\":\"Como calcular quantis por grupo em R (com exemplos)\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-25T15:30:37+00:00\",\"dateModified\":\"2023-07-25T15:30:37+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como calcular quantis por grupo em R, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como calcular quantis por grupo em r (com exemplos)\"}]},{\"@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 quantis por grupo em R (com exemplos)","description":"Este tutorial explica como calcular quantis por grupo em R, com v\u00e1rios exemplos.","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\/r-quantil-por-grupo\/","og_locale":"pt_PT","og_type":"article","og_title":"Como calcular quantis por grupo em R (com exemplos)","og_description":"Este tutorial explica como calcular quantis por grupo em R, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/","og_site_name":"Statorials","article_published_time":"2023-07-25T15:30:37+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\/r-quantil-por-grupo\/","url":"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/","name":"Como calcular quantis por grupo em R (com exemplos)","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-25T15:30:37+00:00","dateModified":"2023-07-25T15:30:37+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como calcular quantis por grupo em R, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/r-quantil-por-grupo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como calcular quantis por grupo em r (com exemplos)"}]},{"@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\/1618","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=1618"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/1618\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=1618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=1618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=1618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}