Análise de dados com R
Conjunto de dados
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
Análise Exploratória de dados
Medidas-Resumo
Vamos calcular algumas medidas de posição e dispersão com funções do R.
## [1] 5.843333
## [1] 5.8
## [1] 0.6856935
## [1] 0.8280661
Algumas outras medidas resumo
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
Gráficos
Também há funções implementadas para confecção de gráficos.
Histograma
hist(dados$Petal.Length, main = "Histograma dos tamanhos de pétala",
xlab = "Tamanhos de pétala",
ylab = "Frequência")Boxplot
Será que há diferença no tamanho das pétalas entre as espécies de flores?
Gráficos mais bonitos com o pacote ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.3
Melhorando um pouco o gráfico…
ggplot(data = dados) +
aes(x = Sepal.Length, y = Sepal.Width, colour = Species) +
geom_point(size = 2) +
labs(x = "Comprimento da Sépala",
y = "Largura da Sépala",
colour = "Espécie",
title = "Medidas da sépala por espécie") +
theme_bw()Histograma no ggplot
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Outras utilidades
Distribuições de probabilidade
## [1] -1.498473925 0.006180356 0.584895319 -1.333115402 0.202802352
## [6] -0.592021858 1.872343521 0.246501746 0.783646430 -0.903579533
## [1] 0.9750021
## [1] 1.959964
## [1] 1.644854
## [1] 1.987608
Gerando valores da distribuição exponencial
Testes de hipótese
Teste Unilateral com
\[H_0: \mu = 6 \\ H_1: \mu < 6 \]
##
## One Sample t-test
##
## data: dados$Sepal.Length
## t = -2.3172, df = 149, p-value = 0.01093
## alternative hypothesis: true mean is less than 6
## 95 percent confidence interval:
## -Inf 5.95524
## sample estimates:
## mean of x
## 5.843333
## p-valor calculado "na mão"
n = nrow(dados)
(t = (mean(dados$Sepal.Length) - 6)/(sd(dados$Sepal.Length)/sqrt(n)))## [1] -2.317166
## [1] 0.01092831
Também podemos testar:
\[H_0: \mu = 6 \\ H_1: \mu \neq 6 \]
##
## One Sample t-test
##
## data: dados$Sepal.Length
## t = -2.3172, df = 149, p-value = 0.02186
## alternative hypothesis: true mean is not equal to 6
## 95 percent confidence interval:
## 5.709732 5.976934
## sample estimates:
## mean of x
## 5.843333
## [1] 0.02185662
## [1] 0.02185662