Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to combine an If statement with Statistics

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131393] Re: How to combine an If statement with Statistics
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Thu, 18 Jul 2013 03:00:27 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20130717055024.0CF1E69D0@smc.vnet.net>

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 that
Greater 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 Hanlon




On Wed, Jul 17, 2013 at 1:50 AM, William Duhe <wjduhe at 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"]
>
>



  • Prev by Date: f'[0]=0.5 is True?
  • Next by Date: Re: MCMC in Mathematica
  • Previous by thread: How to combine an If statement with Statistics
  • Next by thread: DynamicModule Problem