| Title: | Survey Sampling Methods for Teaching and Practice |
|---|---|
| Description: | Planning, selection, and estimation for surveys under the main probability sampling designs taught in introductory sampling courses: simple random sampling with and without replacement, stratified sampling (proportional, Neyman, and cost-based allocation), systematic sampling, one- and two-stage cluster sampling, and ratio and regression estimators. Functions accept a superset of the inputs a given formula requires and silently ignore arguments that are not needed for the selected computation. Each function returns a structured object with the point estimate, the associated variance and confidence interval, a step-by-step breakdown of the calculation, and a short pedagogical note suggesting related methods to explore, making the package suitable both for applied survey work and for classroom use. Methods follow Cochran (1977, ISBN:0-471-16240-X) and Bolfarine & Bussab (2005, ISBN:8521203675), among others referenced in each function's documentation. |
| Authors: | Miguel Luiz de Almeida Pinto [aut, cre], Mariano Martinez Espinosa [aut] (Author of the source course material (course notes) this package implements) |
| Maintainer: | Miguel Luiz de Almeida Pinto <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-13 23:52:25 UTC |
| Source: | https://github.com/cran/sampleone |
Inflates a sample size by a flat percentage buffer, following
Example 3.14 of the course notes: n_ajustado = n * (1 + taxa_acrescimo)
(there illustrated as a 25% buffer added to protect against losses,
refusals, or other contingencies during fieldwork). This is a distinct,
simpler convention from the formal non-response adjustment of Section
4.7.2 (dividing by an expected response rate, see the course notes'
Eq. 4.25 and the package's stratified-sampling module) – do not
confuse the two: dividing by (1 - taxa) targets a given number of
completed responses after losses, while multiplying by (1 + taxa) is
a simpler flat safety margin, as used here.
aas_ajustar_perdas(n, taxa_acrescimo, arredondar = c("cima", "proximo"))aas_ajustar_perdas(n, taxa_acrescimo, arredondar = c("cima", "proximo"))
n |
Base (unadjusted) sample size. |
taxa_acrescimo |
Flat buffer to add, as a proportion (e.g. |
arredondar |
Either |
A sampling_result object with the adjusted sample size.
aas_ajustar_perdas(357, 0.25) # arredondar="cima" (padrao) -> 447 aas_ajustar_perdas(357, 0.25, arredondar = "proximo") # Exemplo 3.14 -> 446aas_ajustar_perdas(357, 0.25) # arredondar="cima" (padrao) -> 447 aas_ajustar_perdas(357, 0.25, arredondar = "proximo") # Exemplo 3.14 -> 446
Computes the sampling-plan effect (EPA, "efeito do planejamento
amostral", a.k.a. design effect) comparing AASs to AASc for the same N
and n, following Eq. (3.46)-(3.47) of the course notes.
aas_comparar_reposicao(N, n)aas_comparar_reposicao(N, n)
N |
Population size. |
n |
Sample size. |
A sampling_result object with the EPA value and its
interpretation.
Bolfarine, H.; Bussab, W.O. (2005). Elementos de Amostragem. Edgard Blucher.
aas_comparar_reposicao(N = 2695, n = 336)aas_comparar_reposicao(N = 2695, n = 336)
Estimates the population mean from a simple random sample, with or without replacement, together with its variance and a confidence interval. Corresponds to Eqs. (3.4)-(3.7) (with replacement, AASc) and (3.25)-(3.28.1) (without replacement, AASs) of the course notes.
aas_estima_media(x, N = NULL, reposicao = c("sem", "com"), conf = 0.95, ...)aas_estima_media(x, N = NULL, reposicao = c("sem", "com"), conf = 0.95, ...)
x |
Numeric vector with the sample data. |
N |
Optional population size. If |
reposicao |
Either |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated mean, its
variance, coefficient of variation, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley. Bolfarine, H.; Bussab, W.O. (2005). Elementos de Amostragem. Edgard Blucher.
aas_estima_media(c(12, 30, 18), N = 3, reposicao = "com")aas_estima_media(c(12, 30, 18), N = 3, reposicao = "com")
Estimates a population proportion from a simple random sample, with or without replacement. Corresponds to Eqs. (3.16)-(3.21) (AASc) and (3.39)-(3.44) (AASs) of the course notes.
aas_estima_proporcao( x, N = NULL, reposicao = c("sem", "com"), conf = 0.95, ... )aas_estima_proporcao( x, N = NULL, reposicao = c("sem", "com"), conf = 0.95, ... )
x |
Numeric or logical vector coded 0/1 (or |
N |
Optional population size. If |
reposicao |
Either |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated proportion, its
variance, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
aas_estima_proporcao(c(1, 0, 1, 1, 0, 1, 0, 0), N = 500)aas_estima_proporcao(c(1, 0, 1, 1, 0, 1, 0, 0), N = 500)
Estimates the population total from a
simple random sample without replacement (Eq. 3.28.2-3.28.3 of the
course notes). For the "with replacement" plan, the same expressions
are used with f = 0.
aas_estima_total(x, N, reposicao = c("sem", "com"), conf = 0.95, ...)aas_estima_total(x, N, reposicao = c("sem", "com"), conf = 0.95, ...)
x |
Numeric vector with the sample data. |
N |
Population size (required to scale the total). |
reposicao |
Either |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated total, its
variance, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 2 (extension not explicit in the course notes for AAS, but consistent with Eq. 3.28.3).
aas_estima_total(c(12, 30, 18), N = 300)aas_estima_total(c(12, 30, 18), N = 300)
Convenience "umbrella" function that accepts every input that might be
relevant to determine an AAS sample size (population variance or
standard deviation, expected proportion, population size, expected
losses) and automatically dispatches to aas_tamanho_media() or
aas_tamanho_proporcao() depending on parametro, silently ignoring
whichever inputs are not needed for the chosen calculation.
aas_tamanho_amostra( parametro = c("media", "proporcao"), N = NULL, sigma2 = NULL, sigma = NULL, p = NULL, d, conf = 0.95, perda = 0, arredondar = c("cima", "proximo"), ... )aas_tamanho_amostra( parametro = c("media", "proporcao"), N = NULL, sigma2 = NULL, sigma = NULL, p = NULL, d, conf = 0.95, perda = 0, arredondar = c("cima", "proximo"), ... )
parametro |
Either |
N |
Optional population size. |
sigma2 |
Population variance (used only when |
sigma |
Population standard deviation (alternative to |
p |
Expected proportion (used only when |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
perda |
Optional expected non-response/loss rate in |
arredondar |
Either |
... |
Ignored. Any other variables from a broader problem statement (e.g. sample data, stratum information) may be passed here without causing an error. |
A sampling_result object, as produced by
aas_tamanho_media() or aas_tamanho_proporcao().
aas_tamanho_amostra(parametro = "media", sigma = 7, d = 2) aas_tamanho_amostra(parametro = "proporcao", p = 0.6, d = 0.03, N = 5000)aas_tamanho_amostra(parametro = "media", sigma = 7, d = 2) aas_tamanho_amostra(parametro = "proporcao", p = 0.6, d = 0.03, N = 5000)
Computes the sample size needed to estimate a population mean with a
given margin of error, choosing automatically between the
infinite/unknown-population formula (Eq. 3.15) and the finite-population
formula (Eq. 3.37/3.38) depending on whether N is supplied. Extra
arguments not needed for the chosen formula are ignored.
aas_tamanho_media( sigma2 = NULL, sigma = NULL, d, conf = 0.95, N = NULL, perda = 0, arredondar = c("cima", "proximo"), ... )aas_tamanho_media( sigma2 = NULL, sigma = NULL, d, conf = 0.95, N = NULL, perda = 0, arredondar = c("cima", "proximo"), ... )
sigma2 |
Population variance (or its estimate). Alternatively
supply |
sigma |
Optional population standard deviation, used only if
|
d |
Tolerable margin of error (same units as the variable). |
conf |
Confidence level, default |
N |
Optional population size. If |
perda |
Optional flat safety-margin proportion (e.g. |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required sample size.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
aas_tamanho_media(sigma = 7, d = 2, conf = 0.95) aas_tamanho_media(sigma2 = 1240, d = 7, conf = 0.95, N = 10000)aas_tamanho_media(sigma = 7, d = 2, conf = 0.95) aas_tamanho_media(sigma2 = 1240, d = 7, conf = 0.95, N = 10000)
Computes the sample size needed to estimate a population proportion with
a given margin of error, using the infinite/unknown-population formula
(Eq. 3.23, or the conservative Eq. 3.24 when p is unknown) or the
finite-population formula (Eq. 3.45) when N is supplied.
aas_tamanho_proporcao( p = NULL, d, conf = 0.95, N = NULL, perda = 0, arredondar = c("cima", "proximo"), ... )aas_tamanho_proporcao( p = NULL, d, conf = 0.95, N = NULL, perda = 0, arredondar = c("cima", "proximo"), ... )
p |
Expected proportion. If |
d |
Tolerable margin of error (same units as the variable). |
conf |
Confidence level, default |
N |
Optional population size. If |
perda |
Optional flat safety-margin proportion (e.g. |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required sample size.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
aas_tamanho_proporcao(p = 0.6, d = 0.03, conf = 0.95) aas_tamanho_proporcao(d = 0.05, conf = 0.95) # p desconhecido -> conservadoraas_tamanho_proporcao(p = 0.6, d = 0.03, conf = 0.95) aas_tamanho_proporcao(d = 0.05, conf = 0.95) # p desconhecido -> conservador
Computes the sample mean (Eq. 2.8), the unbiased sample variance (Eq. 2.10, divisor n-1), and, when the data are binary, the sample proportion (Eq. 2.9) – all from a single call. This function is used internally as a building block by most other functions in the package.
amostra_estimadores(x, ...)amostra_estimadores(x, ...)
x |
Numeric vector with the sample data. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the requested sample estimators.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
amostra_estimadores(c(12, 30, 18)) amostra_estimadores(c(1, 0, 1, 1, 0))amostra_estimadores(c(12, 30, 18)) amostra_estimadores(c(1, 0, 1, 1, 0))
Inflates a base sample size (computed under a simple-random-sampling
assumption) by a design effect (deff, accounting for the extra
variability introduced by a more complex design such as clustering or
multi-stage sampling) and by an expected response rate, following
Eq. (6.6) of the course notes (Espinosa et al., 2019).
amostragem_ajustar_deff_resposta(n_prime, deff = 1.5, taxa_resposta = 0.85)amostragem_ajustar_deff_resposta(n_prime, deff = 1.5, taxa_resposta = 0.85)
n_prime |
Base sample size (e.g. from |
deff |
Design effect ( |
taxa_resposta |
Expected response rate, default |
Although this formula is first introduced in the course notes' cluster
sampling chapter, it is a general-purpose adjustment: it only needs
a base sample size, a design effect, and a response rate – nothing
specific to clusters. Course exercises apply it to plain AAS and
stratified problems just as often as to cluster problems (e.g. to
scale up a prevalence-survey sample size for an anticipated design
effect and non-response), so it is exposed here as a cross-cutting
utility rather than tucked away under the cong1_ prefix.
cong1_ajustar_deff() remains available as an alias, for continuity
with the cluster-sampling chapter and its documentation.
A sampling_result object with the adjusted sample size.
Espinosa et al. (2019), as cited in the course notes, Eq. (6.6).
# Cap. 3 (AAS) + deff + resposta -- ex.: planejamento de prevalencia n_prime <- aas_tamanho_proporcao(p = 0.20, d = 0.05)$estimativa$n amostragem_ajustar_deff_resposta(n_prime, deff = 1.2, taxa_resposta = 0.85)# Cap. 3 (AAS) + deff + resposta -- ex.: planejamento de prevalencia n_prime <- aas_tamanho_proporcao(p = 0.20, d = 0.05)$estimativa$n amostragem_ajustar_deff_resposta(n_prime, deff = 1.2, taxa_resposta = 0.85)
Inflates a sample size to guarantee a target number of completed
responses given an expected response rate, following Eqs. (4.24)-(4.25)
of the course notes: n* = n / taxa_resposta. This targets completed
responses after losses and is conceptually distinct from the flat
safety-margin buffer of aas_ajustar_perdas() (which multiplies by
1 + taxa, see Example 3.14) – do not confuse the two.
amostragem_ajustar_resposta(n, taxa_resposta)amostragem_ajustar_resposta(n, taxa_resposta)
n |
Base sample size computed ignoring non-response. |
taxa_resposta |
Expected response rate, in |
A sampling_result object with the adjusted sample size.
amostragem_ajustar_resposta(1525, 0.85)amostragem_ajustar_resposta(1525, 0.85)
Convenience function that lines up the estimated variance obtained
under different sampling designs (as returned by sampling_result
objects from this package) so they can be compared directly, computing
the sampling-plan effect (EPA / design effect) of each one relative to
a chosen baseline. This operationalises the comparisons illustrated
throughout the course notes (Section 3.7.7, Examples 4.4-4.5, and the
design-effect discussion in Section 6.1.5).
amostragem_comparar_planos(..., referencia = NULL)amostragem_comparar_planos(..., referencia = NULL)
... |
Two or more named |
referencia |
Name of the plan to use as the baseline (denominator of the EPA ratio). Defaults to the first plan supplied. |
A sampling_result object with a comparison table of
variances and EPA (design effect) ratios relative to referencia.
x <- rnorm(30, 50, 5) plano_aas <- aas_estima_media(x, N = 300) # (em um caso real, plano_estrat viria de estr_estima_media() com os # mesmos dados organizados em estratos) amostragem_comparar_planos(aas = plano_aas)x <- rnorm(30, 50, 5) plano_aas <- aas_estima_media(x, N = 300) # (em um caso real, plano_estrat viria de estr_estima_media() com os # mesmos dados organizados em estratos) amostragem_comparar_planos(aas = plano_aas)
Convenience "umbrella" function analogous to aas_tamanho_amostra():
dispatches automatically to cong2_estima_media() (when M is
supplied) or cong2_estima_razao_media() (when M is NULL),
ignoring whichever inputs are not needed.
cong_estima( dados = NULL, Mi = NULL, mi = NULL, yi_bar = NULL, si2 = NULL, Nc, M = NULL, conf = 0.95, ... )cong_estima( dados = NULL, Mi = NULL, mi = NULL, yi_bar = NULL, si2 = NULL, Nc, M = NULL, conf = 0.95, ... )
dados |
A |
Mi |
Optional numeric vector with the population size of each
sampled cluster (used instead of |
mi |
Optional numeric vector with the number of sampled elements in each cluster. |
yi_bar |
Optional numeric vector with the sample mean of each cluster. |
si2 |
Optional numeric vector with the sample variance within each cluster (Eq. 6.15). |
Nc |
Total number of clusters in the population. |
M |
Total number of elements in the population. |
conf |
Confidence level, default |
... |
Ignored. Any other variables from a broader problem statement may be passed here without causing an error. |
A sampling_result object, as produced by
cong2_estima_media() or cong2_estima_razao_media().
Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) yi_bar <- c(5.4, 4.0, 5.6667, 4.8, 4.3, 3.8333, 5.0, 3.8462, 4.875, 5.0) si2 <- c(11.3778, 10.6667, 16.75, 13.2889, 11.1222, 14.8788, 5.1429, 4.3077, 6.125, 11.8) cong_estima(Mi = Mi, mi = mi, yi_bar = yi_bar, si2 = si2, Nc = 90) # M ausente -> razaoMi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) yi_bar <- c(5.4, 4.0, 5.6667, 4.8, 4.3, 3.8333, 5.0, 3.8462, 4.875, 5.0) si2 <- c(11.3778, 10.6667, 16.75, 13.2889, 11.1222, 14.8788, 5.1429, 4.3077, 6.125, 11.8) cong_estima(Mi = Mi, mi = mi, yi_bar = yi_bar, si2 = si2, Nc = 90) # M ausente -> razao
Alias for amostragem_ajustar_deff_resposta(), kept for continuity with
the cluster-sampling chapter, since that is where the course notes
first introduce Eq. (6.6). The underlying formula is general-purpose
(not specific to clusters) – see amostragem_ajustar_deff_resposta()
for the full documentation and for use with non-cluster problems (AAS,
stratified, etc.).
cong1_ajustar_deff(n_prime, deff = 1.5, taxa_resposta = 0.85)cong1_ajustar_deff(n_prime, deff = 1.5, taxa_resposta = 0.85)
n_prime |
Base sample size (e.g. from |
deff |
Design effect ( |
taxa_resposta |
Expected response rate, default |
A sampling_result object with the adjusted sample size.
Espinosa et al. (2019), as cited in the course notes, Eq. (6.6).
cong1_ajustar_deff(n_prime = 518, deff = 1.5, taxa_resposta = 0.85)cong1_ajustar_deff(n_prime = 518, deff = 1.5, taxa_resposta = 0.85)
Estimates the population mean from a sample of whole clusters, all of whose elements were observed (one-stage cluster sampling), following Eqs. (6.1)-(6.4) of the course notes.
cong1_estima_media(yi, Mi, Nc, M = NULL, conf = 0.95, ...)cong1_estima_media(yi, Mi, Nc, M = NULL, conf = 0.95, ...)
yi |
Numeric vector with the cluster totals ( |
Mi |
Numeric vector with the number of elements in each sampled cluster. |
Nc |
Total number of clusters in the population. |
M |
Optional total number of elements in the population (used to
compute the population average cluster size |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated mean, variance,
and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 9.
# Exemplo 6.1 (turmas da UFMT) cong1_estima_media( yi = c(1209, 921, 1116, 1433, 1037, 2112, 1737, 2206, 2112, 1870), Mi = c(20, 16, 17, 21, 16, 25, 21, 26, 25, 23), Nc = 373, M = 8018 )# Exemplo 6.1 (turmas da UFMT) cong1_estima_media( yi = c(1209, 921, 1116, 1433, 1037, 2112, 1737, 2206, 2112, 1870), Mi = c(20, 16, 17, 21, 16, 25, 21, 26, 25, 23), Nc = 373, M = 8018 )
Analogous to cong1_estima_media() but for a population proportion,
following Eqs. (6.7)-(6.10) of the course notes.
cong1_estima_proporcao(yi, Mi, Nc, M = NULL, conf = 0.95, ...)cong1_estima_proporcao(yi, Mi, Nc, M = NULL, conf = 0.95, ...)
yi |
Numeric vector with the number of "successes" (elements with the characteristic of interest) in each sampled cluster. |
Mi |
Numeric vector with the number of elements in each sampled cluster. |
Nc |
Total number of clusters in the population. |
M |
Optional total number of elements in the population (see
|
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated proportion,
variance, and confidence interval.
# Exemplo 6.3 (proporcao de alunos com peso acima da mediana) cong1_estima_proporcao( yi = c(7, 6, 5, 6, 5, 7, 5, 6, 6, 6), Mi = c(20, 16, 17, 21, 16, 25, 21, 26, 25, 23), Nc = 373, M = 8018 )# Exemplo 6.3 (proporcao de alunos com peso acima da mediana) cong1_estima_proporcao( yi = c(7, 6, 5, 6, 5, 7, 5, 6, 6, 6), Mi = c(20, 16, 17, 21, 16, 25, 21, 26, 25, 23), Nc = 373, M = 8018 )
Computes the number of clusters needed to estimate a population mean with a given margin of error under one-stage cluster sampling (Eq. 6.5 of the course notes).
cong1_tamanho_media( Nc, sigmac2, M_barra, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )cong1_tamanho_media( Nc, sigmac2, M_barra, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )
Nc |
Total number of clusters in the population. |
sigmac2 |
Between-cluster population variance (or its estimate, from a pilot study). |
M_barra |
Average number of elements per cluster. |
d |
Tolerable margin of error (in the original units of the variable, not per-cluster). |
conf |
Confidence level, default |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required number of
clusters.
cong1_tamanho_media(Nc = 373, sigmac2 = 51054.3854, M_barra = 8018/373, d = 3)cong1_tamanho_media(Nc = 373, sigmac2 = 51054.3854, M_barra = 8018/373, d = 3)
Analogous to cong1_tamanho_media() but for a population proportion
(Eq. 6.11 of the course notes).
cong1_tamanho_proporcao( Nc, sigmacp2, M_barra, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )cong1_tamanho_proporcao( Nc, sigmacp2, M_barra, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )
Nc |
Total number of clusters in the population. |
sigmacp2 |
Between-cluster population variance for the proportion (or its estimate). |
M_barra |
Average number of elements per cluster. |
d |
Tolerable margin of error (in the original units of the variable, not per-cluster). |
conf |
Confidence level, default |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required number of
clusters.
cong1_tamanho_proporcao(Nc = 373, sigmacp2 = 0.91785840, M_barra = 8018/373, d = 0.013)cong1_tamanho_proporcao(Nc = 373, sigmacp2 = 0.91785840, M_barra = 8018/373, d = 0.013)
Estimates the population mean from a two-stage cluster sample (a sample
of clusters – UPA – followed by a sample of elements within each
sampled cluster – USA), when the total population size M is known,
following Eqs. (6.12)-(6.18) of the course notes.
cong2_estima_media( dados = NULL, Mi = NULL, mi = NULL, yi_bar = NULL, si2 = NULL, Nc, M, conf = 0.95, ... )cong2_estima_media( dados = NULL, Mi = NULL, mi = NULL, yi_bar = NULL, si2 = NULL, Nc, M, conf = 0.95, ... )
dados |
A |
Mi |
Optional numeric vector with the population size of each
sampled cluster (used instead of |
mi |
Optional numeric vector with the number of sampled elements in each cluster. |
yi_bar |
Optional numeric vector with the sample mean of each cluster. |
si2 |
Optional numeric vector with the sample variance within each cluster (Eq. 6.15). |
Nc |
Total number of clusters in the population. |
M |
Total number of elements in the population. |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
Two calling styles are supported: (1) pass raw per-element data via
dados (a data.frame with one row per sampled element), or (2) pass
already-summarised per-cluster vectors Mi, mi, yi_bar, si2
directly. The second style is convenient when a problem statement (as
in a textbook exercise) already gives per-cluster summaries instead of
raw data – any of dados/Mi/mi/yi_bar/si2 not needed for the
chosen style are simply ignored.
A sampling_result object with the estimated mean, its
two-part variance decomposition, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 10.
Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) yi_bar <- c(5.4, 4.0, 5.6667, 4.8, 4.3, 3.8333, 5.0, 3.8462, 4.875, 5.0) si2 <- c(11.3778, 10.6667, 16.75, 13.2889, 11.1222, 14.8788, 5.1429, 4.3077, 6.125, 11.8) cong2_estima_media(Mi = Mi, mi = mi, yi_bar = yi_bar, si2 = si2, Nc = 90, M = 4500)Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) yi_bar <- c(5.4, 4.0, 5.6667, 4.8, 4.3, 3.8333, 5.0, 3.8462, 4.875, 5.0) si2 <- c(11.3778, 10.6667, 16.75, 13.2889, 11.1222, 14.8788, 5.1429, 4.3077, 6.125, 11.8) cong2_estima_media(Mi = Mi, mi = mi, yi_bar = yi_bar, si2 = si2, Nc = 90, M = 4500)
Analogous to cong2_estima_media() but for a population proportion,
following Eqs. (6.24)-(6.29) of the course notes. Note that, unlike
cong2_estima_media(), the proportion estimator is inherently a
ratio-type estimator (structurally analogous to
cong2_estima_razao_media()) and therefore always uses the sample
average cluster size m_barra = mean(Mi) in its variance formula, even
when the population totals Nc/M are known – this is exactly how
Example 6.6 of the course notes computes it (using m_barra = 52.2
rather than M/Nc = 50, even though both M and Nc are known in
that example).
cong2_estima_proporcao(Mi, mi, pi_hat, Nc, M = NULL, conf = 0.95, ...)cong2_estima_proporcao(Mi, mi, pi_hat, Nc, M = NULL, conf = 0.95, ...)
Mi |
Numeric vector with the population size of each sampled cluster. |
mi |
Numeric vector with the number of sampled elements in each cluster. |
pi_hat |
Numeric vector with the sample proportion of each cluster (Eq. 6.24). |
Nc |
Total number of clusters in the population. |
M |
Ignored (kept for signature symmetry with
|
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated proportion, its
variance, and confidence interval.
Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) pi_hat <- c(0.4, 0.3077, 0.3333, 0.3, 0.3, 0.25, 0.375, 0.3077, 0.375, 0.3636) cong2_estima_proporcao(Mi = Mi, mi = mi, pi_hat = pi_hat, Nc = 90)Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) pi_hat <- c(0.4, 0.3077, 0.3333, 0.3, 0.3, 0.25, 0.375, 0.3077, 0.375, 0.3636) cong2_estima_proporcao(Mi = Mi, mi = mi, pi_hat = pi_hat, Nc = 90)
Analogous to cong2_estima_media() but for the case where the total
population size M is unknown, using the ratio estimator of
Eqs. (6.19)-(6.23) of the course notes, with m_barra (the sample
average cluster size) substituted for M_barra = M/Nc.
cong2_estima_razao_media( dados = NULL, Mi = NULL, mi = NULL, yi_bar = NULL, si2 = NULL, Nc, M = NULL, conf = 0.95, ... )cong2_estima_razao_media( dados = NULL, Mi = NULL, mi = NULL, yi_bar = NULL, si2 = NULL, Nc, M = NULL, conf = 0.95, ... )
dados |
A |
Mi |
Optional numeric vector with the population size of each
sampled cluster (used instead of |
mi |
Optional numeric vector with the number of sampled elements in each cluster. |
yi_bar |
Optional numeric vector with the sample mean of each cluster. |
si2 |
Optional numeric vector with the sample variance within each cluster (Eq. 6.15). |
Nc |
Total number of clusters in the population. |
M |
Ignored for this estimator (kept for signature symmetry with
|
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the ratio-estimated mean, its
variance, and confidence interval.
Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) yi_bar <- c(5.4, 4.0, 5.6667, 4.8, 4.3, 3.8333, 5.0, 3.8462, 4.875, 5.0) si2 <- c(11.3778, 10.6667, 16.75, 13.2889, 11.1222, 14.8788, 5.1429, 4.3077, 6.125, 11.8) cong2_estima_razao_media(Mi = Mi, mi = mi, yi_bar = yi_bar, si2 = si2, Nc = 90)Mi <- c(50, 65, 45, 48, 52, 58, 42, 66, 40, 56) mi <- c(10, 13, 9, 10, 10, 12, 8, 13, 8, 11) yi_bar <- c(5.4, 4.0, 5.6667, 4.8, 4.3, 3.8333, 5.0, 3.8462, 4.875, 5.0) si2 <- c(11.3778, 10.6667, 16.75, 13.2889, 11.1222, 14.8788, 5.1429, 4.3077, 6.125, 11.8) cong2_estima_razao_media(Mi = Mi, mi = mi, yi_bar = yi_bar, si2 = si2, Nc = 90)
Allocates strata sample sizes to minimise variance subject to a fixed total budget, when per-unit sampling costs differ across strata (Eqs. 4.7-4.8 for means, Eq. 4.13 for proportions).
estr_alocacao_custo(n, Nk, sigmak = NULL, pk = NULL, ck, ...)estr_alocacao_custo(n, Nk, sigmak = NULL, pk = NULL, ck, ...)
n |
Total sample size to allocate. |
Nk |
Numeric vector with the population size of each stratum. |
sigmak |
Numeric vector with the population standard deviation of
each stratum (for a mean problem). Ignored if |
pk |
Numeric vector with the population proportion of each
stratum (for a proportion problem); if supplied, |
ck |
Numeric vector with the sampling cost per unit in each stratum. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the per-stratum sample sizes
under cost-based optimum allocation.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 5.
estr_alocacao_custo(n = 491, Nk = c(4000, 3000, 2000), sigmak = c(3, 3, 2), ck = c(10, 10, 20))estr_alocacao_custo(n = 491, Nk = c(4000, 3000, 2000), sigmak = c(3, 3, 2), ck = c(10, 10, 20))
Allocates a total sample size across strata to minimise variance for a
fixed total sample size, assuming equal per-unit cost across strata
(Eqs. 4.18-4.20 of the course notes). Works for both mean (sigmak
known) and proportion (pk known, substituting
sigmak = sqrt(pk*(1-pk))) problems.
estr_alocacao_neyman(n, Nk, sigmak = NULL, pk = NULL, ...)estr_alocacao_neyman(n, Nk, sigmak = NULL, pk = NULL, ...)
n |
Total sample size to allocate. |
Nk |
Numeric vector with the population size of each stratum. |
sigmak |
Numeric vector with the population standard deviation of
each stratum (for a mean problem). Ignored if |
pk |
Numeric vector with the population proportion of each
stratum (for a proportion problem); if supplied, |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the per-stratum sample sizes
under Neyman allocation.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 5.
estr_alocacao_neyman(n = 261, Nk = c(1540, 770, 385), sigmak = c(2.6, 3, 3.3))estr_alocacao_neyman(n = 261, Nk = c(1540, 770, 385), sigmak = c(2.6, 3, 3.3))
Allocates a total sample size across strata proportionally to stratum
size, nk = n * Wk (Eq. 4.6, or Eq. 4.14-4.15 for proportions).
estr_alocacao_proporcional(n, Nk, ...)estr_alocacao_proporcional(n, Nk, ...)
n |
Total sample size to allocate. |
Nk |
Numeric vector with the population size of each stratum. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the per-stratum sample sizes.
estr_alocacao_proporcional(n = 120, Nk = c(1540, 770, 385))estr_alocacao_proporcional(n = 120, Nk = c(1540, 770, 385))
Estimates the population mean from data collected under stratified random sampling, given per-stratum sample means and sizes (Eqs. 4.1-4.4 of the course notes).
estr_estima_media(Nk, xk_bar, sk2, nk, conf = 0.95, ...)estr_estima_media(Nk, xk_bar, sk2, nk, conf = 0.95, ...)
Nk |
Numeric vector with the population size of each stratum. |
xk_bar |
Numeric vector with the sample mean of each stratum. |
sk2 |
Numeric vector with the sample variance of each stratum. |
nk |
Numeric vector with the sample size of each stratum. |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated stratified mean,
its variance, coefficient of variation, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 5.
estr_estima_media(Nk = c(1540, 770, 385), xk_bar = c(120, 118, 125), sk2 = c(7, 9, 11), nk = c(69, 34, 17))estr_estima_media(Nk = c(1540, 770, 385), xk_bar = c(120, 118, 125), sk2 = c(7, 9, 11), nk = c(69, 34, 17))
Estimates a population proportion from data collected under stratified random sampling, given per-stratum sample proportions and sizes (Eqs. 4.9-4.11 of the course notes).
estr_estima_proporcao(Nk, pk, nk, conf = 0.95, ...)estr_estima_proporcao(Nk, pk, nk, conf = 0.95, ...)
Nk |
Numeric vector with the population size of each stratum. |
pk |
Numeric vector with the sample proportion of each stratum. |
nk |
Numeric vector with the sample size of each stratum. |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated stratified
proportion, its variance, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 5.
estr_estima_proporcao(Nk = c(1540, 770, 385), pk = c(0.75, 0.50, 0.25), nk = c(161, 81, 40))estr_estima_proporcao(Nk = c(1540, 770, 385), pk = c(0.75, 0.50, 0.25), nk = c(161, 81, 40))
Convenience "umbrella" function analogous to aas_tamanho_amostra():
accepts every input potentially relevant to a stratified sample-size
problem and dispatches to estr_tamanho_media() or
estr_tamanho_proporcao() depending on parametro, ignoring whichever
inputs are not needed.
estr_tamanho_amostra( parametro = c("media", "proporcao"), Nk, sigmak2 = NULL, pk = NULL, d, conf = 0.95, ck = NULL, alocacao = c("proporcional", "neyman", "custo", "nenhuma"), arredondar = c("cima", "proximo"), ... )estr_tamanho_amostra( parametro = c("media", "proporcao"), Nk, sigmak2 = NULL, pk = NULL, d, conf = 0.95, ck = NULL, alocacao = c("proporcional", "neyman", "custo", "nenhuma"), arredondar = c("cima", "proximo"), ... )
parametro |
Either |
Nk |
Numeric vector with the population size of each stratum. |
sigmak2 |
Numeric vector with the population variance of each stratum. |
pk |
Numeric vector with the population proportion of each stratum
(used only when |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
ck |
Optional numeric vector with the sampling cost per unit in each stratum. If supplied, the cost-based formula (Eq. 4.8) is used; otherwise the standard formula (Eq. 4.5) is used. |
alocacao |
How to allocate |
arredondar |
Either |
... |
Ignored. Any other variables from a broader problem statement may be passed here without causing an error. |
A sampling_result object, as produced by
estr_tamanho_media() or estr_tamanho_proporcao().
estr_tamanho_amostra(parametro = "media", Nk = c(1540, 770, 385), sigmak2 = c(7, 9, 11), d = 0.5)estr_tamanho_amostra(parametro = "media", Nk = c(1540, 770, 385), sigmak2 = c(7, 9, 11), d = 0.5)
Computes the total sample size and, when alocacao is not "nenhuma",
the per-stratum allocation, to estimate a population mean under
stratified sampling, dispatching automatically between the
proportional/Neyman formula (Eq. 4.5) and the cost-based formula
(Eq. 4.8) depending on whether ck is supplied. Extra arguments not
needed for the chosen formula are ignored.
estr_tamanho_media( Nk, sigmak2, d, conf = 0.95, ck = NULL, alocacao = c("proporcional", "neyman", "custo", "nenhuma"), arredondar = c("cima", "proximo"), ... )estr_tamanho_media( Nk, sigmak2, d, conf = 0.95, ck = NULL, alocacao = c("proporcional", "neyman", "custo", "nenhuma"), arredondar = c("cima", "proximo"), ... )
Nk |
Numeric vector with the population size of each stratum. |
sigmak2 |
Numeric vector with the population variance of each stratum. |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
ck |
Optional numeric vector with the sampling cost per unit in each stratum. If supplied, the cost-based formula (Eq. 4.8) is used; otherwise the standard formula (Eq. 4.5) is used. |
alocacao |
How to allocate |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the total sample size and,
unless alocacao = "nenhuma", the per-stratum allocation.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 5.
estr_tamanho_media(Nk = c(1540, 770, 385), sigmak2 = c(7, 9, 11), d = 0.5, conf = 0.95)estr_tamanho_media(Nk = c(1540, 770, 385), sigmak2 = c(7, 9, 11), d = 0.5, conf = 0.95)
Analogous to estr_tamanho_media() but for a population proportion,
using Eq. (4.12), with per-stratum proportions substituting for
variances (sigmak2 = pk*(1-pk)).
estr_tamanho_proporcao( Nk, pk, d, conf = 0.95, ck = NULL, alocacao = c("proporcional", "neyman", "custo", "nenhuma"), arredondar = c("cima", "proximo"), ... )estr_tamanho_proporcao( Nk, pk, d, conf = 0.95, ck = NULL, alocacao = c("proporcional", "neyman", "custo", "nenhuma"), arredondar = c("cima", "proximo"), ... )
Nk |
Numeric vector with the population size of each stratum. |
pk |
Numeric vector with the population proportion of each stratum. |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
ck |
Optional numeric vector with the sampling cost per unit in each stratum (Eq. 4.13). |
alocacao |
How to allocate |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the total sample size and,
unless alocacao = "nenhuma", the per-stratum allocation.
estr_tamanho_proporcao(Nk = c(1540, 770, 385), pk = c(0.75, 0.50, 0.25), d = 0.05)estr_tamanho_proporcao(Nk = c(1540, 770, 385), pk = c(0.75, 0.50, 0.25), d = 0.05)
Computes the population mean (Eq. 2.3) and,
when requested, the population variance (Eq. 2.5).
pop_media(x, ...)pop_media(x, ...)
x |
Numeric vector with the full population values. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the population mean and variance.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
pop_media(c(44, 45, 48, 42, 46))pop_media(c(44, 45, 48, 42, 46))
Computes the population proportion for a binary
(0/1) characteristic (Eq. 2.4) and its variance (Eq. 2.5.1).
pop_proporcao(x, ...)pop_proporcao(x, ...)
x |
Numeric or logical vector coded as 0/1 (or |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the population proportion.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
pop_proporcao(c(1, 0, 0, 1, 1))pop_proporcao(c(1, 0, 0, 1, 1))
Computes the population total
(course notes, Eq. 2.2).
pop_total(x, ...)pop_total(x, ...)
x |
Numeric vector with the full population values. |
... |
Ignored. Present so that extra, unrelated arguments can be passed without causing an error (see package overview). |
A sampling_result object with the population total.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley.
pop_total(c(1, 2, 3, 4, 5))pop_total(c(1, 2, 3, 4, 5))
Print method for sampling_result objects
## S3 method for class 'sampling_result' print(x, ...)## S3 method for class 'sampling_result' print(x, ...)
x |
A |
... |
Further arguments (unused, kept for S3 consistency). |
x, invisibly.
Estimates the population mean using the ratio estimator
(Eq. 7.36-7.38 of the course notes). Unlike razao_estima_R(), this
does not require knowing X (the population total of the auxiliary
variable) – only N.
razao_estima_media( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N, X = NULL, conf = 0.95, ... )razao_estima_media( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N, X = NULL, conf = 0.95, ... )
x, y
|
Optional raw numeric vectors (sample data). |
n, sum_x, sum_y, sum_x2, sum_y2, sum_xy
|
Optional pre-aggregated summary statistics, used when raw data are not available (e.g. a problem statement that only gives totals). |
N |
Population size. |
X |
Optional population total of the auxiliary variable; not
needed to compute the mean itself (only |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated mean, its
variance, and confidence interval.
x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_estima_media(x = x, y = y, N = 1500)x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_estima_media(x = x, y = y, N = 1500)
Estimates the population ratio R = Y/X (Eq. 7.27-7.30 of the course
notes) and its variance (Eq. 7.31), from either raw sample data
(x, y) or pre-aggregated sums – see .razao_resumo().
razao_estima_R( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N, X, conf = 0.95, ... )razao_estima_R( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N, X, conf = 0.95, ... )
x, y
|
Optional raw numeric vectors (sample data). |
n, sum_x, sum_y, sum_x2, sum_y2, sum_xy
|
Optional pre-aggregated summary statistics, used when raw data are not available (e.g. a problem statement that only gives totals). |
N |
Population size. |
X |
Population total of the auxiliary variable (used to derive
|
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated ratio, its
variance, and confidence interval.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 6.
x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_estima_R(x = x, y = y, N = 1500, X = 15000)x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_estima_R(x = x, y = y, N = 1500, X = 15000)
Estimates the population total using the ratio estimator (Eq. 7.33-7.35 of the course notes).
razao_estima_total( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N, X, conf = 0.95, ... )razao_estima_total( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N, X, conf = 0.95, ... )
x, y
|
Optional raw numeric vectors (sample data). |
n, sum_x, sum_y, sum_x2, sum_y2, sum_xy
|
Optional pre-aggregated summary statistics, used when raw data are not available (e.g. a problem statement that only gives totals). |
N |
Population size. |
X |
Population total of the auxiliary variable (used to derive
|
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the estimated total, its
variance, and confidence interval.
x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_estima_total(x = x, y = y, N = 1500, X = 15000)x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_estima_total(x = x, y = y, N = 1500, X = 15000)
Analogous to razao_tamanho_R() but for the population mean
(Eq. 7.44 of the course notes). Unlike razao_tamanho_R(), this does
not require X_barra.
razao_tamanho_media( sr2, N, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )razao_tamanho_media( sr2, N, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )
sr2 |
Variance of the ratio estimator (population value, or a
pilot-sample estimate from |
N |
Population size. |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required sample size.
razao_tamanho_media(sr2 = 2.2462, N = 1000, d = 0.75)razao_tamanho_media(sr2 = 2.2462, N = 1000, d = 0.75)
Computes the sample size needed to estimate the population ratio R
with a given margin of error (Eq. 7.41 of the course notes).
razao_tamanho_R( sr2, N, X_barra, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )razao_tamanho_R( sr2, N, X_barra, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )
sr2 |
Variance of the ratio estimator (population value, or a
pilot-sample estimate from |
N |
Population size. |
X_barra |
Population mean of the auxiliary variable ( |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required sample size.
razao_tamanho_R(sr2 = 7.7853, N = 1500, X_barra = 10, d = 0.05)razao_tamanho_R(sr2 = 7.7853, N = 1500, X_barra = 10, d = 0.05)
Analogous to razao_tamanho_R() but for the population total
(Eq. 7.43 of the course notes).
razao_tamanho_total( sr2, N, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )razao_tamanho_total( sr2, N, d, conf = 0.95, arredondar = c("cima", "proximo"), ... )
sr2 |
Variance of the ratio estimator (population value, or a
pilot-sample estimate from |
N |
Population size. |
d |
Tolerable margin of error. |
conf |
Confidence level, default |
arredondar |
Either |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the required sample size.
razao_tamanho_total(sr2 = 7.7853, N = 1500, d = 500)razao_tamanho_total(sr2 = 7.7853, N = 1500, d = 500)
Computes s_r^2, the pilot-sample estimate of the population variance
of the ratio estimator (Eq. 7.42 of the course notes), used as an input
to razao_tamanho_R(), razao_tamanho_total(), and
razao_tamanho_media() when no prior estimate of the variance is
available.
razao_variancia_piloto( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N = NULL, X = NULL, ... )razao_variancia_piloto( x = NULL, y = NULL, n = NULL, sum_x = NULL, sum_y = NULL, sum_x2 = NULL, sum_y2 = NULL, sum_xy = NULL, N = NULL, X = NULL, ... )
x, y
|
Optional raw numeric vectors (sample data). |
n, sum_x, sum_y, sum_x2, sum_y2, sum_xy
|
Optional pre-aggregated summary statistics, used when raw data are not available (e.g. a problem statement that only gives totals). |
N, X
|
Ignored (kept for signature symmetry with |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with s_r^2.
x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_variancia_piloto(x = x, y = y)x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) razao_variancia_piloto(x = x, y = y)
Convenience "umbrella" function that fits the regression model, tests whether the line passes through the origin, and computes both the ratio and the regression estimators of the population mean side by side, clearly flagging which one the origin test recommends – following the full workflow of Examples 7.1-7.2 of the course notes. This lets students and instructors compare both estimators even when only one is formally "correct" for the data at hand.
razao_vs_regressao_decidir(x, y, X_barra, N, conf = 0.95, ...)razao_vs_regressao_decidir(x, y, X_barra, N, conf = 0.95, ...)
x |
Numeric vector with the auxiliary variable. |
y |
Numeric vector with the variable of interest. |
X_barra |
Known population mean of the auxiliary variable
(required for the regression estimator; not required for the ratio
estimator, whose mean form only needs |
N |
Population size. |
conf |
Confidence level, default |
... |
Ignored. Any other variables from a broader problem statement may be passed here without causing an error. |
The function itself does not write anything to the console; print the returned object (or just type its name) to see a side-by-side summary.
An object of class razao_vs_regressao: a named list with
elements teste (from reg_teste_origem()), razao (from
razao_estima_media()), and regressao (from reg_estima_media()),
plus a recomendado character scalar. It has a print() method.
x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) res <- razao_vs_regressao_decidir(x, y, X_barra = 10, N = 1500) res$recomendado print(res)x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) res <- razao_vs_regressao_decidir(x, y, X_barra = 10, N = 1500) res$recomendado print(res)
Fits the simple linear regression of y on x by least squares
(Eqs. 7.9-7.10 of the course notes), and computes the residual
variance, the standard error of the intercept, and the t-statistic
used to test whether the line passes through the origin
(Eqs. 7.18-7.20) – the basis for deciding between the ratio and the
regression estimator (see reg_teste_origem()).
reg_ajustar(x, y, ...)reg_ajustar(x, y, ...)
x |
Numeric vector with the auxiliary variable. |
y |
Numeric vector with the variable of interest. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the fitted coefficients,
residual variance, and the intercept's standard error and
t-statistic.
Cochran, W.G. (1977). Sampling Techniques, 3rd ed. Wiley, cap. 7.
x <- c(39, 43, 21, 64, 57, 47, 28, 75, 34, 52) y <- c(65, 78, 52, 82, 92, 89, 73, 98, 56, 75) reg_ajustar(x, y)x <- c(39, 43, 21, 64, 57, 47, 28, 75, 34, 52) y <- c(65, 78, 52, 82, 92, 89, 73, 98, 56, 75) reg_ajustar(x, y)
Estimates the population mean using the regression estimator
(Eq. 7.22-7.25 of the course notes), which uses a known population
mean X_barra of an auxiliary variable correlated with y.
reg_estima_media(x, y, X_barra, N = NULL, conf = 0.95, ...)reg_estima_media(x, y, X_barra, N = NULL, conf = 0.95, ...)
x |
Numeric vector with the auxiliary variable. |
y |
Numeric vector with the variable of interest. |
X_barra |
Known population mean of the auxiliary variable. |
N |
Optional population size, used for the finite-population
correction |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the regression-estimated mean,
its variance, and confidence interval.
x <- c(39, 43, 21, 64, 57, 47, 28, 75, 34, 52) y <- c(65, 78, 52, 82, 92, 89, 73, 98, 56, 75) reg_estima_media(x, y, X_barra = 52, N = 486)x <- c(39, 43, 21, 64, 57, 47, 28, 75, 34, 52) y <- c(65, 78, 52, 82, 92, 89, 73, 98, 56, 75) reg_estima_media(x, y, X_barra = 52, N = 486)
Tests whether the regression line of y on x passes through the
origin (H0: a0 = 0), using both the t-statistic (Eq. 7.20) and the
confidence interval for a0 (Eq. 7.21), and recommends the ratio
estimator if the line passes through the origin (fails to reject
H0) or the regression estimator otherwise – following the logic of
Examples 7.1-7.2 of the course notes.
reg_teste_origem(x, y, conf = 0.95, ...)reg_teste_origem(x, y, conf = 0.95, ...)
x |
Numeric vector with the auxiliary variable. |
y |
Numeric vector with the variable of interest. |
conf |
Confidence level, default |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object stating the recommended estimator,
the test statistic, the confidence interval for a0, and both
estimators computed side by side for comparison.
x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) reg_teste_origem(x, y)x <- c(1, 30, 44, 20, 0, 10, 15, 5, 2, 50, 35, 25) y <- c(2, 35, 50, 27, 1, 15, 17, 7, 0, 53, 35, 30) reg_teste_origem(x, y)
Computes the sampling interval k = N/n used to select a systematic
sample, following Section 5.1-5.2 of the course notes. When N/n is
not an integer, k is first rounded up; if k*n > N, k is then
decremented by 1, and the correction constant k* = N - k*n is
computed (Example 5.2 of the course notes).
sist_intervalo(N, n, ...)sist_intervalo(N, n, ...)
N |
Population size. |
n |
Desired sample size. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the sampling interval (and,
when N/n is not an integer, the correction constant k* needed by
sist_selecionar_amostra()).
sist_intervalo(N = 2000, n = 80) sist_intervalo(N = 2000, n = 75)sist_intervalo(N = 2000, n = 80) sist_intervalo(N = 2000, n = 75)
Selects a systematic sample of size n from a population of size N,
handling both the integer-interval case and the non-integer-interval
case (with the correction constant k*), following the selection
rules of Section 5.2 of the course notes (Examples 5.1-5.2). In the
non-integer case, the first selected element is r; from the second
element onward, k* is added on top of the regular step k
(i.e. element i for i >= 2 equals (i-1)*k + k* plus r), exactly as
illustrated in Example 5.2.
sist_selecionar_amostra(N, n, r = NULL, semente = NULL, ...)sist_selecionar_amostra(N, n, r = NULL, semente = NULL, ...)
N |
Population size. |
n |
Desired sample size. |
r |
Optional random start (an integer between 1 and |
semente |
Optional integer seed for reproducibility. The user's global random state is saved and restored, so calling this function does not affect subsequent unrelated random draws. |
... |
Ignored (see package overview on tolerated extra arguments). |
A sampling_result object with the selected element positions
(1:N).
sist_selecionar_amostra(N = 2000, n = 80, r = 8) sist_selecionar_amostra(N = 2000, n = 75, r = 26)sist_selecionar_amostra(N = 2000, n = 80, r = 8) sist_selecionar_amostra(N = 2000, n = 75, r = 26)
Prints the print method output plus the full step-by-step calculation trace and bibliographic references.
## S3 method for class 'sampling_result' summary(object, ...)## S3 method for class 'sampling_result' summary(object, ...)
object |
A |
... |
Further arguments (unused, kept for S3 consistency). |
object, invisibly.