Thursday, February 10, 2011

Caps Shutout Sim

Reposted from a comment I made over at Japers' Rink.


Two notes:

One, the link points here.

Just a thought that occurred to me: I might have miscalculated the confidence interval, although at first look it looks alright (every team finished within that interval last season).

I copy-pasted the code I used after the jump. Results may vary slightly from what I got.

    public class ShutoutFreq
   {
      private static final double SHOOTINGPCT=0.085397;
      private static final int SHOTSGM=31;
      private static final int SEASONS=10000;
       public static void main(String[] args)
      {
         int goals=0;
         int shutout=0;
         int[] shutoutfreq=new int[21];   //0 to 20 shutouts
         for(int k=1; k<=SEASONS; k++)
         {
            shutout=0;
            for(int gm=1; gm<=82; gm++)
            {
               goals=0;
               for(int s=1; s<=SHOTSGM; s++)
               {
                  if(Math.random()<=SHOOTINGPCT)
                     goals++;
               }
               if(goals==0)
                  shutout++;
            }
            shutoutfreq[shutout]++;
         }
         System.out.println(shutoutfreq);
      }
   }

And (since I forgot to calculate mean, variance, etc, in the first program)

    public class SD
   {
      private static int[] freqs = {35,265,759,1290,1766,1791,1514,1155,647,416,218,86,32,19,5,0,0,0,2};
       public static void main(String[] args)
      {
      //mean
         int sum=0;
         for(int k=0; k
            sum+=k*freqs[k];
         double mean=sum/10000.0;
         System.out.println("Mean:\t"+mean);
         //sd
         double sdsum=0.0;
         for(int k=0; k
            sdsum+=freqs[k]*Math.pow(mean-k,2);
         mean=sum/10000.0;
         System.out.println("Variance:\t"+mean);
         System.out.println("SD:\t"+Math.sqrt(mean));
      //conf interval
      }
   }




1 comment:

  1. I code in Java. If you want to run this yourself, you need a program to run Java--I suggest JGrasp (which is available for free). Do note that I have two programs here, not one.

    ReplyDelete