Obtain this data from any grouped data type. Is there a library that does it or is it necessary to create the function? S
slds
Obtain this data from any grouped data type. Is there a library that does it or is it necessary to create the function? S
slds
The 4 way to observe a distribution can be calculated with a base function of R: quantile()
. Let's see each case:
# generamos 1000 observaciones de 1 a 100
data <- as.integer(runif(min=0, max=100, n=1000))
quantile(data)
Without parameters quantile
returns the quartiles, which we can verify by invoking it with the parameter prob
passing it a vector with the points of each quartile
quantile(data, prob=c(0,0.25,0.5,0.75,1))
In both cases, we can see that the result is the same:
0% 25% 50% 75% 100%
0 24 50 75 99
Same function, but we vary the parameter prob
# deciles
quantile(data, prob=seq(0, 1, length = 11))
0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
0 8 19 30 40 50 62 71 80 90 99
With seq(0, 1, length = 11)
we set the decile points: [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
We have already seen that everything happens to vary the probability vector, so the percentiles calculate them to generate a vector from 0 to 1 doing seq(0, 1, length = 101)
something like this:
[1] 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 ...
...
[91] 0.90 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
Finally:
quantile(data, prob=seq(0, 1, length = 101))
0% 1% 2% 3% 4% 5% 6% 7% 8% 9% 10% 11% 12% 13% 14% 15%
0.00 0.00 1.00 2.00 3.00 4.00 4.00 5.00 6.00 7.00 8.00 9.00 11.00 12.00 13.00 14.00
16% 17% 18% 19% 20% 21% 22% 23% 24% 25% 26% 27% 28% 29% 30% 31%
15.00 16.00 17.00 18.00 19.00 20.00 21.00 23.00 23.76 24.00 25.00 26.00 27.00 29.00 30.00 30.00
32% 33% 34% 35% 36% 37% 38% 39% 40% 41% 42% 43% 44% 45% 46% 47%
32.00 32.00 33.00 34.00 35.00 36.00 37.62 39.00 40.00 41.00 42.00 43.00 44.56 45.00 47.00 47.53
48% 49% 50% 51% 52% 53% 54% 55% 56% 57% 58% 59% 60% 61% 62% 63%
48.00 49.00 50.00 51.00 53.00 54.00 56.00 57.00 58.00 59.00 59.42 61.00 62.00 62.00 63.00 64.00
64% 65% 66% 67% 68% 69% 70% 71% 72% 73% 74% 75% 76% 77% 78% 79%
64.36 65.00 66.00 67.33 69.00 70.00 71.00 72.00 73.00 74.00 75.00 75.00 77.00 78.00 79.00 79.00
80% 81% 82% 83% 84% 85% 86% 87% 88% 89% 90% 91% 92% 93% 94% 95%
80.00 81.00 82.00 82.17 84.00 85.00 86.00 87.00 88.00 89.00 90.00 91.00 92.00 93.00 94.00 94.00
96% 97% 98% 99% 100%
95.00 96.00 97.00 98.00 99.00