A relação agora será verificada com todos os dados juntos, referentes aos anos de 2011, 2013, 2015, 2017 e 2019.
library(tidyverse)
library(readr)
library(readxl)
library(rstatix)
library(ggpubr)
library(gridExtra)
saeb_2011 <- read_csv("base de dados/base_saeb_inse_2011.csv")[,-1]
saeb_2013 <- read_csv("base de dados/base_saeb_inse_2013.csv")[,-1]
saeb_2015 <- read_csv("base de dados/base_saeb_inse_2015.csv")[,-1]
saeb_2017 <- read_csv("base de dados/base_saeb_inse_2017.csv")[,-1]
saeb_2019 <- read_csv("base de dados/base_saeb_inse_2019.csv")[,-1]
Precisou-se corrigir os dados do INSE dos anos 2011, 2013 e 2019, pois, houve problema devido ao acento agudo das palavras.
a <- gsub("[^[:alnum:]]","1", saeb_2011$inse)
a <- gsub("11", "e", a)
a <- gsub("1", " ", a)
saeb_2011$inse <- a
a <- gsub("[^[:alnum:]]","1", saeb_2013$inse)
a <- gsub("11", "e", a)
a <- gsub("1", " ", a)
saeb_2013$inse <- a
a <- gsub("[^[:alnum:]]","1", saeb_2019$inse)
a <- gsub("11", "i", a)
a <- gsub("1", " ", a)
saeb_2019$inse <- a
remove(a)
saeb_inse_2011_2019 <- saeb_2011 %>% full_join(saeb_2013, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% full_join(saeb_2015, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% full_join(saeb_2017, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% full_join(saeb_2019, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% convert_as_factor(inse,rede)
glimpse(saeb_inse_2011_2019)
## Rows: 6,490
## Columns: 5
## $ ano <dbl> 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2~
## $ id_escola <dbl> 26106582, 26106612, 26106698, 26106701, 26106728,~
## $ rede <fct> estadual, estadual, estadual, estadual, estadual,~
## $ nota_saeb_matematica <dbl> 221.91, 232.53, 244.20, 241.24, 208.44, 220.05, 2~
## $ inse <fct> Medio, Medio, Medio, Medio, Medio, Medio, Medio, ~
Através do boxplot conseguimos ver que a nota de de matemática no SAEB dos estudantesd e escola pública foram aumentando ao longo dos anos, saindo da proficiência insuficiente para básica. Também pode-se perceber que a rede municipal acaba superando a estadual em desempenho a partir de 2017. Percebe-se que a maior parte dos alunos se encontra na proficiência básica (entre as linhas vermelhas)
a_part1 <- saeb_2011 %>% full_join(saeb_2013, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% select(ano, inse) %>% table() %>% data.frame()
a_part2 <- saeb_2015 %>% full_join(saeb_2017, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% select(ano, inse) %>% table() %>% data.frame()
a_part3 <- saeb_2019 %>% select(ano, inse) %>% table() %>% data.frame()
a_part1$inse <- factor(a_part1$inse, levels = c("Muito Baixo", "Baixo", "Medio Baixo", "Medio", "Medio Alto", "Alto", "Muito Alto"))
p1 <- a_part1 %>% ggplot(aes(x = inse, y = Freq, fill = inse)) + geom_bar(stat = "identity") + facet_wrap(~ano, scales = "free") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(fill=guide_legend(ncol=2))
p2 <- a_part2 %>% ggplot(aes(x = inse, y = Freq, fill = inse)) + geom_bar(stat = "identity") + facet_wrap(~ano, scales = "free") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(fill=guide_legend(ncol=2))
p3 <- a_part3 %>% ggplot(aes(x = inse, y = Freq, fill = inse)) + geom_bar(stat = "identity") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(fill=guide_legend(nrow=2))
lay <- rbind(c(1,1,1,1),
c(2,2,2,2),
c(3,3,3,3))
grid.arrange(p1, p2, p3, layout_matrix = lay)
O Gráfico acima apresenta um panorama do nível socioeconômico das escolas ao longo dos anos a partir da relação da variável frequência (Freq) e índice de nível socioeconômico (inse). No ano de 2019 não constava nenhum dado referente ao Nível I do INSE, por isso o mesmo não aparece no gráfico. Pode-se destacar dois pontos a partir do gráfico acima: O terceiro grupo socioeconômico predomina como o nível que representa grande parte das escolas; E a frequência do quarto grupo apresenta uma queda significativa após 2013, assim como o grupo do “Nível II” em 2019.
Utilizou-se o teste de kolmogorov para verificar a normalidade.
ks.test(saeb_2011$nota_saeb_matematica, rnorm(1360))
## Warning in ks.test(saeb_2011$nota_saeb_matematica, rnorm(1360)): p-value will be
## approximate in the presence of ties
##
## Two-sample Kolmogorov-Smirnov test
##
## data: saeb_2011$nota_saeb_matematica and rnorm(1360)
## D = 1, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(saeb_2013$nota_saeb_matematica, rnorm(1371))
## Warning in ks.test(saeb_2013$nota_saeb_matematica, rnorm(1371)): p-value will be
## approximate in the presence of ties
##
## Two-sample Kolmogorov-Smirnov test
##
## data: saeb_2013$nota_saeb_matematica and rnorm(1371)
## D = 1, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(saeb_2015$nota_saeb_matematica, rnorm(1279))
## Warning in ks.test(saeb_2015$nota_saeb_matematica, rnorm(1279)): p-value will be
## approximate in the presence of ties
##
## Two-sample Kolmogorov-Smirnov test
##
## data: saeb_2015$nota_saeb_matematica and rnorm(1279)
## D = 1, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(saeb_2017$nota_saeb_matematica, rnorm(1180))
## Warning in ks.test(saeb_2017$nota_saeb_matematica, rnorm(1180)): p-value will be
## approximate in the presence of ties
##
## Two-sample Kolmogorov-Smirnov test
##
## data: saeb_2017$nota_saeb_matematica and rnorm(1180)
## D = 0.99915, p-value < 2.2e-16
## alternative hypothesis: two-sided
ks.test(saeb_2019$nota_saeb_matematica, rnorm(1300))
## Warning in ks.test(saeb_2019$nota_saeb_matematica, rnorm(1300)): p-value will be
## approximate in the presence of ties
##
## Two-sample Kolmogorov-Smirnov test
##
## data: saeb_2019$nota_saeb_matematica and rnorm(1300)
## D = 1, p-value < 2.2e-16
## alternative hypothesis: two-sided
Todos apresentaram uma distribuição não-normal, satisfazendo a condição para o teste de Kruskal-Wallis
res_teste_kruskal_2011 <- saeb_2011 %>% kruskal_test(nota_saeb_matematica ~ inse)
res_teste_kruskal_2011
## # A tibble: 1 x 6
## .y. n statistic df p method
## * <chr> <int> <dbl> <int> <dbl> <chr>
## 1 nota_saeb_matematica 1360 72.7 6 1.13e-13 Kruskal-Wallis
res_teste_kruskal_2013 <- saeb_2013 %>% kruskal_test(nota_saeb_matematica ~ inse)
res_teste_kruskal_2013
## # A tibble: 1 x 6
## .y. n statistic df p method
## * <chr> <int> <dbl> <int> <dbl> <chr>
## 1 nota_saeb_matematica 1371 43.0 6 0.000000119 Kruskal-Wallis
res_teste_kruskal_2015 <- saeb_2015 %>% kruskal_test(nota_saeb_matematica ~ inse)
res_teste_kruskal_2015
## # A tibble: 1 x 6
## .y. n statistic df p method
## * <chr> <int> <dbl> <int> <dbl> <chr>
## 1 nota_saeb_matematica 1279 83.9 5 1.27e-16 Kruskal-Wallis
res_teste_kruskal_2017 <- saeb_2017 %>% kruskal_test(nota_saeb_matematica ~ inse)
res_teste_kruskal_2017
## # A tibble: 1 x 6
## .y. n statistic df p method
## * <chr> <int> <dbl> <int> <dbl> <chr>
## 1 nota_saeb_matematica 1180 34.8 5 0.00000166 Kruskal-Wallis
res_teste_kruskal_2019 <- saeb_2019 %>% kruskal_test(nota_saeb_matematica ~ inse)
res_teste_kruskal_2019
## # A tibble: 1 x 6
## .y. n statistic df p method
## * <chr> <int> <dbl> <int> <dbl> <chr>
## 1 nota_saeb_matematica 1300 29.2 5 0.000021 Kruskal-Wallis
Todos apresentaram diferença estatisticamente significativa entre alguns dos grupos.
res_efeito_kruskal_2011 <- saeb_2011 %>% kruskal_effsize(nota_saeb_matematica ~ inse)
res_efeito_kruskal_2011
## # A tibble: 1 x 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 nota_saeb_matematica 1360 0.0493 eta2[H] small
res_efeito_kruskal_2013 <- saeb_2013 %>% kruskal_effsize(nota_saeb_matematica ~ inse)
res_efeito_kruskal_2013
## # A tibble: 1 x 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 nota_saeb_matematica 1371 0.0271 eta2[H] small
res_efeito_kruskal_2015 <- saeb_2015 %>% kruskal_effsize(nota_saeb_matematica ~ inse)
res_efeito_kruskal_2015
## # A tibble: 1 x 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 nota_saeb_matematica 1279 0.0620 eta2[H] moderate
res_efeito_kruskal_2017 <- saeb_2017 %>% kruskal_effsize(nota_saeb_matematica ~ inse)
res_efeito_kruskal_2017
## # A tibble: 1 x 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 nota_saeb_matematica 1180 0.0254 eta2[H] small
res_efeito_kruskal_2019 <- saeb_2019 %>% kruskal_effsize(nota_saeb_matematica ~ inse)
res_efeito_kruskal_2019
## # A tibble: 1 x 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 nota_saeb_matematica 1300 0.0187 eta2[H] small
Todos os anos apresentaram uma relação pequena entre as variáveis, exceto o ano de 2015 que apresentou uma relação moderada.
res_dunn_test_2011 <- saeb_2011 %>% dunn_test(nota_saeb_matematica ~ inse, p.adjust.method = "bonferroni") %>% filter(p.adj.signif != "ns") %>% select(group1, group2, n1, n2, p.adj, p.adj.signif)
res_dunn_test_2011
## # A tibble: 6 x 6
## group1 group2 n1 n2 p.adj p.adj.signif
## <chr> <chr> <int> <int> <dbl> <chr>
## 1 Baixo Medio 154 513 3.53e- 6 ****
## 2 Baixo Medio Alto 154 31 1.13e-11 ****
## 3 Baixo Medio Baixo 154 658 1.20e- 6 ****
## 4 Medio Medio Alto 513 31 7.89e- 6 ****
## 5 Medio Alto Medio Baixo 31 658 7.73e- 6 ****
## 6 Medio Alto Muito Baixo 31 2 9.22e- 3 **
res_dunn_test_2013 <- saeb_2013 %>% dunn_test(nota_saeb_matematica ~ inse, p.adjust.method = "bonferroni") %>% filter(p.adj.signif != "ns") %>% select(group1, group2, n1, n2, p.adj, p.adj.signif)
res_dunn_test_2013
## # A tibble: 4 x 6
## group1 group2 n1 n2 p.adj p.adj.signif
## <chr> <chr> <int> <int> <dbl> <chr>
## 1 Baixo Medio 133 534 0.0110 *
## 2 Baixo Medio Alto 133 37 0.000000309 ****
## 3 Medio Medio Alto 534 37 0.000520 ***
## 4 Medio Alto Medio Baixo 37 664 0.0000699 ****
res_dunn_test_2015 <- saeb_2015 %>% dunn_test(nota_saeb_matematica ~ inse, p.adjust.method = "bonferroni") %>% filter(p.adj.signif != "ns") %>% select(group1, group2, n1, n2, p.adj, p.adj.signif)
res_dunn_test_2015
## # A tibble: 6 x 6
## group1 group2 n1 n2 p.adj p.adj.signif
## <chr> <chr> <int> <int> <dbl> <chr>
## 1 Grupo 1 Grupo 2 76 488 5.10e- 3 **
## 2 Grupo 1 Grupo 3 76 693 1.46e- 8 ****
## 3 Grupo 1 Grupo 4 76 20 6.15e-11 ****
## 4 Grupo 2 Grupo 3 488 693 7.61e- 6 ****
## 5 Grupo 2 Grupo 4 488 20 1.79e- 7 ****
## 6 Grupo 3 Grupo 4 693 20 1.44e- 4 ***
res_dunn_test_2017 <- saeb_2017 %>% dunn_test(nota_saeb_matematica ~ inse, p.adjust.method = "bonferroni") %>% filter(p.adj.signif != "ns") %>% select(group1, group2, n1, n2, p.adj, p.adj.signif)
res_dunn_test_2017
## # A tibble: 3 x 6
## group1 group2 n1 n2 p.adj p.adj.signif
## <chr> <chr> <int> <int> <dbl> <chr>
## 1 Grupo 1 Grupo 4 80 17 0.00000114 ****
## 2 Grupo 2 Grupo 4 489 17 0.00000703 ****
## 3 Grupo 3 Grupo 4 592 17 0.0000531 ****
res_dunn_test_2019 <- saeb_2019 %>% dunn_test(nota_saeb_matematica ~ inse, p.adjust.method = "bonferroni") %>% filter(p.adj.signif != "ns") %>% select(group1, group2, n1, n2, p.adj, p.adj.signif)
res_dunn_test_2019
## # A tibble: 3 x 6
## group1 group2 n1 n2 p.adj p.adj.signif
## <chr> <chr> <int> <int> <dbl> <chr>
## 1 Nivel II Nivel V 165 9 0.00131 **
## 2 Nivel III Nivel V 769 9 0.00152 **
## 3 Nivel IV Nivel V 355 9 0.0132 *
A partir do teste de Dunn é possível ver quais grupos tiverem relação significativa.
Antes de plotar precisou-se ordenar os INSE que estão como fatores para plotar devidamente.
my_comparisons_2011 <- list( c("Muito Baixo", "Medio Alto"), c("Baixo", "Medio Baixo"), c("Baixo", "Medio"), c("Baixo", "Medio Alto"), c("Medio Baixo", "Medio Alto"), c("Medio", "Medio Alto"))
my_comparisons_2013 <- list(c("Baixo", "Medio"), c("Baixo", "Medio Alto"), c("Medio Baixo", "Medio Alto"), c("Medio", "Medio Alto"))
my_comparisons_2015 <- list( c("Grupo 1", "Grupo 2"), c("Grupo 1", "Grupo 3"), c("Grupo 1", "Grupo 4"), c("Grupo 2", "Grupo 3"), c("Grupo 2", "Grupo 4"), c("Grupo 3", "Grupo 4"))
my_comparisons_2017 <- list(c("Grupo 1", "Grupo 4"), c("Grupo 2", "Grupo 4"), c("Grupo 3", "Grupo 4"))
my_comparisons_2019 <- list( c("Nivel II", "Nivel V"), c("Nivel III", "Nivel V"), c("Nivel IV", "Nivel V"))
saeb_2011$inse <- factor(saeb_2011$inse, levels = c("Muito Baixo", "Baixo", "Medio Baixo", "Medio", "Medio Alto", "Alto", "Muito Alto"))
saeb_2013$inse <- factor(saeb_2013$inse, levels = c("Muito Baixo", "Baixo", "Medio Baixo", "Medio", "Medio Alto", "Alto", "Muito Alto"))
saeb_2015$inse <- factor(saeb_2015$inse, levels = c("Grupo 1", "Grupo 2", "Grupo 3", "Grupo 4", "Grupo 5", "Grupo 6"))
saeb_2017$inse <- factor(saeb_2017$inse, levels = c("Grupo 1", "Grupo 2", "Grupo 3", "Grupo 4", "Grupo 5", "Grupo 6"))
saeb_2019$inse <- factor(saeb_2019$inse, levels = c("Nivel I", "Nivel II", "Nivel III", "Nivel IV", "Nivel V", "Nivel VI", "Nivel VII"))
plot_2011 <- saeb_2011 %>% filter(inse != "Alto" & inse != "Muito Alto") %>% ggboxplot(x = "inse", y = "nota_saeb_matematica", color = "inse", bxp.errorbar = TRUE, facet.by = "rede") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + stat_compare_means(comparisons = my_comparisons_2011) + labs(subtitle = get_test_label(res_teste_kruskal_2011, type = "expression", detailed = TRUE), caption = get_pwc_label(res_dunn_test_2011, type = "expression"), x = "INSE 2011", y = "Nota SAEB Matematica 2011") + guides(color=guide_legend(nrow=2)) + guides(labs = guide_legend(nrow=2))
plot_2013 <- saeb_2013 %>% filter(inse != "Alto" & inse != "Muito Alto" & inse != "Muito Baixo") %>% ggboxplot(x = "inse", y = "nota_saeb_matematica", color = "inse", bxp.errorbar = TRUE, facet.by = "rede") + stat_compare_means(comparisons = my_comparisons_2013) + labs(subtitle = get_test_label(res_teste_kruskal_2013, type = "expression", detailed = TRUE), caption = get_pwc_label(res_dunn_test_2013, type = "expression"), x = "INSE 2013", y = "Nota SAEB Matematica 2013")+ theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(color=guide_legend(nrow=2)) + guides(labs = guide_legend(nrow=2))
plot_2015 <- saeb_2015 %>% filter(inse != "Grupo 5" & inse != "Grupo 6") %>% ggboxplot(x = "inse", y = "nota_saeb_matematica", color = "inse", bxp.errorbar = TRUE, facet.by = "rede") + stat_compare_means(comparisons = my_comparisons_2015) + labs(subtitle = get_test_label(res_teste_kruskal_2015, type = "expression", detailed = TRUE), caption = get_pwc_label(res_dunn_test_2015, type = "expression"), x = "INSE 2015", y = "Nota SAEB Matematica 2015")+ theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(color=guide_legend(nrow=2)) + guides(labs = guide_legend(nrow=2))
plot_2017 <- saeb_2017 %>% filter(inse != "Grupo 5" & inse != "Grupo 6") %>% ggboxplot(x = "inse", y = "nota_saeb_matematica", color = "inse", bxp.errorbar = TRUE, facet.by = "rede") + stat_compare_means(comparisons = my_comparisons_2017) + labs(subtitle = get_test_label(res_teste_kruskal_2017, type = "expression", detailed = TRUE), caption = get_pwc_label(res_dunn_test_2017, type = "expression"), x = "INSE 2017", y = "Nota SAEB Matematica 2017")+ theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(color=guide_legend(nrow=2)) + guides(labs = guide_legend(nrow=2))
plot_2019 <- saeb_2019 %>% filter(inse == "Nivel II" | inse == "Nivel III" | inse == "Nivel IV" | inse == "Nivel V" ) %>% ggboxplot(x = "inse", y = "nota_saeb_matematica", color = "inse", bxp.errorbar = TRUE, facet.by = "rede") + stat_compare_means(comparisons = my_comparisons_2019) + labs(subtitle = get_test_label(res_teste_kruskal_2019, type = "expression", detailed = TRUE), caption = get_pwc_label(res_dunn_test_2019, type = "expression"), x = "INSE 2019", y = "Nota SAEB Matematica 2019")+ theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(color=guide_legend(nrow=2)) + guides(labs = guide_legend(nrow=2))
plot_2011
plot_2013
plot_2015
## Warning in wilcox.test.default(c(240.18, 242.59, 242.05, 228.82, 249.65, :
## cannot compute exact p-value with ties
plot_2017
plot_2019
É possível ver a diferença significativa entre os INSE.
b_part1 <- saeb_2011 %>% full_join(saeb_2013, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% select(ano, nota_saeb_matematica,inse)
b_part2 <- saeb_2015 %>% full_join(saeb_2017, by = c("ano" = "ano", "id_escola" = "id_escola", "rede" = "rede", "nota_saeb_matematica" = "nota_saeb_matematica", "inse" = "inse")) %>% select(ano, nota_saeb_matematica,inse)
b_part3 <- saeb_2019 %>% select(ano, nota_saeb_matematica,inse)
b_part1$inse <- factor(b_part1$inse, levels = c("Muito Baixo", "Baixo", "Medio Baixo", "Medio", "Medio Alto", "Alto", "Muito Alto"))
g1 <- b_part1 %>% ggplot(aes(x = inse, y = nota_saeb_matematica, fill = inse)) + geom_boxplot() + facet_wrap(~ano, scales = "free") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(fill=guide_legend(ncol=2))
g2 <- b_part2 %>% ggplot(aes(x = inse, y = nota_saeb_matematica, fill = inse)) + geom_boxplot() + facet_wrap(~ano, scales = "free") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(fill=guide_legend(ncol=2))
g3 <- b_part3 %>% ggplot(aes(x = inse, y = nota_saeb_matematica, fill = inse)) + geom_boxplot() + facet_wrap(~ano, scales = "free") + theme(axis.text.x = element_text(angle = 60, hjust = 1)) + guides(fill=guide_legend(ncol=2))
lay <- rbind(c(1,1,1,1),
c(2,2,2,2),
c(3,3,3,3))
grid.arrange(g1, g2, g3, layout_matrix = lay)
Isso poderia significar que a qualidade da educação vem melhorando já que a diferença tende a diminuir com o aumento da qualidade de ensino das escolas públicas.