Simulation of sampling without replacement, Sampling-without-replacement function, Sampling without replacement – Texas Instruments PLUS TI-89 User Manual

Page 424

Advertising
background image

Chapter 23: Activities 407

23ACTS.DOC TI-89/TI-92 Plus: Activities (English) Susan Gullord Revised: 02/23/01 1:24 PM Printed: 02/23/01 2:20 PM Page 407 of 26

In the Program Editor, define

drawball()

as a function that can be

called with two parameters. The first parameter is a list where each
element is the number of balls of a certain color. The second
parameter is the number of balls to select. This function returns a list
where each element is the number of balls of each color that were
selected.

:drawball(urnlist,drawnum)
:Func
:Local templist,drawlist,colordim,

numballs,i,pick,urncum,j

:If drawnum>sum(urnlist)
:Return “too few balls”
:dim(urnlist)

!

colordim

:urnlist

!

templist

:newlist(colordim)

!

drawlist

:For i,1,drawnum,1
:sum(templist)

!

numballs

:rand(numballs)

!

pick

:For j,1,colordim,1
:cumSum(templist)

!

urncum

(continued in next column)

:If pick



urncum[j] Then

:drawlist[j]+1

!

drawlist[j]

:templist[j]

ì

1

!

templist[j]

:Exit
:EndIf
:EndFor
:EndFor
:Return drawlist
:EndFunc

Suppose an urn contains n1 balls of a color, n2 balls of a second
color, n3 balls of a third color, etc. Simulate drawing balls without
replacing them.

1. Enter a random seed using the

RandSeed

command.

2. Assuming the urn contains 10

red balls and 25 white balls,
simulate picking 5 balls at
random from the urn without
replacement. Enter

drawball({10,25},5)

.

Result: 2 red balls and 3 white
balls.

Simulation of Sampling without Replacement

This activity simulates drawing different colored balls from an urn
without replacing them. Detailed information about the steps used
in this example can be found in Chapter 17: Programming.

Sampling-without-
Replacement
Function

Sampling without
Replacement

Advertising
This manual is related to the following products: