Carregando pacotes
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.3 ✓ dplyr 1.0.2
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(cluster)
library(dendextend)
##
## ---------------------
## Welcome to dendextend version 1.14.0
## Type citation('dendextend') for how to cite the package.
##
## Type browseVignettes(package = 'dendextend') for the package vignette.
## The github page is: https://github.com/talgalili/dendextend/
##
## Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues
## Or contact: <tal.galili@gmail.com>
##
## To suppress this message use: suppressPackageStartupMessages(library(dendextend))
## ---------------------
##
## Attaching package: 'dendextend'
## The following object is masked from 'package:stats':
##
## cutree
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
Análise para alunos
Verificando dados
head(dados_alunos)
Análise descritiva - Sociodemográfica
table<-with(dados_alunos,table(sexo))
table
## sexo
## feminino masculino
## 55 51
prop.table(table)
## sexo
## feminino masculino
## 0.5188679 0.4811321
table <- with(dados_alunos,table(cor))
table
## cor
## Amarela branco morena
## 1 56 6
## naosabe/naorespondeu parda preta
## 17 21 5
prop.table(table)
## cor
## Amarela branco morena
## 0.009433962 0.528301887 0.056603774
## naosabe/naorespondeu parda preta
## 0.160377358 0.198113208 0.047169811
table <- with(dados_alunos,table(serie))
table
## serie
## 1 2 3
## 32 42 32
prop.table(table)
## serie
## 1 2 3
## 0.3018868 0.3962264 0.3018868
table <- with(dados_alunos,table(conh_instituicao))
table
## conh_instituicao
## Amigo do meu pai Amigos
## 1 25
## Coral cantou na minha igreja Escola
## 1 1
## FamÃlia Internet
## 66 1
## Pastor da igreja da minha mãe Pela igreja
## 1 2
## Pesquisando no Google Por meio da empresa Gazin
## 1 1
## Redes Sociais
## 6
prop.table(table)
## conh_instituicao
## Amigo do meu pai Amigos
## 0.009433962 0.235849057
## Coral cantou na minha igreja Escola
## 0.009433962 0.009433962
## FamÃlia Internet
## 0.622641509 0.009433962
## Pastor da igreja da minha mãe Pela igreja
## 0.009433962 0.018867925
## Pesquisando no Google Por meio da empresa Gazin
## 0.009433962 0.009433962
## Redes Sociais
## 0.056603774
table <- with(dados_alunos,table(tempo_aluno))
table
## tempo_aluno
## 2 3 4 5 6 8 12 13 15 16 17 18 19 24 26 28 30 36 48
## 7 11 5 1 5 3 11 1 3 2 4 2 1 21 1 1 3 20 4
prop.table(table)
## tempo_aluno
## 2 3 4 5 6 8
## 0.066037736 0.103773585 0.047169811 0.009433962 0.047169811 0.028301887
## 12 13 15 16 17 18
## 0.103773585 0.009433962 0.028301887 0.018867925 0.037735849 0.018867925
## 19 24 26 28 30 36
## 0.009433962 0.198113208 0.009433962 0.009433962 0.028301887 0.188679245
## 48
## 0.037735849
table <- with(dados_alunos,table(acomp_psicologico))
table
## acomp_psicologico
## Não Sim
## 91 15
prop.table(table)
## acomp_psicologico
## Não Sim
## 0.8584906 0.1415094
Análise Escala de Bem estar Psicológico
alunos_ebep<-with(dados_alunos,data.frame(aluno,rel_pos, autonomia, ambiente, crescimento, proposito, autoaceitacao))
head(alunos_ebep)
Transformar o nome dos alunos em linhas
rownames(alunos_ebep) <- alunos_ebep[,1]
alunos_ebep <- alunos_ebep[,-1]
Padronizar variaveis
#Padronizar variaveis
alunos_ebep.padronizado <- scale(alunos_ebep)
Rodar o modelo - 2 clusters
alunos_ebep.k2 <- kmeans(alunos_ebep.padronizado, centers = 2)
Grafico - 2 clusters
G2 <- fviz_cluster(alunos_ebep.k2, geom = "point", data = alunos_ebep.padronizado) + ggtitle("k = 2")
G2
Rodar o modelo - 3 clusters
alunos_ebep.k3 <- kmeans(alunos_ebep.padronizado, centers = 3)
Grafico - 3 clusters
G3 <- fviz_cluster(alunos_ebep.k3, geom = "point", data = alunos_ebep.padronizado) + ggtitle("k = 3")
G3
Rodar o modelo - 4 clusters
alunos_ebep.k4 <- kmeans(alunos_ebep.padronizado, centers = 4)
Grafico - 4 clusters
G4 <- fviz_cluster(alunos_ebep.k4, geom = "point", data = alunos_ebep.padronizado) + ggtitle("k = 4")
G4
Rodar o modelo - 5 clusters
alunos_ebep.k5 <- kmeans(alunos_ebep.padronizado, centers = 5)
Grafico - 5 clusters
G5 <- fviz_cluster(alunos_ebep.k5, geom = "point", data = alunos_ebep.padronizado) + ggtitle("k = 5")
G5
VERIFICANDO ELBOW E SILHOUTTE
fviz_nbclust(alunos_ebep.padronizado, kmeans, method = "wss")
fviz_nbclust(alunos_ebep.padronizado, kmeans, method = "silhouette")
#PARA EXPLORAR OS DADOS, JUNTANDO TABELAS:
alunosfit <- data.frame(alunos_ebep.k2$cluster)
alunosfinal <- cbind(dados_alunos, alunosfit)
salvando novo banco
write.csv(alunosfinal, "alunosfinal.csv")