-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstatistic_functions.jl
More file actions
53 lines (41 loc) · 873 Bytes
/
statistic_functions.jl
File metadata and controls
53 lines (41 loc) · 873 Bytes
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
51
52
53
#---
using ProgressMeter
import Base: length
function rse_sum(x)
s = 0
@showprogress for k = eachindex(x)
s = s+x[k]
end
return s
end
rse_sum(1:36) == 666
#---
function rse_mean(x)
return rse_sum(x) / length(x)
end
rse_mean(-15:17) == 1
#----
function rse_std(x)
return sqrt(rse_sum((x.-rse_mean(x)).^2)/(length(x)-1))
end
rse_std([1,2,3]) == 1
#----
function rse_tstat(x;σ = rse_std(x))
return rse_mean(x)./ (σ / sqrt(length(x)))
end
rse_tstat(2:3) == 5
#---
struct StatResult
x::Vector
n::Int32
std::Float64
tvalue::Float64
end
Base.length(s::StatResult) = s.n
StatResult(x) = StatResult(x,length(x))
StatResult(x,n) = StatResult(x,n,rse_std(x))
StatResult(x,n,std) = StatResult(x,n,std,rse_tstat(x;σ=std))
StatResult([10,500.]) # <1>
function tstat(x)
return StatResult(length(x),rse_tstat(x))
end