Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15180 > unrolled thread

How to combine an If statement with Statistics

Started byWilliam Duhe <wjduhe@loyno.edu>
First post2013-07-17 05:46 +0000
Last post2013-07-17 05:46 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to combine an If statement with Statistics William Duhe <wjduhe@loyno.edu> - 2013-07-17 05:46 +0000

#15180 — How to combine an If statement with Statistics

FromWilliam Duhe <wjduhe@loyno.edu>
Date2013-07-17 05:46 +0000
SubjectHow to combine an If statement with Statistics
Message-ID<ks5b33$clh$1@smc.vnet.net>
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 the label "Signal". When the Signal is positive S2 should be positive and when 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"]

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web