sample_finite_population: Sample from finite population with known number of true...

Description Usage Arguments Details Value See Also Examples

View source: R/finite_pop_sampling.R

Description

Sample from finite population with known number of true positives

Usage

1
sample_finite_population(n, N, p = NULL, npositive = NULL, replicates = 1)

Arguments

n

sample size

N

Population size

p

positive probability (e.g. of being an LHN)

npositive

Number of true positives (e.g. actual number LHNs in a tract)

replicates

Number of samples to draw

Details

Imagine we have integers 1:N (the population size). We say that the first npositive integers are the true positives in the population (npositive may be 0).

Now we draw a sample of size n from the integers 1:N. For this sample we say that the observed positives are those integers <=npositive.

NB this is the hypergeometric distribution.

Value

A vector of length replicates with counts of sample positives.

See Also

truepos_given_sample for estimating the true number of positives in a finite population given a sample.

Other population-sampling: prop.ci, required.sample.size, truepos_given_sample

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Draw a random sample of size 24 tracings for a population of 96 profiles in
# a tract known to have 36 LHNs
sample_finite_population(24, N=96, npositive=36)
# Draw 1000 random samples, plot the distribution of observed sample positives
rand.samples=sample_finite_population(24, N=96, npositive=36, replicates=1000)
mean(rand.samples)
quants=quantile(rand.samples, c(0.05,0.95))

library(ggplot2)
qplot(rand.samples, binwidth=1, xlab='Observed Sample Positives') +
  geom_vline(xintercept = quants, colour='red')



# Compare with binomial distribution
resdf=data.frame(x=popsample(10,50,p=.5, replicates = 100000), type='popsample')
resdf=rbind(resdf, data.frame(x=rbinom(100000, size=10,p=.5), type='rbinom'))
library(ggplot2)
qplot(x, col=type, data=resdf, geom='density')

sfrechter/physplit.analysis documentation built on May 29, 2019, 8:02 p.m.