Re: How to simulate random samples from crooked coin toss?

*To*: mathgroup at smc.vnet.net*Subject*: [mg58543] Re: [mg58511] How to simulate random samples from crooked coin toss?*From*: Curtis Osterhoudt <gardyloo at mail.wsu.edu>*Date*: Wed, 6 Jul 2005 03:11:28 -0400 (EDT)*References*: <200507050557.BAA29457@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi, Dan, Here's my solution. There are probably much more elegant ways to do it, but this is quick: Get your probabilities (for the crooked coin, or die, or whatever) in the range [0, 1] for each side. That is, if the die has 6 sides, you could say probsOfEachSide={0.4, 0.15, 0.3, 0.1, 0.025, 0.025} so that "side 1" has a 40% chance of coming up, "side 2" has a 15% chance, etc. numberOfSide = probsOfEachSide//Length Note that probsOfEachSide//Total = 1. Create a list of cutoffs -- read the documentation about RangeCounts and RangeLists: cutoffs={0}; cutoffs[[1]] = probsOfEachSide//First; (AppendTo[cutoffs, probsOfEachSide[[#]] + cutoffs[[# - 1]]]) & /@ (Range[2, numberOfSides - 1]); Needs["Statistics`DataManipulation`"] Here, we toss a coin 10000 (or however many you want) times: rawTosses = Random[] & /@ Range[10000]; If you want to see explicitly which tosses fall into which bins (between 0 and 0.4, or between 0.4 and 0.4+0.15, etc.) then you can use RangeLists[rawTosses, cutoffs] but I suspect that you want to use numberInEachBin=RangeCounts[rawTosses, cutoffs] which will actually count the number of tosses which fall into each bin. ListPlot[numberInEachBin, PlotJoined -> True] Alternatively, Histogram looks nice: Needs["Graphics`Graphics`"] Histogram[numberInEachBin, FrequencyData -> True]; Hope that helps, C.O. DAN BIKLE wrote: >Math People, > >I'm new to Mathematica so please bear with me. > >I have a simple problem I want to solve and I'm looking >for some ideas to get started on it. > >I want to simulate 100 tosses of a crooked coin where >probability of Heads is 0.6 and Tails is 0.4. > >After I figure the coin out, I want to move on to crooked >dice and crooked card decks. > >So, really what I'm looking for has more to do with developing >a method to simulate the collection of random samples. > >I looked around in Help and found a promising sentence: > >"Random[distribution] gives a random number with the specified >statistical distribution." > >Then I found a page here which has some clues: >http://mathworld.wolfram.com/DiscreteDistribution.html > >Unfortunately, I'm weak with math notation so the above >page makes little sense to me. > >So, let me put it to you as simply as I can: > >I want to define a function that could be called like this: > >numberOfHeads = coinTosser[infoAboutCoin, numberOfTosses, head] >numberOfTails = coinTosser[infoAboutCoin, numberOfTosses, tail] > >Once I figure out how to write the above function, >I could template off of it to build something like this: > >numberOfOnes = diceRoller[infoAboutThisDie, numberOfRolls, aOne] > >Do any of you have thoughts on how to approach the >writing of the above functions? > >-Dan > > -- PGP Key ID: 0x235FDED1 Please avoid sending me Word or PowerPoint attachments. http://www.gnu.org/philosophy/no-word-attachments.html

**References**:**How to simulate random samples from crooked coin toss?***From:*DAN BIKLE <dbikle@gmail.com>