Created
April 25, 2022 14:50
-
-
Save DATAUNIRIO/6eeb23dfb24f321a9bb61e4117a796d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Desvio-Padrão e duas variáveis qualitativas" | |
subtitle: "proporção e tabelas" | |
author: "Prof. Steven Dutt Ross" | |
date: "25/04/2022" | |
output: | |
html_document: | |
theme: darkly | |
highlight: tango | |
toc: true | |
toc_float: true | |
code_folding: hide | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
``` | |
## Desvio - Padrão | |
```{r} | |
# rua azul | |
azul<-c(70,65,55,70,75) | |
media_azul <- mean(azul) | |
variancia_azul <- var(azul) | |
dp_azul <- sd(azul) | |
dp_azul | |
sqrt(variancia_azul) | |
# rua vermelha | |
vermelho<-c(40,95,55,80,65) | |
media_vermelho <- mean(vermelho) | |
variancia_vermelho <- var(vermelho) | |
dp_vermelho <-sd(vermelho) | |
dp_vermelho | |
sqrt(variancia_vermelho) | |
``` | |
A rua vermelha tem um desvio-padrão maior que a rua azul. | |
## Desvio - Padrão em uma base de dados | |
```{r, warning=FALSE,message=FALSE} | |
library(readr) | |
Fifa <- read_csv("C:/Users/Hp/Desktop/Base_de_dados-master/FifaData.csv") | |
#View(Fifa) | |
dp_velocidade <- sd(Fifa$Speed) | |
dp_velocidade | |
mean(Fifa$Speed) | |
``` | |
## Cruzamento de duas variáveis | |
* Quali X Quali | |
* Quanti X Quanti | |
* Quali X Quanti | |
```{r} | |
# Fase 1 - Carregar um banco de dados | |
load("C:/Users/Hp/Desktop/Base_de_dados-master/Titanic.RData") | |
``` | |
## Perguntas | |
Mulheres e crianças primeiro. isso aconteceu de fato? | |
Teve desigualdade da sobrevivência? | |
# Variáveis | |
variável de interesse: sobrevivência | |
preditores lineares: sexo, idade, e classe | |
## Análise por sexo | |
```{r,warning=FALSE,message=FALSE,echo=TRUE} | |
tabela_sexo <- table(Titanic$Sexo,Titanic$Sobreviveu) | |
#tabela_sexo | |
#prop.table(tabela_sexo,1)%>% round(digits = 2) | |
#prop.table(tabela_sexo,2) | |
library(dplyr) | |
library(flextable) | |
tabela_sexo %>% | |
prop.table(1) %>% | |
round(digits = 2) %>% | |
data.frame() %>% | |
flextable() %>% | |
set_header_labels(Var1="sexo",Var2="sobrevivencia",Freq="percentual") %>% | |
#bg(bg = "#EFEF99") | |
theme_tron() | |
``` | |
Teve uma diferença entre homens e mulheres! | |
## Análise por Idade | |
```{r} | |
tabela_idade <- table(Titanic$Idade,Titanic$Sobreviveu) | |
prop.table(tabela_idade,1) %>% data.frame() %>% flextable() %>% theme_vader()%>% | |
set_header_labels(Var1="idade",Var2="sobrevivencia",Freq="percentual") | |
``` | |
Teve uma diferença entre adultos e crianças no tange a sobrevivência. | |
Hipótese confimada! Mulheres e crianças primeiro. | |
# Análise por classe | |
abaixo, temos duas tabelas simples de proporção. | |
```{r} | |
tabela_classe <- table(Titanic$Classe,Titanic$Sobreviveu) | |
tabela_classe | |
prop.table(tabela_classe,1) | |
prop.table(tabela_classe,2) | |
``` | |
abaixo temos a primeira tentativa do gráfico de barras | |
```{r} | |
par(bg="lightyellow") | |
barplot(tabela_classe,beside = T, | |
main="Desigualdade da sobrevivência", | |
col=c("pink","red","blue","skyblue")) | |
``` | |
versão final do gráfico de barras | |
```{r,warning=FALSE,message=FALSE,comment=NA} | |
tabela_classe2 <- table(Titanic$Sobreviveu,Titanic$Classe) | |
barplot(tabela_classe2,beside=T,col=c("red","blue"), | |
ylim =c(0,750), legend.text = rownames(tabela_classe2)) | |
``` | |
# Conclusão | |
teve uma desigualdade da sobrevivência | |
hipótese confirmada! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://glin.github.io/reactable/articles/womens-world-cup/womens-world-cup.html
https://mran.revolutionanalytics.com/snapshot/2019-02-07/web/packages/flextable/vignettes/examples.html
https://aulas.metodosquantitativos.com/desviopadrao/#1
https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html
https://glin.github.io/reactable/