Last data update: 2014.03.03

R: Required Sample Size
nsizeR Documentation

Required Sample Size

Description

Function to determine required sample size to be within a given margin of error.

Usage

nsize(b, sigma = NULL, p = 0.5, conf.level = 0.95, type = "mu")

Arguments

b

the desired bound.

sigma

population standard deviation. Not required if using type "pi".

p

estimate for the population proportion of successes. Not required if using type "mu".

conf.level

confidence level for the problem, restricted to lie between zero and one.

type

character string, one of "mu" or "pi", or just the initial letter of each, indicating the appropriate parameter. Default value is "mu".

Details

Answer is based on a normal approximation when using type "pi".

Value

Returns required sample size.

Author(s)

Alan T. Arnholt

Examples

nsize(b=.03, p=708/1200, conf.level=.90, type="pi")
    # Returns the required sample size (n) to estimate the population 
    # proportion of successes with a 0.9 confidence interval 
    # so that the margin of error is no more than 0.03 when the
    # estimate of the population propotion of successes is 708/1200.
    # This is problem 5.38 on page 257 of Kitchen's BSDA.
    
nsize(b=.15, sigma=.31, conf.level=.90, type="mu")
    # Returns the required sample size (n) to estimate the population 
    # mean with a 0.9 confidence interval so that the margin 
    # of error is no more than 0.15.  This is Example 5.17 on page
    # 261 of Kitchen's BSDA.

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BSDA)
Loading required package: e1071
Loading required package: lattice

Attaching package: 'BSDA'

The following object is masked from 'package:datasets':

    Orange

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BSDA/nsize.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nsize
> ### Title: Required Sample Size
> ### Aliases: nsize
> ### Keywords: univar
> 
> ### ** Examples
> 
> nsize(b=.03, p=708/1200, conf.level=.90, type="pi")

The required sample size (n) to estimate the population 
proportion of successes with a 0.9 confidence interval 
so that the margin of error is no more than 0.03 is 728 . 


>     # Returns the required sample size (n) to estimate the population 
>     # proportion of successes with a 0.9 confidence interval 
>     # so that the margin of error is no more than 0.03 when the
>     # estimate of the population propotion of successes is 708/1200.
>     # This is problem 5.38 on page 257 of Kitchen's BSDA.
>     
> nsize(b=.15, sigma=.31, conf.level=.90, type="mu")

The required sample size (n) to estimate the population 
mean with a 0.9 confidence interval so that the margin 
of error is no more than 0.15 is 12 . 


>     # Returns the required sample size (n) to estimate the population 
>     # mean with a 0.9 confidence interval so that the margin 
>     # of error is no more than 0.15.  This is Example 5.17 on page
>     # 261 of Kitchen's BSDA.
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>