module Statsample::SRS

Several methods to estimate parameters for simple random sampling

Reference:

Several methods to estimate parameters for simple random sampling

Reference:

Mean stimation

↑ top

Public Instance Methods

mean_confidence_interval(mean,s,n_sample,n_population,x) click to toggle source

Confidente interval using X.

Better use #mean_confidence_interval_z or #mean_confidence_interval_t

# 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) click to toggle source

Confidence Interval using T-Student Use with n < 60

# 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) click to toggle source

Confidente Interval using Z Use with n > 60

# 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
standard_error_esd_wor(s,sam,pop) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

Standard error. Known variance, sample with replacement.

# 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) click to toggle source

Standard error of total estimation

# File lib/statsample/srs.rb, line 144
def standard_error_total(s,sam,pop)
    pop*se(s,sam,pop)
end

Proportion estimation

↑ top

Public Instance Methods

estimation_n(d,prop,n_pobl,margin=0.95) click to toggle source

Sample size estimation for proportions, finite poblation.

# 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) click to toggle source

Sample size estimation for proportions, infinite poblation

# 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) click to toggle source

Finite population correction (over standard deviation)

# File lib/statsample/srs.rb, line 24
def fpc(sam,pop)
    Math::sqrt((pop-sam).quo(pop-1))
end
fpc_var(sam,pop) click to toggle source

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

# File lib/statsample/srs.rb, line 20
def fpc_var(sam,pop)
    (pop - sam).quo(pop - 1)
end
proportion_confidence_interval(p, sam,pop , x) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

  • Cochran, 1972, T├ęcnicas de muestreo

# 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) click to toggle source

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

# 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) click to toggle source

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

Sources:

  • Cochran(1972)

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

  • Cochran(1972)

# 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) click to toggle source

Non sample fraction.

1 - sample fraction

# File lib/statsample/srs.rb, line 31
def qf(sam , pop)
    1-(sam.quo(pop))
end