Paquetes y fuentes
prob, ggraph,igraph,tidyverse,summarytools
https://cran.r-project.org/web/packages/prob/vignettes/prob.pdf
https://stackoverflow.com/questions/25692325/list-the-sample-space
https://www.r-graph-gallery.com/334-basic-dendrogram-with-ggraph.html
https://www.r-graph-gallery.com/335-custom-ggraph-dendrogram.html
La suma de las 216 posibles tiradas tiene su propia distribución de probabilidad
cada=6
# create an edge list data frame giving the binomial dos opciones ocho enventos
d1 <- data.frame(from="origen", to=paste("rama", seq(1,cada), sep=""))
d2 <- data.frame(from=rep(d1$to, each=cada), to=paste("srama", seq(1,cada˄2), sep="_"))
d3 <- data.frame(from=rep(d2$to, each=cada), to=paste("ssrama", seq(1,cada˄3), sep="_"))
d4 <- data.frame(from=rep(d3$to, each=cada), to=paste("sssrama", seq(1,cada˄4), sep="_"))
d5 <- data.frame(from=rep(d4$to, each=cada), to=paste("ssssrama", seq(1,cada˄5), sep="_"))
#d6 <- data.frame(from=rep(d5$to, each=cada), to=paste("sssssrama", seq(1,cada˄6), sep="_"))
#d7 <- data.frame(from=rep(d6$to, each=cada), to=paste("ssssssrama", seq(1,cada˄7), sep="_"))
#d8 <- data.frame(from=rep(d7$to, each=cada), to=paste("sssssssrama", seq(1,cada˄8), sep="_"))
edges <- rbind(d1, d2, d3)
#,d4,d5)
#,d4,d5,d6,d7,d8)
edges$res<-ifelse(((as.integer(substrRight(as.character(edges$to),1))/6)%%1) == 0,"1",
ifelse(((as.integer(substrRight(as.character(edges$to),1))/6)%%1) == 1/6,"2",
ifelse(((as.integer(substrRight(as.character(edges$to),1))/6)%%1) == 2/6,"3",
ifelse(((as.integer(substrRight(as.character(edges$to),1))/6)%%1) == 3/6,"4",
ifelse(((as.integer(substrRight(as.character(edges$to),1))/6)%%1) == 4/6,"5","6")))))
mygraph <- graph_from_data_frame(edges)
pic<-ggraph(mygraph, layout = 'dendrogram' , circular = FALSE) +
geom_edge_diagonal(aes(color = as.factor(res))) +
geom_node_point() +
theme_void()
print(pic)
espm <-rolldie(3)
espm$suma <- (espm$X1+espm$X2+espm$X3)
#+espm$X4+espm$X5)
x<-espm
#x %>%
# kable() %>%
# kable_styling(full_width = F,font_size = 20)
f<-freq(espm$suma, style = "rmarkdown")
f<-as.data.frame(f)
f$suma<-row.names(f)
f %>%
kable() %>%
kable_styling(full_width = F,font_size = 20)
Freq | % Valid | % Valid Cum. | % Total | % Total Cum. | suma | |
---|---|---|---|---|---|---|
3 | 1 | 0.462963 | 0.462963 | 0.462963 | 0.462963 | 3 |
4 | 3 | 1.388889 | 1.851852 | 1.388889 | 1.851852 | 4 |
5 | 6 | 2.777778 | 4.629630 | 2.777778 | 4.629630 | 5 |
6 | 10 | 4.629630 | 9.259259 | 4.629630 | 9.259259 | 6 |
7 | 15 | 6.944444 | 16.203704 | 6.944444 | 16.203704 | 7 |
8 | 21 | 9.722222 | 25.925926 | 9.722222 | 25.925926 | 8 |
9 | 25 | 11.574074 | 37.500000 | 11.574074 | 37.500000 | 9 |
10 | 27 | 12.500000 | 50.000000 | 12.500000 | 50.000000 | 10 |
11 | 27 | 12.500000 | 62.500000 | 12.500000 | 62.500000 | 11 |
12 | 25 | 11.574074 | 74.074074 | 11.574074 | 74.074074 | 12 |
13 | 21 | 9.722222 | 83.796296 | 9.722222 | 83.796296 | 13 |
14 | 15 | 6.944444 | 90.740741 | 6.944444 | 90.740741 | 14 |
15 | 10 | 4.629630 | 95.370370 | 4.629630 | 95.370370 | 15 |
16 | 6 | 2.777778 | 98.148148 | 2.777778 | 98.148148 | 16 |
17 | 3 | 1.388889 | 99.537037 | 1.388889 | 99.537037 | 17 |
18 | 1 | 0.462963 | 100.000000 | 0.462963 | 100.000000 | 18 |
<NA> | 0 | NA | NA | 0.000000 | 100.000000 | <NA> |
Total | 216 | 100.000000 | 100.000000 | 100.000000 | 100.000000 | Total |
colors <- c(rep("red",6), rep("blue",5), rep("orange",4),rep("yellow",5),rep("green",6))
g <- ggplot(espm, aes(suma))+
geom_bar(fill="red")
g