in reply to Re: Calculate propabilities without recursion? Coin toss.
in thread Calculate propabilities without recursion? Coin toss.

Could you show me how the script would look like? Unfortunately I'm just a biologist and a very poor programmer. Many Thanks...
  • Comment on Re^2: Calculate propabilities without recursion? Coin toss.

Replies are listed 'Best First'.
Re^3: Calculate propabilities without recursion? Coin toss.
by roboticus (Chancellor) on Mar 16, 2011 at 19:03 UTC

    Microcebus:

    As others have said, if you're a scientist, you should definitely find a programming language to become proficient at!

    Anyway, here's a start. I don't know exactly what you're trying to do, so I just hacked together a couple things from the posts I cited in my previous response. Here ya go:

    use strict; use warnings; use List::Util qw(reduce); use bignum; # Number of coins to toss my $coin_toss=1000; # We cumulative probability of side1 appearing anywhere between 1 and +60 times my $side1=60; # Compute the binomial coefficients for row 1000 of pascal's triangle my @triangle = robo_2(1000); print <<EOHDR; Tails Count % ----- ---------- ------ EOHDR my $total_prob=0; my $runs = reduce { $a + $b } @triangle; for (my $i = 0; $i < @triangle; $i++) { my $prob = $triangle[$i]/$runs; $total_prob += $prob unless $i > $side1; print "$i\t$triangle[$i]\t",100*$prob, "\n"; } print "\n\nProbability of 0..60 tails is: ", $total_prob*100; sub robo_2 { my $row = shift; my @cols = (1); ++$row; $cols[$_] = $cols[$_-1] * ($row-$_)/$_ for 1 .. $row-1; return @cols; }

    Note: The output gets pretty darned wide with 1000 tosses and bignum in the picture...

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thank you very much, this solved my problem.

      By the way: I want to analyze sections of the genome encoding many genes that can be encoded either on + or - strand (as you may know, DNA is made up of two complementary strands). I'm searching for a specific kind of gene clusters which typically exhibit a strong strand bias. Therefore I want to calculate the propability, that a given strand bias occures by chance.