```Date: Jul 18, 2013 2:44 AM
Author: Bob Hanlon
Subject: Re: How to combine an If statement with Statistics

off = 140;(*Expected Number of Off Counts*)=E1 = .3;(*Ratio of On/Off Counts*)Non = RandomVariate[PoissonDistribution[=E1*off], 100000];Noff = RandomVariate[PoissonDistribution[off], 100000];(*Normal Distribution*)h2 = Plot[   PDF[NormalDistribution[], x],   {x, -6, 6},   PlotStyle -> Directive[Red, Thick]];Attributes /@ {Greater, Sign}{{Protected}, {Listable, NumericFunction, Protected, ReadProtected}}Non - =E1*Noff is a list and is neither positive nor negative. Note thatGreater is not Listable but Sign is Listable.Clear[S2];S2[off_, =E1_] =  Sign[Non - =E1*Noff]*   Sqrt[2] (Non*Log[(1 + =E1)/=E1 (Non/(Non + Noff))] +      Noff*Log[(1 + =E1) (Noff/(Non + Noff))])^(1/2);ListPlot[S2[off, =E1], Frame -> True, Axes -> False, PlotLabel -> "Formula 17"]hist2 = Histogram[S2[off, =E1],  "Log",  "ProbabilityDensity",  PlotLabel -> "Formula 17 LOG"]hist22 = Histogram[S2[off, =E1],   Automatic,   "ProbabilityDensity",   PlotLabel -> "Formula 17"];Show[hist22, h2]ProbabilityScalePlot[S2[off, =E1], "Normal", PlotLabel -> "Formula 17"]Bob HanlonOn Wed, Jul 17, 2013 at 1:50 AM, William Duhe <wjduhe@loyno.edu> wrote:> Bellow is a code which attempts to change the sign (+/-) of S with an if> statement. S1 is shown and S2 is the attempt to include the if statement.>> You can see from the information yielded from S1 that the Gaussian fit is> off by roughly a factor of 2 when it should in theory match. This is> because it is overestimating positive events due to the lack of the sign> change. The sign change should change with the quantity I have assigned t=he> label "Signal". When the Signal is positive S2 should be positive and whe=n> Signal is negative S2 should become negative.>>> (*VARIABLES*)>> Non = RandomVariate[PoissonDistribution[\[Alpha]*off], 100000];> Noff = RandomVariate[PoissonDistribution[off], 100000];> off = 140; (*Expected Number of Off Counts*)> \[Alpha] = .3; (*Ratio of On/Off Counts*)>> (*Normal Distribution*)> h2 = Plot[>    Evaluate@>     Table[PDF[NormalDistribution[0, \[Sigma]], x], {\[Sigma],>       1}], {x, -6, 6}, PlotStyle -> Red];>> (*Signal*)> S[off_, \[Alpha]_] = Non - \[Alpha]*Noff;> hist = Histogram[S[off, \[Alpha]], Automatic, "ProbabilityDensity",>   PlotLabel -> "Signal"]>>>> (*Formula WITHOUT IF STATEMENT*)> S1[off_, \[Alpha]_] = .5 Sqrt[>    2] (Non*Log[(1 + \[Alpha])/\[Alpha] (Non/(Non + Noff))] +>      Noff*Log[(1 + \[Alpha]) (Noff/(Non + Noff))])^(1/2);> ListPlot[S1[off, \[Alpha]], PlotLabel -> "Formula 17",>  PlotRange -> {{0, 100000}, {0, 8}}]> hist1 = Histogram[S1[off, \[Alpha]], "Log", "ProbabilityDensity",>   PlotLabel -> "Formula 17 LOG"]> hist11 = Histogram[S1[off, \[Alpha]], Automatic, "ProbabilityDensity",>    PlotLabel -> "Formula 17"]> Show[hist11, h2]> ProbabilityScalePlot[S1[off, \[Alpha]], "Normal",>  PlotLabel -> "Formula 17"]>>>>> (*Formula WITH IF STATEMENT*)> S2[off_, \[Alpha]_] =>   If[Non - \[Alpha]*Noff > 0,>    Sqrt[2] (Non*Log[(1 + \[Alpha])/\[Alpha] (Non/(Non + Noff))] +>       Noff*Log[(1 + \[Alpha]) (Noff/(Non + Noff))])^(>     1/2), -Sqrt[>      2] (Non*Log[(1 + \[Alpha])/\[Alpha] (Non/(Non + Noff))] +>       Noff*Log[(1 + \[Alpha]) (Noff/(Non + Noff))])^(1/2)];>> ListPlot[S2[off, \[Alpha]], PlotLabel -> "Formula 17"]> hist2 = Histogram[S2[off, \[Alpha]], "Log", "ProbabilityDensity",>   PlotLabel -> "Formula 17 LOG"]> hist22 = Histogram[S2[off, \[Alpha]], Automatic, "ProbabilityDensity",>    PlotLabel -> "Formula 17"]> Show[hist22, h2]> ProbabilityScalePlot[S2[off, \[Alpha]], "Normal",>  PlotLabel -> "Formula 17"]>>
```