Module: Statsample::SRS

Defined in:
lib/statsample/srs.rb

Overview

Reference:

Class Method Summary collapse

Class Method Details

.estimation_n(d, prop, n_pobl, margin = 0.95) ⇒ Object

Sample size estimation for proportions, finite poblation.


41
42
43
44
# File 'lib/statsample/srs.rb', line 41

def estimation_n(d,prop,n_pobl,margin=0.95)
    n0=estimation_n0(d,prop,margin)
    n0.quo( 1 + ((n0 - 1).quo(n_pobl)))
end

.estimation_n0(d, prop, margin = 0.95) ⇒ Object

Sample size estimation for proportions, infinite poblation


35
36
37
38
39
# File 'lib/statsample/srs.rb', line 35

def estimation_n0(d,prop,margin=0.95)
    t=Distribution::Normal.p_value(1-(1-margin).quo(2))
    var=prop*(1-prop)
    t**2*var.quo(d**2)
end

.fpc(sam, pop) ⇒ Object

Finite population correction (over standard deviation)


24
25
26
# File 'lib/statsample/srs.rb', line 24

def fpc(sam,pop)
    Math::sqrt((pop-sam).quo(pop-1))
end

.fpc_var(sam, pop) ⇒ Object

Finite population correction (over variance) Source: Cochran(1972)


20
21
22
# File 'lib/statsample/srs.rb', line 20

def fpc_var(sam,pop)
    (pop - sam).quo(pop - 1)
end

.mean_confidence_interval(mean, s, n_sample, n_population, x) ⇒ Object

Confidente interval using X.

Better use mean_confidence_interval_z or mean_confidence_interval_t


163
164
165
166
# File 'lib/statsample/srs.rb', line 163

def mean_confidence_interval(mean,s,n_sample,n_population,x)
    range=x*se(s,n_sample,n_population)
    [mean-range,mean+range]
end

.mean_confidence_interval_t(mean, s, n_sample, n_population, margin = 0.95) ⇒ Object

Confidence Interval using T-Student Use with n < 60


150
151
152
153
# File 'lib/statsample/srs.rb', line 150

def mean_confidence_interval_t(mean,s,n_sample,n_population,margin=0.95)
    t=Distribution::T.p_value(1-((1-margin) / 2),n_sample-1)
    mean_confidence_interval(mean,s,n_sample,n_population,t)
end

.mean_confidence_interval_z(mean, s, n_sample, n_population, margin = 0.95) ⇒ Object

Confidente Interval using Z Use with n > 60


156
157
158
159
# File 'lib/statsample/srs.rb', line 156

def mean_confidence_interval_z(mean,s,n_sample,n_population,margin=0.95)
    z=Distribution::Normal.p_value(1-((1-margin) / 2))
    mean_confidence_interval(mean,s,n_sample,n_population, z)
end

.proportion_confidence_interval(p, sam, pop, x) ⇒ Object

Proportion confidence interval with x value Uses estimated proportion, sample without replacement


64
65
66
67
68
# File 'lib/statsample/srs.rb', line 64

def proportion_confidence_interval(p, sam,pop , x)
    #f=sam.quo(pop)
    one_range=x * Math::sqrt((qf(sam, pop) * p * (1-p)).quo(sam-1)) + (1.quo(sam * 2.0))
    [p-one_range, p+one_range]
end

.proportion_confidence_interval_t(prop, n_sample, n_population, margin = 0.95) ⇒ Object

Proportion confidence interval with t values Uses estimated proportion, sample without replacement.


50
51
52
53
# File 'lib/statsample/srs.rb', line 50

def proportion_confidence_interval_t(prop, n_sample, n_population, margin=0.95)
    t = Distribution::T.p_value(1-((1-margin).quo(2)) , n_sample-1)
    proportion_confidence_interval(prop,n_sample,n_population, t)
end

.proportion_confidence_interval_z(p, n_sample, n_population, margin = 0.95) ⇒ Object

Proportion confidence interval with z values Uses estimated proportion, sample without replacement.


57
58
59
60
# File 'lib/statsample/srs.rb', line 57

def proportion_confidence_interval_z(p, n_sample, n_population, margin=0.95)
    z=Distribution::Normal.p_value(1-((1-margin).quo(2)))
    proportion_confidence_interval(p,n_sample,n_population, z)
