46
Chapter 11 Inference for a single probability 11.1 Review In a single population, π is the probability of an event such as heads on a coin toss, or some other measure of success. It may also be thought of as the population proportion, such as the proportion of smokers in Canada, and hence as the probability of selecting a smoker at random from the population of Canada. We use a mathematical model to allow us to mimic the selection of a ran- dom sample from the population. Mathematically we tale about repeatedly sampling a Random variable. The random variable, takes on a value, X = 1, when there is a success, for example, a head when a coin is tossed, or the selection of a smoker, as opposed to X = 0 when there is NOT a success, that is, a tail or the selection of a non-smoker. In a sample of size n, there is a sample mean, ¯ x = x i n . For binary data, it is also called the sample proportion p ( or ˆ π). Each of the X I random variables has a Bernoulli distribution, and we know that the sum of n Bernoullis, X (= X i ), measures the number of successes in n ”trials”, and has a binomial distribution. The pdf is n x π x (1 π) n-x 1

Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

Chapter 11

Inference for a singleprobability

11.1 Review

In a single population, π is the probability of an event such as heads on acoin toss, or some other measure of success. It may also be thought of asthe population proportion, such as the proportion of smokers in Canada, andhence as the probability of selecting a smoker at random from the populationof Canada.

We use a mathematical model to allow us to mimic the selection of a ran-dom sample from the population. Mathematically we tale about repeatedlysampling a Random variable. The random variable, takes on a value, X = 1,when there is a success, for example, a head when a coin is tossed, or theselection of a smoker, as opposed to X = 0 when there is NOT a success,that is, a tail or the selection of a non-smoker.

In a sample of size n, there is a sample mean, x̄ =∑

xi

n. For binary data,

it is also called the sample proportion p ( or π̂).Each of the XI random variables has a Bernoulli distribution, and we

know that the sum of n Bernoullis, X(=∑

Xi), measures the number ofsuccesses in n ”trials”, and has a binomial distribution.

The pdf is

(

n

x

)

πx(1− π)n−x

1

Page 2: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

2 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

For example, for π = 0.2, n = 10, we have

(

10

x

)

0.2x0.810−x

Page 3: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.1. REVIEW 3

To get this pdf, we can use the SAS function PDF

Here is the pdf of B(10,0.2)

0.15

0.10

0.00

0.20

0.05

8 9765430 1 2 10

Probability

0.25

0.30

It can be seen clearly that this is an asymmetric distribution

Page 4: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

4 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.2 inference - hypothesis test

We wish to test an hypothesis about probability in a single populationHo : π = πo

againstHA : π > πo

with α = 0.05

ExampleFor 36 students, 9 are smokers, that is, n = 36, p = 0.25.

Statistics Canada says that, for the age group under consideration, 20% ofpeople smoke.Hence, at α = 0.05, we wish to testHo : π = 0.20againstHA : π > 0.20

11.2.1 computation

11.2.1.1 exact computation

For the binomial distribution

p-value = PR(p ≥ 0.25|π = 0.20)

= Pr(XB ≥ 9|π = 0.20)

= 1− Pr(XB ≤ 8|π = 0.20)

= 1−8∑

x=0

(

36

x

)

0.20x0.8036−x

Page 5: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.2. INFERENCE - HYPOTHESIS TEST 5

To compute this, we need a SAS program

title "calculate binomial probability ";

options ps=24 ls=64;

data binom4;

prob = cdf("binomial", 8, 0.2, 36);

pvalue = 1 - prob;

output binom4;

proc print data=binom4;

Here is the output of that program

calculate binomial probability

Obs prob pvalue

1 0.71588 0.28412

11.2.1.2 Normal approximation to Binomial Mean

Recall that p is sample mean so that, for large n, the CLT holdsMoreover, for the mean we have

E(P ) = E(X̄B)

= E

(

XB

n

)

=1

nE(XB)

=1

n(nπ) = π

and for the variance

V ar(P ) = V ar

(

XB

n

)

=1

n2V ar(XB)

=1

n2nπ(1− π)

=π(1− π)

n

Page 6: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

6 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

Example (continued)For the hypotheses test, we use πo

As for the use of the Normal approximation for a binomial, we need to check

1. nπo ≥ 5

2. n(1− πo) ≥ 5

Hence for out example:

1. nπo = 36(0.2) = 7.2,

2. n(1− πo) = 36(0.8) = 28.8

Since both criteria are met, the sample should be large enough for a Normalapproximation to be used(but there are two possible approximations).

11.2.1.3 Simple normal approximation

p-value = Pr(p > 0.25|π = 0.20)

= Pr

ZN >0.25− 0.20√

0.2(0.8)36

= Pr

(

ZN >0.05√

0.004444

)

= Pr

(

ZN >0.05

0.0667

)

= Pr(ZN > 0.75)

= z(0.75)

= 0.2266

