statsample 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +8 -0
  2. data/Manifest.txt +20 -2
  3. data/data/crime.txt +47 -0
  4. data/data/test_binomial.csv +201 -0
  5. data/demo/distribution_t.rb +2 -2
  6. data/demo/regression.rb +2 -1
  7. data/lib/distribution.rb +8 -0
  8. data/lib/distribution/chisquare.rb +24 -0
  9. data/lib/distribution/f.rb +25 -0
  10. data/lib/distribution/normal.rb +25 -0
  11. data/lib/distribution/t.rb +22 -0
  12. data/lib/matrix_extension.rb +78 -0
  13. data/lib/statistics2.rb +531 -0
  14. data/lib/statsample.rb +12 -9
  15. data/lib/statsample/anova.rb +1 -5
  16. data/lib/statsample/bivariate.rb +24 -20
  17. data/lib/statsample/combination.rb +14 -4
  18. data/lib/statsample/converters.rb +17 -1
  19. data/lib/statsample/dataset.rb +66 -10
  20. data/lib/statsample/dominanceanalysis/bootstrap.rb +1 -3
  21. data/lib/statsample/graph/gdchart.rb +2 -3
  22. data/lib/statsample/graph/svggraph.rb +8 -4
  23. data/lib/statsample/mle.rb +137 -0
  24. data/lib/statsample/mle/logit.rb +95 -0
  25. data/lib/statsample/mle/normal.rb +83 -0
  26. data/lib/statsample/mle/probit.rb +93 -0
  27. data/lib/statsample/regression.rb +3 -1
  28. data/lib/statsample/regression/binomial.rb +65 -0
  29. data/lib/statsample/regression/binomial/logit.rb +13 -0
  30. data/lib/statsample/regression/binomial/probit.rb +13 -0
  31. data/lib/statsample/regression/multiple.rb +61 -58
  32. data/lib/statsample/regression/multiple/rubyengine.rb +1 -1
  33. data/lib/statsample/srs.rb +5 -5
  34. data/lib/statsample/vector.rb +129 -59
  35. data/test/test_anova.rb +0 -5
  36. data/test/test_dataset.rb +13 -1
  37. data/test/test_distribution.rb +57 -0
  38. data/test/test_gsl.rb +22 -0
  39. data/test/test_logit.rb +22 -0
  40. data/test/test_mle.rb +140 -0
  41. data/test/test_r.rb +9 -0
  42. data/test/test_regression.rb +12 -4
  43. data/test/test_srs.rb +0 -4
  44. data/test/test_stata.rb +11 -0
  45. data/test/test_statistics.rb +0 -15
  46. data/test/test_vector.rb +11 -0
  47. metadata +28 -4
  48. data/lib/statsample/chidistribution.rb +0 -39
  49. data/lib/statsample/regression/logit.rb +0 -35
@@ -1,39 +0,0 @@
1
- module Statsample
2
- # Based on Babatunde, Iyiola & Eni () :
3
- # "A Numerical Procedure for Computing Chi-Square Percentage Points"
4
- #
5
- module ChiDistribution
6
- class << self
7
- def steps(av, bv, itv)
8
- steps = ((bv.to_f - av.to_f) / itv.to_f).to_i
9
- end
10
- def loggamma(k)
11
- c1 = 76.18009173
12
- c2 = -86.50532033
13
- c3 = 24.01409822
14
- c4 = -1.231739516
15
- c5 = 0.00120858
16
- c6 = -0.000005364
17
- c7 = 2.506628275
18
- x1 = k - 1
19
- ws = x1 + 5.5
20
- ws = (x1 + 0.5) * Math::log(ws) - ws
21
- s = 1 + c1 / (x1 + 1) + c2 / (x1 + 2) + c3 / (x1 + 3) + c4 / (x1 + 4) + c5 / (x1 + 5) + c6 / (x1 + 6)
22
- ws + Math::log(c7 * s)
23
- end
24
- def f(x, k)
25
- Math::exp(0.5 * k * Math::log(0.5 * x) - Math::log(x) - loggamma(0.5 * k) - 0.5 * x)
26
- end
27
- def cdf(b,k)
28
- a = 0.001
29
- b=b.to_f
30
- if k==2
31
- 1 - Math::exp( -b.to_f / 2)
32
- else
33
- w = (b - a) / 28.to_f
34
- 2 * w / 45 * (7 * (f(a, k) + f(a + 28 * w, k)) + 12 * (f(a + 2 * w, k) + f(a + 6 * w, k) + f(a + 10 * w, k) + f(a + 14 * w, k) + f(a + 18 * w, k) + f(a + 22 * w, k) + f(a + 26 * w, k)) + 14 * (f(a + 4 * w, k) + f(a + 8 * w, k) + f(a + 12 * w, k) + f(a + 16 * w, k) + f(a + 20 * w, k) + f(a + 24 * w, k)) + 32 * (f(a + w, k) + f(a + 3 * w, k) + f(a + 5 * w, k) + f(a + 7 * w, k) + f(a + 9 * w, k) + f(a + 11 * w, k) + f(a + 13 * w, k) + f(a + 15 * w, k) + f(a + 17 * w, k) + f(a + 19 * w, k) + f(a + 21 * w, k) + f(a + 23 * w, k) + f(a + 25 * w, k) + f(a + 27 * w, k)))
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,35 +0,0 @@
1
- module Statsample
2
- module Regression
3
- class Logit
4
- def initialize(ds,y_var)
5
- @ds=ds
6
- @y_var=y_var
7
- end
8
- def vp(x1,x2)
9
- sum=0
10
- x1.each_index{|i|
11
- sum+=x1[i]*x2[i]
12
- }
13
- sum
14
- end
15
- # F(B'Xi)
16
- def f(b,x)
17
- Math::exp(vp(b,x)) / (1+Math::exp(vp(b,x)))
18
- end
19
- # f(B'Xi)
20
- def fa(b,x)
21
- f(b,x)*(1-f(b,x))
22
- end
23
- def l(b)
24
- prod=1
25
- y=@ds[@y_var]
26
- @ds.each_array{|x|
27
- x.unshift(1) # add constant
28
- l=(f(b,x)**y[@ds.i])*((1.0-f(b,x))**(1.0-y[@ds.i]))
29
- prod=prod*l
30
- }
31
- prod
32
- end
33
- end
34
- end
35
- end