Calcular probabilidades del numero de libros que leen los alumnos del ITD.
Se define una variable discreta “x”, que es la cantidad de libros que han leído los alumnos entre 0 y 7 los últimos tres años. Se cargan librerias* Se construye una tabla de distribución: Se representan visualmente las probabilidades de las variables discretas. Se calculan probabilidades.
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
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
discretas <- c(0:7) # 0 Que no gane, 1 que gane
n <- 100 # sum(casos)
casos <- c(10, 18, 10, 20, 15, 12, 10, 5)
probabilidades <- casos / n
acumulada <- cumsum(probabilidades) # Acumulada
tabla <- data.frame(x=discretas,
casos = casos,
f.prob.x = probabilidades,
F.acum.x = acumulada,
x.f.prob.x = (discretas * probabilidades))
tabla
## x casos f.prob.x F.acum.x x.f.prob.x
## 1 0 10 0.10 0.10 0.00
## 2 1 18 0.18 0.28 0.18
## 3 2 10 0.10 0.38 0.20
## 4 3 20 0.20 0.58 0.60
## 5 4 15 0.15 0.73 0.60
## 6 5 12 0.12 0.85 0.60
## 7 6 10 0.10 0.95 0.60
## 8 7 5 0.05 1.00 0.35
g <- ggplot(data = tabla, aes(x = x, y=f.prob.x, fill=x)) +
geom_bar(stat="identity")
g
## Visualizar gráfica de frecuencia con
g2 = tabla %>%
ggplot(aes(x = x, y = casos)) + geom_col(fill = "salmon")
ggplotly(g2, tooltip = "text")