statsample 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +15 -0
- data/Manifest.txt +6 -0
- data/README.txt +30 -12
- data/Rakefile +91 -0
- data/demo/levene.rb +9 -0
- data/demo/multiple_regression.rb +1 -7
- data/demo/polychoric.rb +1 -0
- data/demo/principal_axis.rb +8 -0
- data/lib/distribution/f.rb +22 -22
- data/lib/spss.rb +99 -99
- data/lib/statsample/bivariate/polychoric.rb +32 -22
- data/lib/statsample/bivariate/tetrachoric.rb +212 -207
- data/lib/statsample/bivariate.rb +6 -6
- data/lib/statsample/codification.rb +65 -65
- data/lib/statsample/combination.rb +60 -59
- data/lib/statsample/converter/csv19.rb +12 -12
- data/lib/statsample/converters.rb +1 -1
- data/lib/statsample/dataset.rb +93 -36
- data/lib/statsample/dominanceanalysis/bootstrap.rb +66 -3
- data/lib/statsample/dominanceanalysis.rb +5 -6
- data/lib/statsample/factor/pca.rb +41 -11
- data/lib/statsample/factor/principalaxis.rb +105 -29
- data/lib/statsample/factor/rotation.rb +20 -3
- data/lib/statsample/factor.rb +1 -1
- data/lib/statsample/graph/gdchart.rb +13 -13
- data/lib/statsample/graph/svggraph.rb +166 -167
- data/lib/statsample/matrix.rb +22 -12
- data/lib/statsample/mle/logit.rb +3 -2
- data/lib/statsample/mle/probit.rb +7 -5
- data/lib/statsample/mle.rb +4 -2
- data/lib/statsample/multiset.rb +125 -124
- data/lib/statsample/permutation.rb +2 -1
- data/lib/statsample/regression/binomial/logit.rb +4 -3
- data/lib/statsample/regression/binomial/probit.rb +2 -1
- data/lib/statsample/regression/binomial.rb +62 -81
- data/lib/statsample/regression/multiple/baseengine.rb +1 -1
- data/lib/statsample/regression/multiple/gslengine.rb +1 -1
- data/lib/statsample/regression/multiple/matrixengine.rb +12 -6
- data/lib/statsample/regression/multiple.rb +15 -42
- data/lib/statsample/regression/simple.rb +93 -78
- data/lib/statsample/regression.rb +74 -2
- data/lib/statsample/reliability.rb +117 -120
- data/lib/statsample/srs.rb +156 -153
- data/lib/statsample/test/levene.rb +90 -0
- data/lib/statsample/test/umannwhitney.rb +25 -9
- data/lib/statsample/test.rb +2 -0
- data/lib/statsample/vector.rb +388 -413
- data/lib/statsample.rb +74 -30
- data/po/es/statsample.mo +0 -0
- data/test/test_bivariate.rb +5 -4
- data/test/test_combination.rb +1 -1
- data/test/test_dataset.rb +2 -2
- data/test/test_factor.rb +53 -6
- data/test/test_gsl.rb +1 -1
- data/test/test_mle.rb +1 -1
- data/test/test_regression.rb +18 -33
- data/test/test_statistics.rb +15 -33
- data/test/test_stest.rb +35 -0
- data/test/test_svg_graph.rb +2 -2
- data/test/test_vector.rb +331 -333
- metadata +38 -11
@@ -1,28 +1,28 @@
|
|
1
1
|
module Statsample
|
2
2
|
module Reliability
|
3
|
-
|
3
|
+
class << self
|
4
4
|
# Calculate Chonbach's alpha for a given dataset.
|
5
5
|
# only uses tuples without missing data
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def cronbach_alpha(ods)
|
7
|
+
ds=ods.dup_only_valid
|
8
|
+
n_items=ds.fields.size
|
9
|
+
sum_var_items=ds.vectors.inject(0) {|ac,v|
|
10
|
+
ac+v[1].variance_sample }
|
11
|
+
total=ds.vector_sum
|
12
|
+
(n_items / (n_items-1).to_f) * (1-(sum_var_items/ total.variance_sample))
|
13
|
+
end
|
14
14
|
# Calculate Chonbach's alpha for a given dataset
|
15
15
|
# using standarized values for every vector.
|
16
16
|
# Only uses tuples without missing data
|
17
|
-
|
17
|
+
|
18
18
|
def cronbach_alpha_standarized(ods)
|
19
19
|
ds=ods.dup_only_valid.fields.inject({}){|a,f|
|
20
20
|
a[f]=ods[f].vector_standarized; a
|
21
21
|
}.to_dataset
|
22
22
|
cronbach_alpha(ds)
|
23
23
|
end
|
24
|
-
|
25
|
-
|
24
|
+
end
|
25
|
+
class ItemCharacteristicCurve
|
26
26
|
attr_reader :totals, :counts,:vector_total
|
27
27
|
def initialize (ds, vector_total=nil)
|
28
28
|
vector_total||=ds.vector_sum
|
@@ -39,28 +39,28 @@ module Statsample
|
|
39
39
|
tot=@vector_total[i]
|
40
40
|
@totals[tot]||=0
|
41
41
|
@totals[tot]+=1
|
42
|
-
|
42
|
+
@ds.fields.each do |f|
|
43
43
|
item=row[f].to_s
|
44
44
|
@counts[f][tot]||={}
|
45
45
|
@counts[f][tot][item]||=0
|
46
|
-
@counts[f][tot][item] += 1
|
46
|
+
@counts[f][tot][item] += 1
|
47
47
|
end
|
48
|
-
|
48
|
+
i+=1
|
49
49
|
end
|
50
50
|
end
|
51
51
|
def curve_field(field, item)
|
52
52
|
out={}
|
53
53
|
item=item.to_s
|
54
54
|
@totals.each{|value,n|
|
55
|
-
|
56
|
-
|
55
|
+
count_value= @counts[field][value][item].nil? ? 0 : @counts[field][value][item]
|
56
|
+
out[value]=count_value.to_f/n.to_f
|
57
57
|
}
|
58
58
|
out
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
class ItemAnalysis
|
62
62
|
attr_reader :mean, :sd,:valid_n, :alpha , :alpha_standarized
|
63
|
-
|
63
|
+
def initialize(ds)
|
64
64
|
@ds=ds.dup_only_valid
|
65
65
|
@total=@ds.vector_sum
|
66
66
|
@item_mean=@ds.vector_mean.mean
|
@@ -74,11 +74,11 @@ module Statsample
|
|
74
74
|
@alpha = Statsample::Reliability.cronbach_alpha(ds)
|
75
75
|
@alpha_standarized = Statsample::Reliability.cronbach_alpha_standarized(ds)
|
76
76
|
rescue => e
|
77
|
-
raise DatasetException.new(@ds,e), "Problem on calculate alpha"
|
77
|
+
raise DatasetException.new(@ds,e), "Problem on calculate alpha"
|
78
78
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
end
|
80
|
+
# Returns a hash with structure
|
81
|
+
def item_characteristic_curve
|
82
82
|
i=0
|
83
83
|
out={}
|
84
84
|
total={}
|
@@ -89,7 +89,7 @@ module Statsample
|
|
89
89
|
total[f]||={}
|
90
90
|
out[f][tot]||= 0
|
91
91
|
total[f][tot]||=0
|
92
|
-
out[f][tot]+= row[f]
|
92
|
+
out[f][tot]+= row[f]
|
93
93
|
total[f][tot]+=1
|
94
94
|
end
|
95
95
|
i+=1
|
@@ -100,79 +100,77 @@ module Statsample
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
out
|
103
|
-
|
103
|
+
end
|
104
104
|
def gnuplot_item_characteristic_curve(directory, base="crd",options={})
|
105
105
|
require 'gnuplot'
|
106
|
-
|
106
|
+
|
107
107
|
crd=item_characteristic_curve
|
108
|
-
@ds.fields.each
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
108
|
+
@ds.fields.each do |f|
|
109
|
+
x=[]
|
110
|
+
y=[]
|
111
|
+
Gnuplot.open do |gp|
|
112
|
+
Gnuplot::Plot.new( gp ) do |plot|
|
113
|
+
crd[f].sort.each do |tot,prop|
|
114
|
+
x.push(tot)
|
115
|
+
y.push((prop*100).to_i.to_f/100)
|
116
|
+
end
|
117
|
+
plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
|
118
|
+
ds.with = "linespoints"
|
119
|
+
ds.notitle
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
123
124
|
end
|
124
|
-
}
|
125
|
-
|
126
125
|
end
|
127
126
|
def svggraph_item_characteristic_curve(directory, base="icc",options={})
|
128
127
|
require 'statsample/graph/svggraph'
|
129
128
|
crd=ItemCharacteristicCurve.new(@ds)
|
130
|
-
@ds.fields.each
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
129
|
+
@ds.fields.each do |f|
|
130
|
+
factors=@ds[f].factors.sort
|
131
|
+
options={
|
132
|
+
:height=>500,
|
133
|
+
:width=>800,
|
134
|
+
:key=>true
|
135
|
+
}.update(options)
|
136
|
+
graph = ::SVG::Graph::Plot.new(options)
|
137
|
+
factors.each do |factor|
|
138
|
+
factor=factor.to_s
|
139
|
+
dataset=[]
|
140
|
+
crd.curve_field(f, factor).each do |tot,prop|
|
141
|
+
dataset.push(tot)
|
142
|
+
dataset.push((prop*100).to_i.to_f/100)
|
143
|
+
end
|
144
|
+
graph.add_data({
|
145
|
+
:title=>"#{factor}",
|
146
|
+
:data=>dataset
|
147
|
+
})
|
148
|
+
end
|
149
|
+
File.open(directory+"/"+base+"_#{f}.svg","w") {|fp|
|
150
|
+
fp.puts(graph.burn())
|
151
|
+
}
|
152
|
+
end
|
155
153
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
154
|
+
def item_total_correlation
|
155
|
+
@ds.fields.inject({}) do |a,v|
|
156
|
+
vector=@ds[v].dup
|
157
|
+
ds2=@ds.dup
|
158
|
+
ds2.delete_vector(v)
|
159
|
+
total=ds2.vector_sum
|
160
|
+
a[v]=Statsample::Bivariate.pearson(vector,total)
|
161
|
+
a
|
164
162
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
163
|
+
end
|
164
|
+
def item_statistics
|
165
|
+
@ds.fields.inject({}) do |a,v|
|
166
|
+
a[v]={:mean=>@ds[v].mean,:sds=>@ds[v].sds}
|
167
|
+
a
|
168
|
+
end
|
169
|
+
end
|
172
170
|
# Returns a dataset with cases ordered by score
|
173
171
|
# and variables ordered by difficulty
|
174
|
-
|
175
|
-
|
172
|
+
|
173
|
+
def item_difficulty_analysis
|
176
174
|
dif={}
|
177
175
|
@ds.fields.each{|f| dif[f]=@ds[f].mean }
|
178
176
|
dif_sort=dif.sort{|a,b| -(a[1]<=>b[1])}
|
@@ -190,20 +188,20 @@ module Statsample
|
|
190
188
|
ds_new.update_valid_data
|
191
189
|
ds_new
|
192
190
|
end
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
191
|
+
def stats_if_deleted
|
192
|
+
@ds.fields.inject({}) do |a,v|
|
193
|
+
ds2=@ds.dup
|
194
|
+
ds2.delete_vector(v)
|
195
|
+
total=ds2.vector_sum
|
196
|
+
a[v]={}
|
197
|
+
a[v][:mean]=total.mean
|
198
|
+
a[v][:sds]=total.sds
|
199
|
+
a[v][:variance_sample]=total.variance_sample
|
200
|
+
a[v][:alpha]=Statsample::Reliability.cronbach_alpha(ds2)
|
201
|
+
a
|
204
202
|
end
|
205
|
-
|
206
|
-
|
203
|
+
end
|
204
|
+
def html_summary
|
207
205
|
html = <<EOF
|
208
206
|
<p><strong>Summary for scale:</strong></p>
|
209
207
|
<ul>
|
@@ -229,27 +227,26 @@ Correl.</th><th>Alpha if
|
|
229
227
|
deleted</th></thead>
|
230
228
|
EOF
|
231
229
|
|
232
|
-
itc=item_total_correlation
|
233
|
-
sid=stats_if_deleted
|
234
|
-
is=item_statistics
|
235
|
-
@ds.fields.each {|f|
|
236
|
-
|
237
|
-
<tr>
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
</tr>
|
230
|
+
itc=item_total_correlation
|
231
|
+
sid=stats_if_deleted
|
232
|
+
is=item_statistics
|
233
|
+
@ds.fields.each {|f|
|
234
|
+
html << <<EOF
|
235
|
+
<tr>
|
236
|
+
<td>#{f}</td>
|
237
|
+
<td>#{sprintf("%0.5f",is[f][:mean])}</td>
|
238
|
+
<td>#{sprintf("%0.5f",is[f][:sds])}</td>
|
239
|
+
<td>#{sprintf("%0.5f",sid[f][:mean])}</td>
|
240
|
+
<td>#{sprintf("%0.5f",sid[f][:variance_sample])}</td>
|
241
|
+
<td>#{sprintf("%0.5f",sid[f][:sds])}</td>
|
242
|
+
<td>#{sprintf("%0.5f",itc[f])}</td>
|
243
|
+
<td>#{sprintf("%0.5f",sid[f][:alpha])}</td>
|
244
|
+
</tr>
|
247
245
|
EOF
|
248
|
-
}
|
249
|
-
html << "</table><hr />"
|
250
|
-
html
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
end
|
246
|
+
}
|
247
|
+
html << "</table><hr />"
|
248
|
+
html
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
255
252
|
end
|
data/lib/statsample/srs.rb
CHANGED
@@ -2,161 +2,164 @@ module Statsample
|
|
2
2
|
# Several methods to estimate parameters for simple random sampling
|
3
3
|
module SRS
|
4
4
|
class << self
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
5
|
+
########################
|
6
|
+
#
|
7
|
+
# :SECTION: Proportion estimation
|
8
|
+
#
|
9
|
+
# Function for estimation of proportions
|
10
|
+
########################
|
11
|
+
|
12
|
+
#
|
13
|
+
# Finite population correction (over variance)
|
14
|
+
# Source: Cochran(1972)
|
15
|
+
def fpc_var(sam,pop)
|
16
|
+
(pop - sam).quo(pop - 1)
|
17
|
+
end
|
18
|
+
# Finite population correction (over standard deviation)
|
19
|
+
def fpc(sam,pop)
|
20
|
+
Math::sqrt((pop-sam).quo(pop-1))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Non sample fraction.
|
24
|
+
#
|
25
|
+
# 1 - sample fraction
|
26
|
+
def qf(sam , pop)
|
27
|
+
1-(sam.quo(pop))
|
28
|
+
end
|
29
|
+
# Sample size estimation for proportions, infinite poblation
|
30
|
+
def estimation_n0(d,prop,margin=0.95)
|
31
|
+
t=Distribution::Normal.p_value(1-(1-margin).quo(2))
|
32
|
+
var=prop*(1-prop)
|
33
|
+
t**2*var.quo(d**2)
|
34
|
+
end
|
35
|
+
# Sample size estimation for proportions, finite poblation.
|
36
|
+
def estimation_n(d,prop,n_pobl,margin=0.95)
|
37
|
+
n0=estimation_n0(d,prop,margin)
|
38
|
+
n0.quo( 1 + ((n0 - 1).quo(n_pobl)))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Proportion confidence interval with t values
|
43
|
+
# Uses estimated proportion, sample without replacement.
|
44
|
+
|
45
|
+
def proportion_confidence_interval_t(prop, n_sample, n_population, margin=0.95)
|
46
|
+
t = Distribution::T.p_value(1-((1-margin).quo(2)) , n_sample-1)
|
47
|
+
proportion_confidence_interval(prop,n_sample,n_population, t)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Proportion confidence interval with z values
|
51
|
+
# Uses estimated proportion, sample without replacement.
|
52
|
+
def proportion_confidence_interval_z(p, n_sample, n_population, margin=0.95)
|
53
|
+
z=Distribution::Normal.p_value(1-((1-margin).quo(2)))
|
54
|
+
proportion_confidence_interval(p,n_sample,n_population, z)
|
55
|
+
end
|
56
|
+
# Proportion confidence interval with x value
|
57
|
+
# Uses estimated proportion, sample without replacement
|
58
|
+
|
59
|
+
def proportion_confidence_interval(p, sam,pop , x)
|
60
|
+
f=sam.quo(pop)
|
61
|
+
one_range=x * Math::sqrt((qf(sam, pop) * p * (1-p)).quo(sam-1)) + (1.quo(sam * 2.0))
|
62
|
+
[p-one_range, p+one_range]
|
63
|
+
end
|
64
|
+
# Standard deviation for sample distribution of a proportion
|
65
|
+
# Know proportion, sample with replacement.
|
66
|
+
# Based on http://stattrek.com/Lesson6/SRS.aspx
|
67
|
+
def proportion_sd_kp_wr(p, n_sample)
|
68
|
+
Math::sqrt(p*(1-p).quo(n_sample))
|
69
|
+
end
|
70
|
+
# Standard deviation for sample distribution of a proportion
|
71
|
+
# Know proportion, sample without replacement.
|
72
|
+
#
|
73
|
+
# Sources:
|
74
|
+
# * http://stattrek.com/Lesson6/SRS.aspx
|
75
|
+
# * Cochran(1972)
|
76
|
+
def proportion_sd_kp_wor(p, sam, pop)
|
77
|
+
fpc(sam,pop)*Math::sqrt(p*(1-p).quo(sam))
|
78
|
+
end
|
79
|
+
# Standard deviation for sample distribution of a proportion
|
80
|
+
# Estimated proportion, sample with replacement
|
81
|
+
# Based on http://stattrek.com/Lesson6/SRS.aspx.
|
82
|
+
def proportion_sd_ep_wr(p, n_sample)
|
83
|
+
Math::sqrt(p*(1-p).quo(n_sample-1))
|
84
|
+
end
|
85
|
+
# Standard deviation for sample distribution of a proportion.
|
86
|
+
# Estimated proportion, sample without replacement.
|
87
|
+
# Reference:
|
88
|
+
# * Cochran, 1972, Técnicas de muestreo
|
89
|
+
def proportion_sd_ep_wor(p, sam,pop)
|
90
|
+
fsc=(pop-sam).quo((sam-1)*pop)
|
91
|
+
Math::sqrt(fsc*p*(1-p))
|
92
|
+
end
|
93
|
+
|
94
|
+
# Total estimation sd based on sample.
|
95
|
+
# Known proportion, sample without replacement
|
96
|
+
# Reference:
|
97
|
+
# * Cochran(1972)
|
98
|
+
def proportion_total_sd_kp_wor(prop, sam, pop)
|
99
|
+
pob * proportion_sd_kp_wor(p, sam, pop)
|
100
|
+
end
|
101
|
+
# Total estimation sd based on sample.
|
102
|
+
# Estimated proportion, sample without replacement
|
103
|
+
# Source: Cochran(1972)
|
104
|
+
def proportion_total_sd_ep_wor(prop, sam, pop)
|
105
|
+
fsc=((pop - sam).to_f / ( sam - 1))
|
106
|
+
Math::sqrt(fsc*pop*prop*(1-prop))
|
107
|
+
end
|
108
|
+
|
109
|
+
########################
|
110
|
+
#
|
111
|
+
# :SECTION: Mean stimation
|
112
|
+
#
|
113
|
+
########################
|
110
114
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
115
|
+
|
116
|
+
# Standard error. Known variance, sample with replacement.
|
117
|
+
def standard_error_ksd_wr(s, sam, pop)
|
118
|
+
s.quo(Math::sqrt(sam)) * Math::sqrt((pop-1).quo(pop))
|
119
|
+
end
|
120
|
+
|
121
|
+
# Standard error of the mean. Known variance, sample w/o replacement
|
122
|
+
def standard_error_ksd_wor(s,sam,pop)
|
123
|
+
s.quo(Math::sqrt(sam)) * Math::sqrt(qf(sam,pop))
|
124
|
+
end
|
125
|
+
|
126
|
+
alias_method :standard_error_esd_wr, :standard_error_ksd_wr
|
127
|
+
|
128
|
+
# Standard error of the mean.
|
129
|
+
# Estimated variance, without replacement
|
130
|
+
# Cochran (1972) p.47
|
131
|
+
def standard_error_esd_wor(s,sam,pop)
|
132
|
+
s.quo(Math::sqrt(sam)) * Math::sqrt(qf(sam,pop))
|
133
|
+
end
|
134
|
+
|
135
|
+
alias_method :standard_error, :standard_error_esd_wor
|
136
|
+
alias_method :se, :standard_error_esd_wor
|
133
137
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
# Standard error of total estimation
|
139
|
+
|
140
|
+
def standard_error_total(s,sam,pop)
|
141
|
+
pop*se(s,sam,pop)
|
142
|
+
end
|
139
143
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
144
|
+
# Confidence Interval using T-Student
|
145
|
+
# Use with n < 60
|
146
|
+
def mean_confidence_interval_t(mean,s,n_sample,n_population,margin=0.95)
|
147
|
+
t=Distribution::T.p_value(1-((1-margin) / 2),n_sample-1)
|
148
|
+
mean_confidence_interval(mean,s,n_sample,n_population,t)
|
149
|
+
end
|
150
|
+
# Confidente Interval using Z
|
151
|
+
# Use with n > 60
|
152
|
+
def mean_confidence_interval_z(mean,s,n_sample,n_population,margin=0.95)
|
153
|
+
z=Distribution::Normal.p_value(1-((1-margin) / 2))
|
154
|
+
mean_confidence_interval(mean,s,n_sample,n_population, z)
|
155
|
+
end
|
156
|
+
# Confidente interval using X.
|
157
|
+
#
|
158
|
+
# Better use mean_confidence_interval_z or mean_confidence_interval_t
|
159
|
+
def mean_confidence_interval(mean,s,n_sample,n_population,x)
|
160
|
+
range=x*se(s,n_sample,n_population)
|
161
|
+
[mean-range,mean+range]
|
162
|
+
end
|
159
163
|
end
|
160
164
|
end
|
161
|
-
|
162
|
-
end
|
165
|
+
end
|