This is smaller than exact computation. This is too liberal (optimistic) inthat it leads to more Type I error, that is, it rejects Ho more often than 5%of the time.

Page 7: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.2. INFERENCE - HYPOTHESIS TEST 7

11.2.1.4 Better Normal approximation

This approach uses a continuity correction of 12n. This factor arises from the

approximation of a continuous distribution to a discrete distribution. Thediscrete distribution of the sample proportion, P:

1. has n+ 1 possible values, {0, 1n, 2n, ..., 1}

2. has a distance of 1nbetween the possible values

3. the approximating normal distribution starts half-way between twoconsecutive points in the discrete distribution, that is , 1

2nfrom each of

two consecutive points of the discrete

Continuing, we have

p-value = Pr(p > 0.25|π = 0.20)

= Pr

(

ZN >0.05− 1/72√

0.004444

)

= Pr

(

ZN >0.05− 0.0139

0.0667

)

= Pr

(

ZN >0.0361

0.0667

)

= Pr(ZN > 0.542)

= z(0.542)

= 0.2939( by linear interpolation)

This is conservative (larger p-value than exact)We reject less often than 0.05, and thus make fewer type I errors

Page 8: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

8 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.2.2 Example with smaller sample size

Consider a sample of size 10, with 3 smokers. We use the same null andalternative hypotheses as in the previous example.

We can calculate the exact p-value:

prob = cdf("binomial", 2, 0.2, 10);

pvalue = 1 - prob;

calculate binomial probability

Obs prob pvalue

1 0.67780 0.32220

11.2.2.1 Normal approximation

This uses the continuity correction

p− value = Pr(p > 3/10|π = 0.20)

=

Pr(ZN >(0.30− 0.20)− 1/2n

0.2(0.8)10

= Pr

(

ZN >0.10− 1/20√

0.016

)

= Pr

(

ZN >0.10− 0.05

0.12649

)

= Pr

(

ZN >0.05

0.12649

)

= Pr(ZN > 0.395)

= z(.395)

= 0.3465 (by linear interpolation)

This is again conservative, but it is not a bad approximation for such a smallsample size.

Page 9: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.2. INFERENCE - HYPOTHESIS TEST 9

11.2.3 P-values with SAS

SAS can also be used to provide Normal approximations; here is a SASprogram that does these calculations:

title "pvalue 1-sided test binom ";

title2 "exact and two approximations";

data binom;

input n x pi;

p = x/n;

num = p - pi;

numcc = p - pi - 1/(2*n);

den = (pi*(1-pi))/n;

sqden = sqrt(den);

zobs = num/sqden;

zobscc=numcc/sqden;

po = probnorm(-zobs);

pocc = probnorm(-zobscc);

xb= x-1;

prob = cdf(’binomial’,xb , pi, n);

pvalue = 1 - prob;

datalines;

36 9 0.2

10 3 0.2

;

proc print data=binom;

quit;

Page 10: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

10 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

Here is the output, using both examples from this section

pvalue 1-sided test binom

exact and two approximations

Obs n x pi p num numcc den sqden zobs

1 36 9 0.2 0.25 0.05 0.036111 0.004444 0.06667 0.75000

2 10 3 0.2 0.30 0.10 0.050000 0.016000 0.12649 0.79057

Obs zobscc po pocc xb prob pvalue

1 0.54167 0.22663 0.29402 8 0.71588 0.28412

2 0.39528 0.21460 0.34632 2 0.67780 0.32220

Page 11: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 11

11.3 Confidence intervals

For confidence intervals, we need an point estimator of the parameter andits variance.

1. we have an estimatorπ̂ = p

2. it has the right expected value

E(P ) = E

(

X

n

)

=1

nE(X)

=1

nnπ

= π

3. we have its variance

V ar(X) =π(1− π)

n

which is estimated by

p(1− p)

n

Note: this is different from the variance used in the hypothesis test wherewe use

πo(1− πo)

n

Page 12: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

12 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

BIG PROBLEM:

1. variance is a function of mean

2. we will be using a continuous interval to estimate a parameter whichdescribes a discrete distribution

3. distribution of estimator (P ) is asymmetric

Because of this, there are many ways of calculating a confidence intervalhave to decide which is the best one (use statistical evaluation)

simple confidence interval

p± zα/2

p(1− p)

n

simple confidence interval with continuity correction

p±(

1

2n+ zα/2

p(1− p)

n

)

These are called Wald tests after Abraham Wald (1943)”Tests of Statistical Hypotheses Concerning Several Parameters When theNumber of Observations is Large”Transactions of the American Mathematical Society 54, 426-482.

Page 13: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 13

11.3.1 symmetric confidence intervals - example

for the sample of 36 students, 9 are smokers95% confidence interval given by

0.25± 1.96

0.25(0.75

36= 0.25± 1.96(0.072)

= 0.25± 0.141

that is (0.109, 0.391)Try continuity correction

0.25±(

1

72+ 1.96

0.25(0.75

36

)

= 0.25± (0.0139 + 0.141)

= 0.25± 0.155

that is (0.095,0.405)

How well do these methods perform

1. may be ok for large samplesbut are symmetric, and, particularly for small samples, the binomialdistribution is quite non-symmetric

2. Vollset (1993), Newcombe (1998), and Agresti and Coull (1998)showed that these intervals do not provide ”advertised” confidence. Onaverage the coverage (observed confidence) is too low; For example, wemay only have 90% confidence instead of 95%

Page 14: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

14 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.3.2 other methods for confidence intervals

1. exact (Clopper-Pearson)Because of discreteness of the binomial, this method is very conservativeexcept for those few points where it is exact;

2. score interval (Wilson)This is asymmetric and very excellent coverage (observed confidence),but it is difficult to compute

3. adjusted Wald (Agresti and Coulls)This is also asymmetric and has good coverage, and it is simple tocalculate

Page 15: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 15

11.3.2.1 Wilson/Score confidence interval

The development of this method is quite complicated, but it reduces to thefollowing.

Consider the hypothesis test with the critical value of distribution

p− π√

π(1− π)

= zα/2

now solve for π

(p− π)2 = z2π(1− π)

n

n(p− π)2 = z2π(1− π)

nπ2 − 2npπ + np2 = z2π − z2π2

collecting like terms in π

(n+ z2)π2 − (2np+ z2)π + np2 = 0

for quadratic ax2 + bx+ c = 0, the solution for x is

−b±√b2 − 4ac

2a

so solution is

2np+ z2 ±√

(2np+ z2)2 − 4(n+ z2)np2

2(n+ z2)

Page 16: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

16 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

The term under square root sign becomes

z4 + 4npz2 + 4n2p2 − 4n2p2 − 4np2z2

= z4 + 4nz2p(1− p)

so solutions for π are

2np+ z2 ± z√

z2 + 4np(1− p)

2(n+ z2)

divide through by 2n to get

(

p+z2

2n± z

p(1− p)

n+

z2

4n2

)

/(1 + z2/n)

The WIlson/Score confidence interval is given by:

(

p+z2

2n± z

p(1− p)

n+

z2

4n2

)

/(1 + z2/n)

which is symmetric about

p+z2(1− 2p)

2(n+ z2)

where z = zα/2, which is, usually, 1.96.

Page 17: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 17

Example

=0.25 + 1.962

72± 1.96

0.25(0.75)36

+ 1.962

4(362)

1 + 1.962

36

=0.25 + 0.05335± 1.96

√0.005208 + 0.00074

1 + 0.10671

=0.30335± 1.96

√0.005282

1.10671

=0.30335± 0.15118

1.10671

= (0.1375, 0.4107)

asymmetric around

0.25 +1.962(1− 0.5)

2(36 + 1.962)= 0.25 + 0.0241 = 0.2741.

Page 18: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

18 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.3.2.2 Deriving the adjusted Wald

This is a simplified version of the Wilson/Score methodMultiply numerator and denominator by n to get

(

x+z2

2± z

np(1− p) +z2

4

)

/(n+ z2)

Since z is approximately 2, then z2 is approximately 4, so the expressionbecomes

(

x+ 2± z√

np(1− p) + 1)

/(n+ 4)

≈(

x+ 2

n+ 4± z

p(1− p)

n+ 4

)

This is not based onx

n

but rather onx+ 2

n+ 4

For example, the confidence interval is based on

11

40= 0.275

which gives

0.275± 1.96

0.275(0.725)

40

= 0.275± 0.138

which is (0.137,0.413), slightly wider than the Wilson

Page 19: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 19

Example 2Again, consider the study with 10 students of whom 3 smoke

1. the simple Wald 95% confidence interval is given by

0.30± 1.96

(3/10)(7/10)

10= 0.30± 1.96(0.1449)

= 0.30± 0.2840

= (0.0160, 0.5840)

2. the continuity-corrected Wald interval is given by

0.30±(

1

20+ 1.96

(3/10)(7/10)

10

)

= 0.30± (0.05 + 0.2804)

= 0.30± 0.3340

= (0.0000, 0.6340)

Page 20: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

20 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

3. the Wilson-Score interval is given by

(

p+z2

2n± z

p(1− p)

n+

z2

4n2

)

/(1 + z2/n)

=0.30 + 1.962

20± 1.96

0.30(0.70)10

+ 1.962

4(102)

1 + 1.962

10

=0.30 + 0.19208± 1.96

√0.021 + 0.009604

1 + 0.38416

=0.49208± 1.96

√0.030604

1.38416

=0.49208± 1.96(0.17494)

1.38416

=0.49208± 0.34238

1.38416= (0.14920/1.38416, 0.83496/1.38416)

= (0.10779, 0.60323)

This is symmetric about 0.492081.38416

= 0.35551, not about p = 310

= 0.30

4. the adjusted Wald The confidence interval is based on

5

14= 0.35714

which gives

0.35714± 1.96

0.35714(0.64286)

14= 0.35714± 1.96(0.1280)

which is (0.1061,0.6081)This is symmetric about 0.35714, not 0.30

Page 21: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 21

numerical summary for example 1

large sampleMethod 95% CIWald (0.109,0.391)

Wald with CC (0.095,0.405)Wilson (0.137,0.411)

Adjusted Wald (0.137,0.413)

numerical summary sample 2

small sampleMethod 95% CIWald (0.0160,0.5840)

Wald with CC (0.000,0.6340)Wilson (0.1078,0.6032)

Adjusted Wald (0.1061,0.6081)

SummaryThe Wilson and Adjusted Wald intervals

1. are symmetric about some valuewhich is not p = x

n

2. are narrower than Wald and Wald with CC(when latter allowed to include negative values)

3. never include negative values

4. provide excellent coverage (observed confidence)particularly for small values of π

Page 22: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

22 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.3.3 SAS program for CIs

title "calculate CI for single probability ";

options ps=24 ls=64;

data ci1;

input n x alpha;

p = x/n;

cc = 1/(2*n);

var = p*(1-p)/n;

se = sqrt(var);

za=probit(1-alpha/2);

waldl=p-za*se;

waldu=p+za*se;

waldccl=waldl-cc;

waldccu=waldu+cc;

pwa=(x+2)/(n+4);

sewa = sqrt(pwa*(1-pwa)/(n+4));

waldal=pwa-za*sewa;

waldau=pwa+za*sewa;

adj = (za*za)/(2*n);

num1 = p + adj;

badj = adj/(2*n);

c = var+badj; d=sqrt(c);

num2 = za*d;

den = 1+2*adj;

scl = (num1-num2)/den;

scu = (num1+num2)/den;

datalines;

36 9 0.05

9 2 0.05

;

proc print data=ci1;

Page 23: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.3. CONFIDENCE INTERVALS 23

SAS program output

calculate CI for single probability

Obs n x alpha p cc var se za

1 36 9 0.05 0.25 0.013889 0.005208 0.07217 1.95996

2 10 3 0.05 0.30 0.050000 0.021000 0.14491 1.95996

Obs waldl waldu waldccl waldccu pwa sewa

1 0.10855 0.39145 0.094663 0.40534 0.27500 0.07060

2 0.01597 0.58403 -0.034026 0.63403 0.35714 0.12806

Obs waldal waldau adj num1 badj c

1 0.13663 0.41337 0.05335 0.30335 .000741022 0.005949

2 0.10615 0.60814 0.19207 0.49207 .009603647 0.030604

Obs d num2 den scl scu

1 0.07713 0.15118 1.10671 0.13750 0.41070

2 0.17494 0.34287 1.38415 0.10779 0.60322

Page 24: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

24 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.4 Sample size and Power

When planning a study, we require a sample size that assures (with prede-termined probability) that our study will be successful. There are two waysof doing this, one using Margin of Error (E) and one using Effect Size (ES).

However, it may be that we have a sample already, and, given the sam-ple size, we want to determine what power we have to find a probability(proportion) of interest.

The type of computation is based on what we want to report about thestudy.

1. margin of error - EWe will give a confidence interval, (a,b), saying that we are 95% confi-dent that the true value of the parameter is in that interval;

2. power of a test of hypothesisWe will conduct a test of hypothesis and reach a conclusion such thatwe have a power (1− β) of reaching a correct conclusion.

3. effect sizeWe will do a test of hypothesis with a prespecified probability (power)of finding a proportion (probability) of interest

11.4.1 Margin of error

The margin or error, denoted by E, is the maximum amount of error inour interval (with 95% confidence). In other words, the true value is withinthe interval (a,b)(with 95% confidence) but no more than E units from aboundary; it is within E units of a or b.

If we have a symmetric confidence interval, then a true value in the half-interval (a,m) (where m is the middle of the interval) is within E units of a,and a true value in the half-interval (m,b) is within E units of b. If w is thehalf-width of the interval (=(m-a) = (b-m)), then E=w. In this sense, E, themargin of error, is a measure of precision.

Page 25: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.4. SAMPLE SIZE AND POWER 25

Since the symmetric interval is of the form

p± zα/2

p(1− p)

n

then half the interval width, w (=E), is

zα/2

p(1− p)

n

Solve for n to get

n = π(1− π)(z(α/2)

E

)2

where E is the margin of error.Since π is usually unknown, we use π = 0.5 which gives a maximum value toπ(1− π), namely 0.25, so formula becomes

n =1

4

(z(α/2)E

)2

(1)

Under the simplifying assumption that

zα/2 = 2

this becomes

n =

(

1

E

)2

(2)

which is slightly conservative, ie, too large.

Page 26: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

26 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

Sample size - margin of error - example

Assume α = 0.05, and, as argued above, π = 0.5.We want to estimate proportion (prevalence) of smokersto within 10%, hence E = .10.

n = 0.5(0.5)

(

1.96

.10

)2

= 0.25(384.16) = 96.04

that is 97(essentially 100)for E = 0.05 (width of 0.10), n is almost 400.

For the simplified formula (2), the results are 100 and 400, respectively.

Page 27: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.4. SAMPLE SIZE AND POWER 27

11.4.2 Power

We are interested in the difference in probability, δπ = πA−πo, where πo is theprobability (proportion) under the null hypothesis and πA is the probability(proportion) under the alternative hypothesis.

Since the variance depends on the mean, for this calculation we have tospecify πo and πA

Because the variance is different under the two hypotheses, we cannotuse the formula for a single population that we used previously, but have toderive a new formula.

The rule for rejecting a null hypothesis about a probability (proportion)looks like this:if p > πo + zα/2σpo , then reject Ho.where

σpo =√

πo(1−πo)n

The probability of this happening, that is, the power of this rule, is theprobability of rejecting the null for a specific value of the alternative hypoth-esis, that is,

Pr(P > πo + zα/2σpo |π = πA)

Next we standardize to get

Pr

(

ZN >(πo − πA) + zα/2σpo

σpA

)

where σpA =√

πA(1−πA)n

This can be written as

Pr

(

ZN >−|πo − πA|+ zα/2σpo

σpA

)

which allows for alternatives less than πo,

It simplifies to

Pr

(

ZN >zα/2σpo − |πo − πA|

σpA

)

(3)

Page 28: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

28 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

This may also be written as

Pr

(

ZN >zα/2σo −

√n|πo − πA|

σA

)

(4)

where σo =√

πo(1− πo) and σA =√

πA(1− πA)

Example of calculation of power for proportionUsually α = 0.05, so that zα/2 = z0.025 = 1.960

The usual success rate in treatment of a disease is 50%. In a new clinicaltrial on 9 subjects, what power do we have of finding a new rate of 60%.

Mathematically, this may be stated asπo = 0.5 and πA = 0.60, δπ = 0.10 = ES

Next we calculate thatσo =

πo(1− πo) =√

0.5(0.5) = 0.5

andσA =

πA(1− πA) =√

0.4(0.6) =√0.24 = 0.490

Plugging these figures into equation (4) above, we get

Pr

(

ZN >1.96(0.5)−

√9(0.10)

0.490

)

= Pr

(

ZN >0.98− 0.3

0.490

)

= z(1.388) = 0.0826

Hence the chance of finding a difference of 0.0 with a sample of size 9 is about8%. We need more subjects; this will be discussed in the next section.

Page 29: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.4. SAMPLE SIZE AND POWER 29

Simplified version of formula

If we assume that σo = σA = 0.5, then (4) becomes

Pr(ZN > zα/2 − 2|πo − πA|√n)(5)

which, for our example, is

Pr(ZN > 1.96− 2|(0.1)|√9)

= Pr(ZN > 1.96− 0.6) = Pr(ZN > 1.36) = z(1.36) = 0.0869

which is slightly larger than the using formula (5).

This formula is optimistic, and should not be used except when both πo

and πA are close to 0.5.

Page 30: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

30 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.4.3 Sample size for a single proportion

The sample size is obtained by taking equation (4) above, and solving for n.

First we insert the term for power, 1− β

1− β = Pr

(

ZN >+zα/2σo −

√n|πo − πA|

σA

)

The probability is merely the calculation of z(1−β), which means that

z(1−β) =zα/2σo −

√n|πo − πA|

σA

From a previous argument, we know that z(1−β) = −zβ, which can besubstituted into the equation which becomes

−zβ =zα/2σo −

√n|πo − πA|

σA

Multiplication of both sides by σA gives

−zβσA = zα/2σo −√n|πo − πA|

Adding zβσA to both sides gives

0 = zα/2σo + zβσA −√n|πo − πA|

Adding√n|πo − πA| to both sides yields

√n|πo − πA| = zα/2σo + zβσA

Dividing both sides by |πo − πA| produces√n =

zα/2σo + zβσA

|πo − πA|Squaring both sides gives

n =

(

zα/2σo + zβσA

|πo − πA|

)2

(6)

where σo =√

πo(1− πo) and σA =√

πA(1− πA)

Page 31: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.4. SAMPLE SIZE AND POWER 31

A simplifying assumption is that

σo = σA = 0.5

under which (6) becomes

n =

(

zα/2 + zβ2|πo − πA|

)2

(7)

This is conservative, but should not be used unless both πo and πA are closeto 0.5; otherwise, it will grossly exaggerate the required sample size.

Example of sample size calculation

Usually, the required power is 80% so that zβ = z(0.20) = 0.842For the same clinical trial, where we wish to show a proportion of 0.6

(πA) where the usual result is 0.5 (πo), we have σA = 0.490 and σo = 0.5.Moreover ES, the effect size,is δπ = 0.6− 0.5 = 0.1

Substituting into the preceding equation, we get

n =

(

zα/2σo + zβσA

|πo − πA|

)2

=

(

1.96(0.5) + 0.842(0.490)

0.1

)2

=

(

0.98 + 0.412

0.1

)2

= 13.9252 = 193.9

Hence 194 subjects are required (close enough to 200)

Using formula (7), we get

n =

(

1.960 + 0.842

2(0.1)

)2

=

(

2.802

0.2

)2

= 196.28

Hence 197 subjects.

Page 32: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

32 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.5 Goodness of fit chi-square

This is used with categorical(polychotomous) data.Let us say there are k categories, and, in each category, we have xi observa-tions, i = 1, ..., k

When, k = 2, this is binary (dichotomous) data, but the analyses lookdifferent from what has been done earlier in this chapter; however, they willbe shown to be equivalent (as far as tests of hypothesis are concerned)

Here are some examples:

• toss coink = 220 tosses, 8 heads (x1), 12 tails (x2)is the coin fair?

• random sample of 20 graduate students8 males (x1), 12 females (x2)supposedly 70% of Western grad students are femaleDoes this seem to be a random sample of that population?

• Of 36 graduate students, selected at random9 are smokers and 27 are notStatistics Canada says that 20% of young people smoke.Do the results for this sample agree with that?

• Of the 20 graduate students, 12 are from Ontario, 4 from Canada out-side Ontario and 4 from outside Canadak = 3supposedly the population figures for Western are 70% Ontario, 20%Canadian outside Ontario, and 10% from outside CanadaIs this sample representative of the population?

Page 33: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.5. GOODNESS OF FIT CHI-SQUARE 33

11.5.1 Test of hypothesis

Assume that the distribution is binomialWe have 8 heads from 20 trials

Ho : π = 0.5

HA : π 6= 0.5

p-value = Pr(XB ≤ 8|π = 0.5)

+Pr(XB ≥ 12|π = 0.5)

= 2Pr(XB ≤ 8|π = 0.5)

(under the null hypothesis, the distribution is symmetric, so we can use onetail of the distribution to compute the probabilities for both tails)

Use SAS program to calculate p-value = 0.5034

Page 34: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

34 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.5.1.1 An approximate test

This is the goodness of fit test, so called, because it answers the questionhow well does data fit a theoretical distribution when π = πo?

Note: It can only be used to test against a two-sided alternative

HA : π 6= πo

This test consists of a calculation of the observed values, and their expectedvalues under the null hypothesis.

Oi observed : xi

Ei expected : under Ho

In this caseO1 = 8, E1 = 10O2 = 12, E2 = 10

S =k∑

i−1

(Oi − Ei)2

Ei

=(8− 10)2

10+

(12− 10)2

10

=4

10+

4

10= 0.8

under Ho, S ∼ χ2k−1

In this case, S ∼ χ21 so that, pvalue = Pr(χ2

1 > 0.8) > 0.10at α = 0.05, we fail to reject Ho.

Page 35: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.5. GOODNESS OF FIT CHI-SQUARE 35

11.5.1.2 More accurate calculation

Mathematically, it can be shown that the

χ21 ∼ (ZN)

2

which in this case means

Pr(χ21 > 0.8) = 2Pr(ZN >

√0.8)

= 2Pr(ZN > 0.8944)

= 2z0.8944

= 2[0.1841 + (.56)(0.1867− 0.1841] linear interpolation

= 2(0.185556)

= 0.3711

11.5.1.3 Better approximate test

Again we use the χ2 approximation to the binomial, but employ a continuitycorrection in calculating the test statistic

S =2∑

i=1

(|Oi − Ei| − 0.5)2

Ei

=(|8− 10| − 0.5)2

10+

(|12− 10| − 0.5)2

10

=2.25

10+

2.25

10= 0.45

Page 36: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

36 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

Pr(χ21 > 0.45) = 2Pr(ZN >

√0.45)

= 2Pr(ZN > 0.6708)

= 2z0.6708

= 2[0.92(9, 2514) + 0.08(0.2483)]liner interpolation

= 2(0.25115)

= 0.5023

This is a pretty good approximation to the exact value

The conditions under which this will be a good approximation are:

1. nπo = 20(0.5) = 10 > 5

2. n(1− πo) = 20(0.5) = 10 > 5

3. Oi > 5, i = 1, ..., k

Page 37: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.5. GOODNESS OF FIT CHI-SQUARE 37

11.5.2 More examples

11.5.2.1 Example 2

Here we have the same observations, O1 = 8, O2 = 12that is, 8 heads and 12 tails but we different Ei because we how believethat the coin is unfair (biased) with probability 0.3 of getting a head on aparticular tossthat is

Ho : π = 0.3

against the alternativeHA : π 6= 0.3

so that E1 = 20(0.3) = 6, E2 = 20(0.7) = 14

S =2∑

i=1

(|Oi − Ei| − 0.5)2

Ei

=(|8− 6| − 0.5)2

6+

(|12− 14| − 0.5)2

14

=2.25

6+

2.25

14= 0.5357

so that p-value= 2Pr(ZN > 0.7319) = 2(0.2321) = 0.4642

and, at α = 0.05, we fail to reject the null

Page 38: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

38 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.5.2.2 example 3

For our 36 students, we have 9 smokers, and 27 non-smokersO1 = 9, O2 = 27.

Based on Statistics Canada surveys, for this age group, 30% of people smoke.Hence the hypothesis

Ho : π = 0.3

against the alternativeHA : π 6= 0.3

which means

E1 = 36(0.2) = 7.2, E2 = 36(0.8) = 28.8

The test statistic is

S =2∑

i=1

(|Oi − Ei| − 0.5)2

Ei

=(|9− 7.2| − 0.5)2

7.2+

(|27− 28.8| − 0.5)2

28.8

=1.69

7.2+

1.69

28.8= 0.2934

so that p-value= Pr(χ21 > 0.2934)

= 2Pr(ZN > 0.5417) = 2[0.17(0.2912) + 0.83(0.2946)]= 2(0.2940) = 0.5880and, at α = 0.05, we fail to reject the null.

Page 39: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.5. GOODNESS OF FIT CHI-SQUARE 39

11.5.2.3 example 4

Of 20 students, 12 are from Ontario, 4 from Canada outside of Ontario, and4 from outside of Canada.in general, 70% of students are from Ontario, 20% from Canada outside ofOntario, and 10% from outside of Canada.Is this sample representative of the population?

O1 = 12, E1 = 20(0.7) = 14O2 = 4, E2 = 20(0.2) = 4O3 = 4, E3 = 20(0.1) = 2The Goodness of Fit statistic is

S =(12− 14)2

14+

(4− 4)2

4

+(4− 2)2

2Note: for k > 2 , there is no CC

=4.0

14+

0.0

10+

4.0

2= 2.285

Under Ho, S ∼ χ22

so that p = Pr(χ22 > 2.285) > 0.10(Table A.2, page A.3)

and, at α = 0.05, we again fail to reject the null.

Page 40: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

40 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.5.3 Test of proportion and Goodness of Fit

This covers the case when k = 2, that is, the binary (dichotomous) datatype. In this case, the test ofHo : π = πo

against a two-sided intervalHA : π 6= πo

can be handled by the p-value calculation

p = 2Pr

(

ZN > (p−πo)−1/2n√πo(1−πo)/n

)

or by the Goodness of Fit test

S =∑2

i=1(|Oi−Ei|−0.5)2

Ei

where E1 = nπo and E2 = n(1− πo)andp = Pr(χ2

1 > S)

It can be shown that

1. the p-values from both tests are the same

2. the test statistics are equivalent, that is(p−πo)−1/2n√

πo(1−πo)/n=√

∑2i=1

(|Oi−Ei|−0.5)2

Ei

Page 41: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.5. GOODNESS OF FIT CHI-SQUARE 41

Proof :Let’s look at

2∑

i=1

(|Oi − Ei| − 0.5)2

Ei

and worry about the√

later. We have

|O1 − E1| − 0.5)2

E1

+|O2 − E2| − 0.5)2

E2

=(|x− nπo| − 0.5)2

nπo

+(|(n− x)− n(1− πo)| − 0.5)2

n(1− πo)

=(1− πo)(|x− nπo| − 0.5)2 ++πo(|(n− x)− n(1− πo)| − 0.5)2

nπo(1− πo)

=(1− πo)(|x− nπo| − 0.5)2 ++πo(|(nπo)− x| − 0.5)2

nπo(1− πo)

|x − nπo| is the same as |x − nπo| and the πo’s cancel out in the numeratorso we have

(|x− nπo| − 0.5)2

nπo(1− πo)

Divide both numerator and denominator by n2 to get

(|xn− πo| − 1

2n)2

(πo(1− πo))/n

Take the square root to get

(|p− πo| − 12n)

(πo(1− πo))/n

which is the equivalence we required.

Page 42: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

42 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

11.6 Using SAS with single samples

Although the next section is not directly related to inference with simplesamples, it is a useful SAS technique, which we choose to introduce at thistime.

11.6.1 Creating new SAS datasets

You require:

1. LIBNAME for the location of your current dataset;

2. LIBNAME for the location of your formats library;

3. DATA command with name of the new permanent dataset;

4. SET sub-command with name of current permanent dataset

Here is an example of part of SAS program for dataset creation.

LIBNAME fred ’U:/Epid9509’;

LIBNAME library ’U:/Epid9509’;

DATA fred.cancer2;

SET fred.cancer;

11.6.1.1 Creating new variables

1. This must be done in a DATA step;

2. It often involves an IF statement;

3. It usually involves creation of new variable with old valuesthen modification of these values, for example,

diag3 = diagnosis ;

if (diagnosis ge 2) then diag3 = 2;

4. Recall that the missing value indicator is .

diag2 = diagnosis ;

if (diagnosis ge 2) then diag2 = .;

Page 43: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.6. USING SAS WITH SINGLE SAMPLES 43

11.6.2 Using SAS for inference with a single popula-tion

SAS Proc FREQ can be used to analyse count data from a single sampleHere is an example:

title ’inference for single sample probabilities’;

options ls=64;

proc format;

value grp 0=’non-smoker’ 1=’smoker’;

data marj;

input grp smok;

format grp grp.;

datalines;

0 27

1 9

;

proc freq;

weight smok;

tables grp/binomial(level =’smoker’ p=0.2 wilson ac);

exact binomial;

run;

1. As for the independent samples t-test, we have to indicate ”group”membership;

2. we indicate that we have counts by using the WEIGHT command inProc FREQ;

3. we can get both Wilson (option WILSON) and adjusted Wald (optionAC) confidence intervals.

4. unfortunately SAS does not do continuity correction for its hypothesistests. We have to ask for an exact test for the binomial (EXACTBINOMIAL).

Page 44: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

44 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

Here is the output of the program:

inference for single sample probabilities 8

The FREQ Procedure

Cumulative Cumulative

grp Frequency Percent Frequency Percent

---------------------------------------------------------------

non-smoker 27 75.00 27 75.00

smoker 9 25.00 36 100.00

Binomial Proportion

for grp = smoker

----------------------

Proportion 0.2500

ASE 0.0722

Type 95% Confidence Limits

Wilson 0.1375 0.4107

Agresti-Coull 0.1356 0.4126

Test of H0: Proportion = 0.2

ASE under H0 0.0667

Z 0.7500

One-sided Pr > Z 0.2266

Two-sided Pr > |Z| 0.4533

Exact Test

One-sided Pr >= 0.2841

Two-sided = 2 * One-sided 0.5682

Sample Size = 36

Page 45: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

11.7. QUESTIONS 45

11.7 Questions

1. In a random sample of 60 students, 18 were smokers.

(a) construct a 95% confidence interval for the probability of smokingamong students.

i. Use both the Wald and adjusted Wald methods

ii. repeat this calculation using SAS

(b) Statistics Canada says that 20% of students smoke

i. test this hypothesis against the hypothesis that more than20% smoke

ii. repeat this calculation using SAS

(c) calculate the power of this study to detect the alternative of asmoking proportion of 30% against the null alternative of 20%

(d) calculate the sample size required to show a difference of 10% fromthe Statistics Canada claim of 20%

(e) calculate the sample size required to give 95% confidence intervalwith a Margin of Error of 10%

2. It is claimed that the rate of obesity among children is 30%.

(a) How large a sample must be used to estimate this rate to with10%?

(b) if we were going to conduct at study with a power of 80% ofshowing that the rate is really 20%, how large would it have tobe?

(c) given that we have a study of size 100, what power does is haveof showing this difference of 10%?

(d) If you had a study of 100 children, of whom 25% were obese:

i. At α = 0.05, does this agree with the claim that the popula-tion proportion is 30%.

ii. calculate a 95% confidence interval for the obesity proportionin the population. Use the Wald and the Adjusted Waldmethods.

Page 46: Chapter 11 Inference for a single probabilitypublish.uwo.ca/~jkoval/courses/Epid9509/notes/single_prop.pdf · Each of the XI random variables has a Bernoulli distribution, and we

46 CHAPTER 11. INFERENCE FOR A SINGLE PROBABILITY

3. For the cancer data

(a) Create a new permanent SAS dataset containing, in addition tothe current variables, three new variables

i. Bence-Jones as present or absent;

ii. cancer diagnosis as three levels Type 1, Type 2 and other;Note - you probably have Diagnosis at 4 levels, but threeformats;do change it to 3 levels!!

iii. cancer diagnosis as two levels Type 1 and Type 2 ;set the other values to missing

(b) The presence of cryoproteins is fairly rare.

i. Use SAS to test the hypothesis that it is present in more than5% of the population;

ii. Confirm this result by a hand calculation.

(c) Bence-Jones is fairly more common:

i. Use SAS to test the hypothesis that it is present in 50% ofthe population;

ii. Confirm this result by a hand calculation.