crear datos
data <- c(2, 3, 0, 1, 5,
3, 2, 3, 0, 0,
2, 1, 2, 1, 0,
2, 1, 1, 1, 3,
4, 0, 0, 2, 1)
knitr::kable(head(data))
| x |
|---|
| 2 |
| 3 |
| 0 |
| 1 |
| 5 |
| 3 |
Calcular tabla de frecuencias
library(questionr)
table <- questionr::freq(data, cum = TRUE, sort = "dec", total = TRUE)
knitr::kable(table)
| n | % | val% | %cum | val%cum | |
|---|---|---|---|---|---|
| 1 | 7 | 28 | 28 | 28 | 28 |
| 0 | 6 | 24 | 24 | 52 | 52 |
| 2 | 6 | 24 | 24 | 76 | 76 |
| 3 | 4 | 16 | 16 | 92 | 92 |
| 4 | 1 | 4 | 4 | 96 | 96 |
| 5 | 1 | 4 | 4 | 100 | 100 |
| Total | 25 | 100 | 100 | 100 | 100 |
x <- row.names(table)
y <- table$n
names <- x[1:(length(x)-1)]
freqs <- y[1:(length(y)-1)]
df <- data.frame(x = names, y = freqs)
knitr::kable(df)
| x | y |
|---|---|
| 1 | 7 |
| 0 | 6 |
| 2 | 6 |
| 3 | 4 |
| 4 | 1 |
| 5 | 1 |
library(ggplot2)
ggplot(data=df, aes(x=x, y=y)) +
geom_bar(stat="identity", color="blue", fill="yellow") +
xlab("NĂºmero de asistencias") +
ylab("Frecuencia")
# TABLA DE FRECUENCIAS AGRUPADA generar datos
edades <- c(22, 19, 16, 13, 18, 15, 20, 14, 15, 16,
15, 16, 20, 13, 15, 18, 15, 13, 18, 15)
knitr::kable(head(edades))
| x |
|---|
| 22 |
| 19 |
| 16 |
| 13 |
| 18 |
| 15 |
calcular numero de clases
n_sturges = 1 + log(length(edades))/log(2)
n_sturgesc = ceiling(n_sturges)
n_sturgesf = floor(n_sturges)
n_clases = 0
if (n_sturgesc%%2 == 0) {
n_clases = n_sturgesf
} else {
n_clases = n_sturgesc
}
R = max(edades) - min(edades)
w = ceiling(R/n_clases)
calcular tabla de frecuencias
bins <- seq(min(edades), max(edades) + w, by = w)
Edades <- cut(edades, bins)
Freq_table <- transform(table(Edades), Rel_Freq=prop.table(Freq), Cum_Freq=cumsum(Freq))
knitr::kable(Freq_table)
| Edades | Freq | Rel_Freq | Cum_Freq |
|---|---|---|---|
| (13,15] | 7 | 0.4117647 | 7 |
| (15,17] | 3 | 0.1764706 | 10 |
| (17,19] | 4 | 0.2352941 | 14 |
| (19,21] | 2 | 0.1176471 | 16 |
| (21,23] | 1 | 0.0588235 | 17 |
graficar histograma
df <- data.frame(x = Freq_table$Edades, y = Freq_table$Freq)
knitr::kable(df)
| x | y |
|---|---|
| (13,15] | 7 |
| (15,17] | 3 |
| (17,19] | 4 |
| (19,21] | 2 |
| (21,23] | 1 |
library(ggplot2)
ggplot(data=df, aes(x=x, y=y)) +
geom_bar(stat="identity", color="blue", fill="green") +
xlab("Rango de Edades") +
ylab("Frecuencia")