end

.proportion_sd_ep_wor(p, sam, pop) ⇒ Object

Standard deviation for sample distribution of a proportion. Estimated proportion, sample without replacement. Reference:

  • Cochran, 1972, T├ęcnicas de muestreo


93
94
95
96
# File 'lib/statsample/srs.rb', line 93

def proportion_sd_ep_wor(p, sam,pop)
    fsc=(pop-sam).quo((sam-1)*pop)
    Math::sqrt(fsc*p*(1-p))
end

.proportion_sd_ep_wr(p, n_sample) ⇒ Object

Standard deviation for sample distribution of a proportion Estimated proportion, sample with replacement Based on stattrek.com/Lesson6/SRS.aspx.


86
87
88
# File 'lib/statsample/srs.rb', line 86

def proportion_sd_ep_wr(p, n_sample)
    Math::sqrt(p*(1-p).quo(n_sample-1))
end

.proportion_sd_kp_wor(p, sam, pop) ⇒ Object

Standard deviation for sample distribution of a proportion Know proportion, sample without replacement.

Sources:

  • Cochran(1972)


80
81
82
# File 'lib/statsample/srs.rb', line 80

def proportion_sd_kp_wor(p, sam, pop)
    fpc(sam,pop)*Math::sqrt(p*(1-p).quo(sam))
end

.proportion_sd_kp_wr(p, n_sample) ⇒ Object

Standard deviation for sample distribution of a proportion Know proportion, sample with replacement. Based on stattrek.com/Lesson6/SRS.aspx


72
73
74
# File 'lib/statsample/srs.rb', line 72

def proportion_sd_kp_wr(p, n_sample)
    Math::sqrt(p*(1-p).quo(n_sample))
end

.proportion_total_sd_ep_wor(prop, sam, pop) ⇒ Object

Total estimation sd based on sample. Estimated proportion, sample without replacement Source: Cochran(1972)


108
109
110
111
# File 'lib/statsample/srs.rb', line 108

def proportion_total_sd_ep_wor(prop, sam, pop)
    fsc=((pop - sam).to_f / ( sam - 1))
    Math::sqrt(fsc*pop*prop*(1-prop))
end

.proportion_total_sd_kp_wor(prop, sam, pop) ⇒ Object

Total estimation sd based on sample. Known proportion, sample without replacement Reference:

  • Cochran(1972)


102
103
104
# File 'lib/statsample/srs.rb', line 102

def proportion_total_sd_kp_wor(prop, sam, pop)
    pob * proportion_sd_kp_wor(p, sam, pop)
end

.qf(sam, pop) ⇒ Object

Non sample fraction.

1 - sample fraction


31
32
33
# File 'lib/statsample/srs.rb', line 31

def qf(sam , pop)
    1-(sam.quo(pop))
end

.standard_error_esd_wor(s, sam, pop) ⇒ Object Also known as: standard_error, se

Standard error of the mean. Estimated variance, without replacement Cochran (1972) p.47


135
136
137
# File 'lib/statsample/srs.rb', line 135

def standard_error_esd_wor(s,sam,pop)
    s.quo(Math::sqrt(sam)) * Math::sqrt(qf(sam,pop))
end

.standard_error_ksd_wor(s, sam, pop) ⇒ Object

Standard error of the mean. Known variance, sample w/o replacement


126
127
128
# File 'lib/statsample/srs.rb', line 126

def standard_error_ksd_wor(s,sam,pop)
    s.quo(Math::sqrt(sam)) * Math::sqrt(qf(sam,pop)) 
end

.standard_error_ksd_wr(s, sam, pop) ⇒ Object Also known as: standard_error_esd_wr

Standard error. Known variance, sample with replacement.


121
122
123
# File 'lib/statsample/srs.rb', line 121

def standard_error_ksd_wr(s, sam, pop)
    s.quo(Math::sqrt(sam)) * Math::sqrt((pop-1).quo(pop))
end

.standard_error_total(s, sam, pop) ⇒ Object

Standard error of total estimation


144
145
146
# File 'lib/statsample/srs.rb', line 144

def standard_error_total(s,sam,pop)
    pop*se(s,sam,pop)
end