# Carregar base de dados
library(readxl)
planilha2 <- read_excel("C:/Users/clara/Downloads/planilha2.xlsx")
View(planilha2)
# Execução e manipulação da tabela
library(DT)
DT::datatable(planilha2, rownames = FALSE, colnames = FALSE)echo = FALSEecho = FALSE
library(readr)
student_mat <- read_csv("C:/Users/Clara/OneDrive/Documentos/R/student-mat.csv")## Rows: 395 Columns: 33
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (17): school, sex, address, famsize, Pstatus, Mjob, Fjob, reason, guardi...
## dbl (16): age, Medu, Fedu, traveltime, studytime, failures, famrel, freetime...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(student_mat)
# inspecionar os dados
summary(student_mat)## school sex age address
## Length:395 Length:395 Min. :15.0 Length:395
## Class :character Class :character 1st Qu.:16.0 Class :character
## Mode :character Mode :character Median :17.0 Mode :character
## Mean :16.7
## 3rd Qu.:18.0
## Max. :22.0
## famsize Pstatus Medu Fedu
## Length:395 Length:395 Min. :0.000 Min. :0.000
## Class :character Class :character 1st Qu.:2.000 1st Qu.:2.000
## Mode :character Mode :character Median :3.000 Median :2.000
## Mean :2.749 Mean :2.522
## 3rd Qu.:4.000 3rd Qu.:3.000
## Max. :4.000 Max. :4.000
## Mjob Fjob reason guardian
## Length:395 Length:395 Length:395 Length:395
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## traveltime studytime failures schoolsup
## Min. :1.000 Min. :1.000 Min. :0.0000 Length:395
## 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:0.0000 Class :character
## Median :1.000 Median :2.000 Median :0.0000 Mode :character
## Mean :1.448 Mean :2.035 Mean :0.3342
## 3rd Qu.:2.000 3rd Qu.:2.000 3rd Qu.:0.0000
## Max. :4.000 Max. :4.000 Max. :3.0000
## famsup paid activities nursery
## Length:395 Length:395 Length:395 Length:395
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## higher internet romantic famrel
## Length:395 Length:395 Length:395 Min. :1.000
## Class :character Class :character Class :character 1st Qu.:4.000
## Mode :character Mode :character Mode :character Median :4.000
## Mean :3.944
## 3rd Qu.:5.000
## Max. :5.000
## freetime goout Dalc Walc
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:3.000 1st Qu.:2.000 1st Qu.:1.000 1st Qu.:1.000
## Median :3.000 Median :3.000 Median :1.000 Median :2.000
## Mean :3.235 Mean :3.109 Mean :1.481 Mean :2.291
## 3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:2.000 3rd Qu.:3.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
## health absences G1 G2
## Min. :1.000 Min. : 0.000 Min. : 3.00 Min. : 0.00
## 1st Qu.:3.000 1st Qu.: 0.000 1st Qu.: 8.00 1st Qu.: 9.00
## Median :4.000 Median : 4.000 Median :11.00 Median :11.00
## Mean :3.554 Mean : 5.709 Mean :10.91 Mean :10.71
## 3rd Qu.:5.000 3rd Qu.: 8.000 3rd Qu.:13.00 3rd Qu.:13.00
## Max. :5.000 Max. :75.000 Max. :19.00 Max. :19.00
## G3
## Min. : 0.00
## 1st Qu.: 8.00
## Median :11.00
## Mean :10.42
## 3rd Qu.:14.00
## Max. :20.00
# Carregar biblioteca de dados
library(flextable)
library(dplyr)##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(reactable)
# Cruzamento de variáveis
student_mat %>% select (Walc,address) %>%
group_by(address) %>%
summarise(minimo=min(Walc),
primeiro_quartil=quantile(Walc, probs=0.25),
mediana=median(Walc),
terceiro_quartil = quantile(Walc, probs=0.75),
maximo=max(Walc))%>%
flextable() %>% theme_vanilla()address | minimo | primeiro_quartil | mediana | terceiro_quartil | maximo |
R | 1 | 1 | 2 | 3 | 5 |
U | 1 | 1 | 2 | 3 | 5 |
# Gerar uma visualização dessa tabela
boxplot(Walc~address, data = student_mat,
col=c("pink1", "tomato"),
horizontal = T,
main= "Boxplot da relação entre local de moradia e consumo de álcool nos fins de semana")echo = FALSE
# carregar base de dados
library(readr)
student_mat <- read_csv("C:/Users/Clara/OneDrive/Documentos/R/student-mat.csv")## Rows: 395 Columns: 33
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (17): school, sex, address, famsize, Pstatus, Mjob, Fjob, reason, guardi...
## dbl (16): age, Medu, Fedu, traveltime, studytime, failures, famrel, freetime...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(student_mat)
# visualização de dados
par(bg="snow")
par(cex=1.0)
plot(student_mat$absences, student_mat$Dalc, pch=16, col="tomato",
main= "Relação entre as faltas escolares \n e o consumo de álcool durante a semana",
ylab = "Consumo de álcool", xlab = "Faltas")
abline(lsfit(student_mat$absences, student_mat$Dalc), col="red")# matriz de correlação
cor(student_mat$absences, student_mat$Dalc)## [1] 0.111908
# Carregar a base
library(readr)
student_mat <- read_csv("C:/Users/Clara/OneDrive/Documentos/R/student-mat.csv")## Rows: 395 Columns: 33
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (17): school, sex, address, famsize, Pstatus, Mjob, Fjob, reason, guardi...
## dbl (16): age, Medu, Fedu, traveltime, studytime, failures, famrel, freetime...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Tabela
tabela_higher <- table(student_mat$higher)
tabela_higher##
## no yes
## 20 375
tabela_activities <- table(student_mat$activities)
tabela_activities##
## no yes
## 194 201
#Tabela de proporção
prop.table(tabela_activities)*100##
## no yes
## 49.11392 50.88608
prop.table(tabela_higher)*100##
## no yes
## 5.063291 94.936709
# Gráfico de barras
barplot(tabela_activities, col =c("Pink1","tomato"),main = "Gráfico 1 - Análise de alunos que fazem atividades extra curriculares",
legend.text = row.names(tabela_activities))barplot(tabela_higher, col =c("pink1","tomato"),main = "Gráfico 2 - Análise de alunos que pensam em fazer faculdade",
legend.text = row.names(tabela_higher))# Matriz de Correlação
dados <-data.frame(x=c(2,3,4,5,5,6,7,8),
y=c(4,7,9,10,11,11,13,15))
cor(dados$x,dados$y)## [1] 0.980871
names(student_mat)## [1] "school" "sex" "age" "address" "famsize"
## [6] "Pstatus" "Medu" "Fedu" "Mjob" "Fjob"
## [11] "reason" "guardian" "traveltime" "studytime" "failures"
## [16] "schoolsup" "famsup" "paid" "activities" "nursery"
## [21] "higher" "internet" "romantic" "famrel" "freetime"
## [26] "goout" "Dalc" "Walc" "health" "absences"
## [31] "G1" "G2" "G3"
# Consume bebida no fim de semana, idade e horas de estudo
selecao<- c("Walc","studytime")
cor_Student_mat <- cor(student_mat[,selecao])
cor_Student_mat## Walc studytime
## Walc 1.0000000 -0.2537847
## studytime -0.2537847 1.0000000
library(corrplot)## corrplot 0.92 loaded
par(cex=0.9)
corrplot(cor_Student_mat)library(readr)
student_mat <- read_csv("C:/Users/Clara/OneDrive/Documentos/R/student-mat.csv")## Rows: 395 Columns: 33
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (17): school, sex, address, famsize, Pstatus, Mjob, Fjob, reason, guardi...
## dbl (16): age, Medu, Fedu, traveltime, studytime, failures, famrel, freetime...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(student_mat)
modelo1 <- aov( Dalc ~ absences, data=student_mat)
residuos1 <- residuals(modelo1)
residuos1## 1 2 3 4 5 6
## -0.48463889 -0.45972825 0.46553983 -0.43481761 -0.45972825 -0.53446017
## 7 8 9 10 11 12
## -0.40990697 -0.48463889 -0.40990697 -0.40990697 -0.40990697 -0.45972825
## 13 14 15 16 17 18
## -0.43481761 -0.43481761 -0.40990697 -0.45972825 -0.48463889 -0.45972825
## 19 20 21 22 23 24
## 0.39080791 -0.45972825 -0.40990697 -0.40990697 -0.43481761 0.59009303
## 25 26 27 28 29 30
## -0.43481761 -0.58428145 -0.43481761 0.54027175 -0.45972825 3.39080791
## 31 32 33 34 35 36
## 1.59009303 -0.40990697 -0.40990697 -0.40990697 -0.40990697 -0.40990697
## 37 38 39 40 41 42
## -0.43481761 -0.49709421 -0.43481761 -0.50954953 -0.72128996 0.49045047
## 43 44 45 46 47 48
## -0.43481761 -0.40990697 0.41571855 -0.50954953 -0.55937081 -0.45972825
## 49 50 51 52 53 54
## 0.56518239 -0.43481761 0.56518239 -0.43481761 1.51536111 0.59009303
## 55 56 57 58 59 60
## 2.51536111 -0.50954953 -0.40990697 -0.45972825 -0.43481761 -0.43481761
## 61 62 63 64 65 66
## 0.51536111 3.51536111 -0.45972825 0.56518239 0.59009303 -0.43481761
## 67 68 69 70 71 72
## 3.54027175 -0.45972825 -0.43481761 0.44062919 -0.40990697 -0.40990697
## 73 74 75 76 77 78
## 0.56518239 0.56518239 -0.08249423 0.51536111 -0.50954953 -0.40990697
## 79 80 81 82 83 84
## -0.43481761 -0.55937081 -0.43481761 -0.45972825 -0.53446017 -0.45972825
## 85 86 87 88 89 90
## 0.56518239 0.51536111 -0.45972825 -0.45972825 -0.55937081 1.36589727
## 91 92 93 94 95 96
## -0.40990697 -0.45972825 0.54027175 -0.40990697 -0.48463889 -0.43481761
## 97 98 99 100 101 102
## -0.43481761 -0.43481761 -0.48463889 -0.40990697 3.41571855 -0.40990697
## 103 104 105 106 107 108
## -0.45972825 -0.73374528 -0.40990697 -0.53446017 -0.50954953 -0.43481761
## 109 110 111 112 113 114
## 1.51536111 -0.45972825 -0.48463889 -0.40990697 -0.48463889 -0.53446017
## 115 116 117 118 119 120
## -0.50954953 -0.43481761 -0.43481761 -0.40990697 -0.65901337 -0.48463889
## 121 122 123 124 125 126
## -0.43481761 -0.48463889 -0.43481761 -0.63410273 -0.40990697 1.59009303
## 127 128 129 130 131 132
## -0.40990697 -0.43481761 -0.40990697 0.49045047 0.59009303 -0.40990697
## 133 134 135 136 137 138
## -0.55937081 -0.60919209 -0.40990697 -0.40990697 0.59009303 -0.40990697
## 139 140 141 142 143 144
## -0.40990697 -0.40990697 -0.40990697 0.49045047 -0.43481761 1.56518239
## 145 146 147 148 149 150
## -0.40990697 -0.40990697 -0.40990697 -0.43481761 0.59009303 0.59009303
## 151 152 153 154 155 156
## 0.59009303 1.51536111 0.49045047 -0.40990697 -0.40990697 -0.43481761
## 157 158 159 160 161 162
## 1.49045047 -0.48463889 -0.43481761 2.54027175 0.59009303 -0.48463889
## 163 164 165 166 167 168
## 0.59009303 -0.43481761 -0.40990697 -0.60919209 0.54027175 -0.40990697
## 169 170 171 172 173 174
## -0.40990697 -0.40990697 0.59009303 -0.43481761 -0.40990697 -0.40990697
## 175 176 177 178 179 180
## -0.45972825 2.54027175 -0.43481761 -0.45972825 1.46553983 -0.45972825
## 181 182 183 184 185 186
## 0.46553983 -0.43481761 0.59009303 -0.10740487 -0.58428145 0.44062919
## 187 188 189 190 191 192
## -0.43481761 -0.40990697 -0.48463889 -0.45972825 -0.53446017 -0.40990697
## 193 194 195 196 197 198
## 2.44062919 1.49045047 -0.40990697 -0.40990697 -0.45972825 1.49045047
## 199 200 201 202 203 204
## 0.29116536 -0.40990697 -0.43481761 -0.48463889 -0.45972825 -0.63410273
## 205 206 207 208 209 210
## -0.48463889 1.24134408 0.52781643 -0.53446017 -0.48463889 -0.48463889
## 211 212 213 214 215 216
## -0.53446017 2.42817387 -0.40990697 0.40326323 -0.55937081 -0.43481761
## 217 218 219 220 221 222
## 0.31607599 0.42817387 -0.44727293 -0.45972825 -0.43481761 -0.40990697
## 223 224 225 226 227 228
## -0.43481761 3.59009303 -0.40990697 -0.60919209 -0.53446017 -0.43481761
## 229 230 231 232 233 234
## 2.41571855 -0.53446017 -0.58428145 -0.45972825 -0.58428145 0.56518239
## 235 236 237 238 239 240
## -0.63410273 -0.53446017 3.54027175 -0.65901337 -0.43481761 1.59009303
## 241 242 243 244 245 246
## -0.58428145 0.56518239 -0.40990697 -0.40990697 -0.40990697 -0.48463889
## 247 248 249 250 251 252
## -0.45972825 3.39080791 -0.50954953 0.59009303 0.59009303 -0.48463889
## 253 254 255 256 257 258
## 0.54027175 -0.40990697 0.59009303 -0.43481761 -0.48463889 -0.55937081
## 259 260 261 262 263 264
## -0.50954953 -0.40990697 -0.67146869 -0.43481761 -0.42236229 -0.45972825
## 265 266 267 268 269 270
## -0.40990697 1.42817387 1.56518239 0.49045047 -0.53446017 -0.40990697
## 271 272 273 274 275 276
## 1.40326323 -0.45972825 -0.43481761 0.56518239 -0.43481761 0.51536111
## 277 278 279 280 281 282
## -1.34405595 -0.68392401 -0.59673677 -0.50954953 0.21643344 1.35344195
## 283 284 285 286 287 288
## -0.42236229 -0.45972825 -0.45972825 -0.43481761 -0.47218357 -0.48463889
## 289 290 291 292 293 294
## -0.48463889 -0.52200485 -0.54691549 -0.40990697 -0.55937081 -0.48463889
## 295 296 297 298 299 300
## -0.50954953 -0.45972825 0.59009303 -0.53446017 -0.40990697 0.52781643
## 301 302 303 304 305 306
## -0.58428145 0.59009303 -0.40990697 -0.40990697 -0.65901337 -0.50954953
## 307 308 309 310 311 312
## -0.40990697 -0.88320912 -0.40990697 -0.63410273 0.59009303 -0.65901337
## 313 314 315 316 317 318
## 0.55272707 -0.68392401 -0.58428145 -0.90811976 -0.40990697 -0.52200485
## 319 320 321 322 323 324
## 0.59009303 1.56518239 -0.69637932 -0.55937081 0.55272707 0.57763771
## 325 326 327 328 329 330
## 0.59009303 0.55272707 1.55272707 3.49045047 -0.49709421 -0.45972825
## 331 332 333 334 335 336
## 0.56518239 -0.49709421 -0.40990697 -0.40990697 -0.40990697 -0.60919209
## 337 338 339 340 341 342
## -0.55937081 0.59009303 -0.49709421 0.54027175 -0.45972825 0.59009303
## 343 344 345 346 347 348
## -0.54691549 -0.40990697 -0.45972825 0.50290579 -0.52200485 0.59009303
## 349 350 351 352 353 354
## -0.40990697 3.46553983 1.49045047 0.56518239 0.50290579 1.54027175
## 355 356 357 358 359 360
## -0.45972825 -0.40990697 -0.45972825 -0.43481761 -0.45972825 -0.40990697
## 361 362 363 364 365 366
## -0.40990697 0.56518239 -0.40990697 -0.40990697 -0.40990697 0.54027175
## 367 368 369 370 371 372
## 0.59009303 -0.40990697 -0.40990697 2.46553983 -0.45972825 0.55272707
## 373 374 375 376 377 378
## -0.50954953 -0.58428145 -0.40990697 -0.43481761 -0.45972825 1.54027175
## 379 380 381 382 383 384
## -0.40990697 0.37835259 -0.45972825 -0.47218357 -0.43481761 -0.40990697
## 385 386 387 388 389 390
## 2.41571855 -0.43481761 0.50290579 -0.40990697 -0.40990697 -0.40990697
## 391 392 393 394 395
## 2.45308451 1.55272707 1.55272707 1.59009303 1.52781643
#H0: Os dados seguem uma distribuição normal
#H1: Os dados NÃO seguem uma distribuição normal
#alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
shapiro.test(residuos1)##
## Shapiro-Wilk normality test
##
## data: residuos1
## W = 0.67194, p-value < 2.2e-16
# p-value = 0.00000000000000022
#p-value não segue uma distribuição normal
#Teste de Spearman
#H0: Não há associação entre as duas variáveis.
#H1: Há associação entre as duas variáveis.
# alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
cor.test(student_mat$Dalc,student_mat$absences, method = "spearman",conf.level = 0.95)## Warning in cor.test.default(student_mat$Dalc, student_mat$absences, method =
## "spearman", : Cannot compute exact p-value with ties
##
## Spearman's rank correlation rho
##
## data: student_mat$Dalc and student_mat$absences
## S = 8939861, p-value = 0.009895
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.1296509
# p-value = 0.009895modelo2 <- aov( Walc ~ address, data=student_mat)
residuos2 <- residuals(modelo2)
residuos2## 1 2 3 4 5 6 7
## -1.2214984 -1.2214984 0.7785016 -1.2214984 -0.2214984 -0.2214984 -1.2214984
## 8 9 10 11 12 13 14
## -1.2214984 -1.2214984 -1.2214984 -0.2214984 -1.2214984 0.7785016 -0.2214984
## 15 16 17 18 19 20 21
## -1.2214984 -0.2214984 -0.2214984 -1.2214984 1.7785016 0.7785016 -1.2214984
## 22 23 24 25 26 27 28
## -1.2214984 0.7785016 1.7785016 -1.5340909 0.7785016 -0.2214984 1.7785016
## 29 30 31 32 33 34 35
## -1.2214984 2.7785016 1.7785016 -1.2214984 -1.5340909 -1.2214984 -1.2214984
## 36 37 38 39 40 41 42
## -1.2214984 -1.2214984 -1.5340909 -1.5340909 -1.5340909 -0.2214984 1.7785016
## 43 44 45 46 47 48 49
## -1.2214984 -1.2214984 -0.2214984 -1.2214984 1.7785016 -1.2214984 -0.2214984
## 50 51 52 53 54 55 56
## -1.2214984 0.7785016 -1.2214984 1.7785016 0.7785016 1.7785016 -1.2214984
## 57 58 59 60 61 62 63
## -1.2214984 -1.2214984 -1.2214984 -1.2214984 0.4659091 2.7785016 -1.2214984
## 64 65 66 67 68 69 70
## 1.7785016 1.7785016 -0.2214984 2.7785016 -0.2214984 0.4659091 0.4659091
## 71 72 73 74 75 76 77
## -1.2214984 -1.2214984 1.4659091 -0.2214984 1.7785016 0.7785016 -1.2214984
## 78 79 80 81 82 83 84
## 0.7785016 -1.2214984 -0.2214984 0.7785016 -0.2214984 -1.2214984 0.7785016
## 85 86 87 88 89 90 91
## 0.7785016 0.7785016 -0.2214984 0.7785016 -1.2214984 2.7785016 0.7785016
## 92 93 94 95 96 97 98
## 0.7785016 0.7785016 -1.2214984 -1.2214984 -1.5340909 -1.5340909 -1.2214984
## 99 100 101 102 103 104 105
## -0.2214984 -1.2214984 2.7785016 -1.2214984 -1.2214984 -1.2214984 -1.2214984
## 106 107 108 109 110 111 112
## -1.2214984 -1.2214984 -1.2214984 2.4659091 -1.2214984 -1.2214984 -1.5340909
## 113 114 115 116 117 118 119
## -1.2214984 -1.2214984 -1.5340909 -0.2214984 -1.2214984 -1.2214984 1.4659091
## 120 121 122 123 124 125 126
## -0.2214984 -0.2214984 -0.2214984 -0.2214984 1.7785016 -1.2214984 -0.2214984
## 127 128 129 130 131 132 133
## -1.2214984 -1.2214984 -0.5340909 2.4659091 -0.5340909 -0.2214984 0.7785016
## 134 135 136 137 138 139 140
## 1.7785016 -1.5340909 -1.2214984 1.4659091 -1.2214984 0.7785016 -1.2214984
## 141 142 143 144 145 146 147
## -1.2214984 -0.2214984 -1.2214984 0.7785016 -0.2214984 -0.2214984 -1.2214984
## 148 149 150 151 152 153 154
## -1.2214984 -1.2214984 2.7785016 2.7785016 2.7785016 0.4659091 -1.2214984
## 155 156 157 158 159 160 161
## -1.2214984 -1.5340909 0.4659091 2.4659091 -0.5340909 1.7785016 -0.5340909
## 162 163 164 165 166 167 168
## 1.4659091 1.7785016 1.7785016 2.4659091 -1.2214984 1.7785016 -1.2214984
## 169 170 171 172 173 174 175
## -1.2214984 -1.2214984 1.7785016 -1.2214984 0.7785016 -1.2214984 -1.2214984
## 176 177 178 179 180 181 182
## 1.7785016 1.7785016 1.7785016 1.4659091 -1.2214984 0.7785016 -0.2214984
## 183 184 185 186 187 188 189
## 0.7785016 0.7785016 -0.2214984 0.7785016 -0.2214984 -0.2214984 0.7785016
## 190 191 192 193 194 195 196
## 2.4659091 -1.2214984 -1.2214984 2.7785016 1.4659091 -1.2214984 -1.2214984
## 197 198 199 200 201 202 203
## -0.2214984 2.4659091 0.7785016 -0.2214984 2.7785016 0.7785016 0.7785016
## 204 205 206 207 208 209 210
## -0.5340909 -1.5340909 1.7785016 -0.2214984 -1.2214984 1.7785016 -1.5340909
## 211 212 213 214 215 216 217
## -0.2214984 2.7785016 -1.2214984 1.7785016 -0.5340909 0.7785016 1.7785016
## 218 219 220 221 222 223 224
## 1.7785016 1.7785016 -1.2214984 -0.5340909 -1.2214984 -1.2214984 2.7785016
## 225 226 227 228 229 230 231
## -1.2214984 -1.5340909 0.7785016 0.7785016 2.7785016 -0.2214984 -0.2214984
## 232 233 234 235 236 237 238
## -1.5340909 0.7785016 1.7785016 -1.2214984 0.7785016 2.7785016 -1.2214984
## 239 240 241 242 243 244 245
## -1.5340909 2.7785016 1.7785016 0.4659091 -1.2214984 -0.2214984 -1.2214984
## 246 247 248 249 250 251 252
## -1.2214984 -1.2214984 2.7785016 0.4659091 1.7785016 1.7785016 0.7785016
## 253 254 255 256 257 258 259
## 2.7785016 0.4659091 1.4659091 -0.2214984 -1.2214984 -1.2214984 -0.2214984
## 260 261 262 263 264 265 266
## -1.2214984 0.7785016 -1.2214984 -1.5340909 -1.2214984 -1.2214984 1.4659091
## 267 268 269 270 271 272 273
## 1.7785016 -0.5340909 0.7785016 -0.5340909 0.7785016 0.7785016 -1.2214984
## 274 275 276 277 278 279 280
## -0.5340909 -1.2214984 0.7785016 -1.5340909 1.7785016 -1.2214984 -0.2214984
## 281 282 283 284 285 286 287
## 1.7785016 1.7785016 -1.5340909 -1.2214984 -0.2214984 -0.2214984 -0.2214984
## 288 289 290 291 292 293 294
## -1.2214984 0.7785016 -1.2214984 1.7785016 -0.2214984 -1.2214984 -1.5340909
## 295 296 297 298 299 300 301
## -1.5340909 0.7785016 0.7785016 -0.2214984 -1.2214984 -0.2214984 -1.2214984
## 302 303 304 305 306 307 308
## -0.2214984 -1.2214984 -0.2214984 -1.2214984 -1.2214984 -1.2214984 -1.2214984
## 309 310 311 312 313 314 315
## -0.5340909 0.7785016 -0.2214984 -1.2214984 -0.2214984 -0.2214984 -1.2214984
## 316 317 318 319 320 321 322
## -1.5340909 -0.2214984 -1.2214984 2.4659091 0.7785016 -0.2214984 -1.2214984
## 323 324 325 326 327 328 329
## -0.5340909 0.7785016 0.7785016 -0.2214984 2.7785016 2.4659091 0.7785016
## 330 331 332 333 334 335 336
## -0.2214984 1.7785016 -1.5340909 -1.2214984 -1.2214984 -1.5340909 0.7785016
## 337 338 339 340 341 342 343
## -0.5340909 0.7785016 -1.2214984 0.4659091 0.7785016 -0.2214984 0.7785016
## 344 345 346 347 348 349 350
## -0.2214984 -0.2214984 0.7785016 -0.5340909 0.7785016 0.7785016 2.4659091
## 351 352 353 354 355 356 357
## 0.4659091 0.7785016 0.7785016 0.4659091 0.4659091 -1.2214984 -0.5340909
## 358 359 360 361 362 363 364
## -0.2214984 -0.2214984 -1.2214984 1.4659091 0.4659091 0.7785016 -1.2214984
## 365 366 367 368 369 370 371
## -0.5340909 1.4659091 -0.2214984 -0.5340909 -0.2214984 -0.5340909 -1.2214984
## 372 373 374 375 376 377 378
## 0.4659091 -1.2214984 0.4659091 -1.5340909 -0.5340909 -1.2214984 1.4659091
## 379 380 381 382 383 384 385
## -0.2214984 0.4659091 1.7785016 0.4659091 -1.2214984 0.4659091 0.4659091
## 386 387 388 389 390 391 392
## 0.4659091 -0.5340909 -0.5340909 -1.2214984 -1.2214984 2.7785016 1.7785016
## 393 394 395
## 0.4659091 1.4659091 0.7785016
#H0: Os dados seguem uma distribuição normal
#H1: Os dados NÃO seguem uma distribuição normal
#alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
shapiro.test(residuos2)##
## Shapiro-Wilk normality test
##
## data: residuos2
## W = 0.88162, p-value < 2.2e-16
#p-value < 0.00000000000000022
#p-value não segue uma distribuição normal
# Teste de Wilcoxon
#H0: os dois grupos são amostrados de populações de distribuições opções.
#H1: os dois grupos são amostrados de populações com distribuições diferentes.
#alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
wilcox.test(Walc ~ address, data=student_mat)##
## Wilcoxon rank sum test with continuity correction
##
## data: Walc by address
## W = 15402, p-value = 0.03689
## alternative hypothesis: true location shift is not equal to 0
#p-value = 0.03689#H0: Não existe associação entre as variáveis
#H1: Existe associação entre as variáveis
#alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
### Tabela para o teste
tabela <- as.table(rbind(c(20,375),c(194,201)))
### Rotulos para tabela
dimnames(tabela) <- list(higher = c("Não","Sim"),
activities = c("Não","Sim"))
TQQ <- chisq.test(tabela)
TQQ$expected## activities
## higher Não Sim
## Não 107 288
## Sim 107 288
TQQ$observed## activities
## higher Não Sim
## Não 20 375
## Sim 194 201
tabela## activities
## higher Não Sim
## Não 20 375
## Sim 194 201
TQQ$p.value## [1] 1.276791e-43
# Se pvalor < alpha Rej H0
# Se pvalor > alpha Não Rej H0
#P_VALUE = 0.0000000000000000000000000000000000000000001276791modelo3 <- aov( Walc ~ studytime, data=student_mat)
residuos3 <- residuals(modelo3)
residuos3## 1 2 3 4 5 6
## -1.30494280 -1.30494280 0.69505720 -0.91548525 -0.30494280 -0.30494280
## 7 8 9 10 11 12
## -1.30494280 -1.30494280 -1.30494280 -1.30494280 -0.30494280 -0.91548525
## 13 14 15 16 17 18
## 0.30559965 -0.30494280 -0.91548525 -0.69440035 0.08451475 -1.30494280
## 19 20 21 22 23 24
## 1.30559965 0.30559965 -1.30494280 -1.69440035 0.69505720 1.69505720
## 25 26 27 28 29 30
## -0.91548525 0.30559965 -0.69440035 1.30559965 -1.30494280 2.69505720
## 31 32 33 34 35 36
## 1.69505720 -1.30494280 -1.30494280 -1.30494280 -1.69440035 -1.69440035
## 37 38 39 40 41 42
## -0.91548525 -0.91548525 -0.91548525 -1.69440035 -0.30494280 1.30559965
## 43 44 45 46 47 48
## -1.30494280 -1.69440035 -0.30494280 -1.30494280 1.69505720 -0.52602770
## 49 50 51 52 53 54
## -0.30494280 -1.30494280 0.69505720 -1.30494280 1.30559965 0.30559965
## 55 56 57 58 59 60
## 1.30559965 -1.30494280 -1.30494280 -1.30494280 -1.30494280 -1.30494280
## 61 62 63 64 65 66
## 0.69505720 2.30559965 -1.30494280 2.08451475 1.69505720 -0.30494280
## 67 68 69 70 71 72
## 3.47397230 0.47397230 0.69505720 1.47397230 -0.52602770 -0.52602770
## 73 74 75 76 77 78
## 1.69505720 -0.69440035 1.69505720 0.69505720 -0.52602770 1.47397230
## 79 80 81 82 83 84
## -1.69440035 -0.30494280 0.30559965 0.08451475 -1.30494280 0.69505720
## 85 86 87 88 89 90
## 0.69505720 0.69505720 -0.30494280 1.08451475 -1.30494280 2.69505720
## 91 92 93 94 95 96
## 1.08451475 0.30559965 0.69505720 -1.30494280 -0.52602770 -0.52602770
## 97 98 99 100 101 102
## -1.69440035 -1.30494280 -0.69440035 -0.91548525 2.30559965 -0.91548525
## 103 104 105 106 107 108
## -1.69440035 -1.30494280 -1.30494280 -0.52602770 -0.52602770 -0.91548525
## 109 110 111 112 113 114
## 3.47397230 -0.91548525 -1.69440035 -0.91548525 -1.30494280 -1.69440035
## 115 116 117 118 119 120
## -1.30494280 -0.30494280 -1.30494280 -1.69440035 1.69505720 -0.69440035
## 121 122 123 124 125 126
## -0.30494280 0.47397230 -0.30494280 1.30559965 -1.30494280 -0.69440035
## 127 128 129 130 131 132
## -1.30494280 -1.30494280 -0.69440035 2.30559965 0.08451475 -0.69440035
## 133 134 135 136 137 138
## 0.30559965 1.30559965 -1.30494280 -0.91548525 1.69505720 -1.69440035
## 139 140 141 142 143 144
## 0.69505720 -1.69440035 -0.52602770 -0.69440035 -0.91548525 0.30559965
## 145 146 147 148 149 150
## -0.69440035 -0.30494280 -1.30494280 -1.30494280 -1.69440035 2.30559965
## 151 152 153 154 155 156
## 2.30559965 2.30559965 1.08451475 -1.69440035 -1.69440035 -1.30494280
## 157 158 159 160 161 162
## 0.30559965 2.30559965 -0.69440035 1.69505720 -0.69440035 1.69505720
## 163 164 165 166 167 168
## 1.30559965 1.30559965 2.69505720 -1.69440035 1.69505720 -1.30494280
## 169 170 171 172 173 174
## -1.30494280 -1.30494280 1.30559965 -1.30494280 0.69505720 -1.30494280
## 175 176 177 178 179 180
## -1.30494280 1.69505720 1.69505720 1.69505720 1.30559965 -1.30494280
## 181 182 183 184 185 186
## 0.69505720 -0.30494280 0.69505720 0.69505720 -0.30494280 0.69505720
## 187 188 189 190 191 192
## -0.69440035 -0.30494280 0.69505720 2.69505720 -1.30494280 -1.30494280
## 193 194 195 196 197 198
## 2.69505720 1.30559965 -1.69440035 -1.30494280 -0.69440035 2.30559965
## 199 200 201 202 203 204
## 0.30559965 -0.30494280 2.69505720 0.69505720 0.69505720 -0.69440035
## 205 206 207 208 209 210
## -0.52602770 2.08451475 -0.30494280 -1.30494280 1.30559965 -0.91548525
## 211 212 213 214 215 216
## 0.47397230 2.69505720 -1.30494280 1.69505720 -0.69440035 0.69505720
## 217 218 219 220 221 222
## 1.69505720 1.69505720 1.30559965 -0.91548525 -0.30494280 -0.91548525
## 223 224 225 226 227 228
## -1.30494280 2.69505720 -0.91548525 -1.30494280 0.69505720 0.69505720
## 229 230 231 232 233 234
## 2.69505720 0.08451475 -0.30494280 -1.30494280 0.69505720 1.69505720
## 235 236 237 238 239 240
## -1.30494280 1.08451475 2.69505720 -1.69440035 -1.30494280 2.69505720
## 241 242 243 244 245 246
## 1.69505720 0.69505720 -1.69440035 -0.69440035 -0.91548525 -1.69440035
## 247 248 249 250 251 252
## -1.69440035 2.30559965 0.69505720 1.30559965 1.30559965 0.69505720
## 253 254 255 256 257 258
## 2.30559965 0.30559965 1.30559965 -0.69440035 -0.52602770 -1.30494280
## 259 260 261 262 263 264
## -0.30494280 -0.52602770 0.69505720 -1.30494280 -0.91548525 -0.91548525
## 265 266 267 268 269 270
## -0.91548525 1.69505720 1.69505720 -0.30494280 0.69505720 -0.30494280
## 271 272 273 274 275 276
## 0.69505720 1.47397230 -1.30494280 -0.30494280 -1.30494280 0.69505720
## 277 278 279 280 281 282
## -1.30494280 1.30559965 -1.30494280 -0.69440035 1.30559965 1.30559965
## 283 284 285 286 287 288
## -0.52602770 -1.30494280 -0.30494280 -0.30494280 0.08451475 -0.91548525
## 289 290 291 292 293 294
## 1.08451475 -1.30494280 1.69505720 0.08451475 -1.30494280 -0.52602770
## 295 296 297 298 299 300
## -0.91548525 0.30559965 0.69505720 -0.30494280 -0.52602770 -0.69440035
## 301 302 303 304 305 306
## -1.30494280 -0.69440035 -0.91548525 0.47397230 -1.30494280 -1.30494280
## 307 308 309 310 311 312
## -1.69440035 -1.69440035 -0.30494280 0.69505720 -0.30494280 -1.30494280
## 313 314 315 316 317 318
## -0.30494280 -0.30494280 -0.91548525 -0.91548525 -0.30494280 -0.91548525
## 319 320 321 322 323 324
## 3.08451475 0.69505720 -0.30494280 -1.30494280 0.08451475 1.08451475
## 325 326 327 328 329 330
## 1.08451475 0.08451475 2.30559965 2.30559965 1.08451475 0.08451475
## 331 332 333 334 335 336
## 2.47397230 -0.91548525 -1.30494280 -1.30494280 -0.52602770 1.08451475
## 337 338 339 340 341 342
## 0.08451475 0.69505720 -0.52602770 0.69505720 1.08451475 -0.30494280
## 343 344 345 346 347 348
## 0.69505720 -0.30494280 0.08451475 1.08451475 0.08451475 1.08451475
## 349 350 351 352 353 354
## 1.08451475 2.30559965 0.69505720 0.69505720 0.30559965 0.30559965
## 355 356 357 358 359 360
## 0.69505720 -1.30494280 -0.30494280 -0.30494280 -0.69440035 -0.91548525
## 361 362 363 364 365 366
## 1.69505720 0.69505720 0.69505720 -1.30494280 -0.30494280 1.69505720
## 367 368 369 370 371 372
## 0.08451475 -0.69440035 -0.69440035 -0.30494280 -1.30494280 0.30559965
## 373 374 375 376 377 378
## -0.91548525 0.30559965 -0.91548525 0.08451475 -0.91548525 1.69505720
## 379 380 381 382 383 384
## -0.30494280 0.69505720 1.69505720 0.30559965 -1.30494280 0.30559965
## 385 386 387 388 389 390
## 0.30559965 1.08451475 -0.69440035 0.08451475 -1.30494280 -1.30494280
## 391 392 393 394 395
## 2.69505720 1.30559965 0.30559965 1.30559965 0.30559965
#H0: Os dados seguem uma distribuição normal
#H1: Os dados NÃO seguem uma distribuição normal
#alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
shapiro.test(residuos3)##
## Shapiro-Wilk normality test
##
## data: residuos3
## W = 0.93063, p-value = 1.398e-12
#p-value não segue uma distribuição normal
#Teste de Spearman
#H0 Não há associação entre as duas variáveis.
#H1: Há associação entre as duas variáveis.
# alpha: 0,05
#Se pvalor < alpha REJ H0
#Se pvalor > NÃO REJ H0
cor.test(student_mat$Walc,student_mat$studytime, method = "spearman",conf.level = 0.95)## Warning in cor.test.default(student_mat$Walc, student_mat$studytime, method =
## "spearman", : Cannot compute exact p-value with ties
##
## Spearman's rank correlation rho
##
## data: student_mat$Walc and student_mat$studytime
## S = 12983494, p-value = 1.007e-07
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.2640212
#p-value = 0.0000001007