-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmpiricalDistribution.R
50 lines (40 loc) · 1017 Bytes
/
EmpiricalDistribution.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
library(ggplot2)
EmpDistribution = function(x){
k = length(x)
p = 1:k
x = sort(x)
sd = 1:k
sup95 = 1:k
inf95 = 1:k
for(i in 1:k){
p[i] = sum(as.numeric(x <= x[i])/k)
sd[i] = sqrt((p[i] * (1-p[i]))/k)
sup95[i] = min(p[i] + 1.96 * sd[i], 1)
inf95[i] = max(p[i] - 1.96 * sd[i], 0)
}
return(list(Probability = p, Data = x, SDesvian = sd, ICSup95 = sup95, ICInf95 = inf95))
}
x1 = rnorm(250, 150, 500)
x = EmpDistribution(x1)
x = data.frame(x)
ggplot(x, aes(Data, Probability)) +
geom_step() +
geom_step(aes(Data, ICInf95), color = "red") +
geom_step(aes(Data, ICSup95), color = "red")
t = 1:(6*30)
l = 0
n = 1:(6*30)
for(j in c(100, 1000, 2500, 5000, 7500, 10000)){
data = rnorm(j, 0, 1)
for(i in 1:30){
start_timer = Sys.time()
EmpDistribution(data)
end_timer = Sys.time()
l = l + 1
t[l] = end_timer - start_timer
n[l] = j
}
}
df = data.frame(t, n)
ggplot(df, aes(n, t)) +
geom_point()