Skip to content

Instantly share code, notes, and snippets.

@DATAUNIRIO
Created October 30, 2025 14:45
Show Gist options
  • Select an option

  • Save DATAUNIRIO/b92482520319cc014fd2b94b0f81cabd to your computer and use it in GitHub Desktop.

Select an option

Save DATAUNIRIO/b92482520319cc014fd2b94b0f81cabd to your computer and use it in GitHub Desktop.
Razao de chances e teste de fisher
link = 'https://github.com/DATAUNIRIO/dados_para_aula/raw/refs/heads/main/csv/Titanic.csv'
link2 ='https://github.com/DATAUNIRIO/dados_para_aula/raw/refs/heads/main/csv/students.csv'
titanic = read.delim2(link,sep = ";")
estudantes = read.csv(link2)
table(estudantes$Sex,estudantes$Major)
library(forcats)
estudantes$Novo_Major = fct_lump(estudantes$Major, n = 3)
table(estudantes$Sex,estudantes$Novo_Major)
probabilidade_mulher = 7/(1+7+6+5)
probabilidade_homem = 9/(8+9+3+9)
homem = 9/(8+3+9)
mulher = 7/(1+6+5)
mulher/homem
#------------------------------------------------------------------------------
estudantes$estatistica = ifelse(estudantes$Novo_Major=="statistics",1,0)
modelo = glm(estatistica ~ Sex, binomial(link = "logit"), data = estudantes)
summary(modelo)
exp(-0.2595)
1/exp(-0.2595)
#----------------------------------------------------------------------------
### Tabela para o teste
M <- as.table(rbind(c(762, 468), c(484, 477)))
### Rótulos para tabela
dimnames(M) <- list(sexo = c("Feminino", "Masculino"),
partido = c("PT", "PL"))
fmpt =((762+484)*(762+468))/2191
mspt =((762+484)*(477+484))/2191
fmpl =((762+468)*(477+468))/2191
mspl =((477+484)*(477+468))/2191
teste = chisq.test(M)
teste$expected
#### Gráfico
library("gplots")
balloonplot(t(M), main ="Partido", xlab ="", ylab="",
label = FALSE, show.margins = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment