Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Using Statistics with an If Statement' topicStudent Support Forum > General > Archives > "Using Statistics with an If Statement"

Next Comment >Help | Reply To Topic
Author Comment/Response
William Duhe
07/16/13 08:10am

Bellow I have 2 segments of code. The first is the code before I have tried to implement an "if statement" to introduce a sign change.

What I am essentially trying to do ( I would think it would be kind of obvious ) is have my function shift signs "+/-" to match the sign of the "Signal" function I have defined. This should make function 17 roughly fit the Gaussian function that I have plotted it against in the code.

As a note you can see that the statistics are roughly twice what they should be to fit the Gaussian. This is because the negative events are currently being counted as positive by the algorithm. Thus we want the sign to change with the signal to compensate for this and distribute the statistics into the negative regime.

For a slightly more detailed account of the Monte Carlo Simulation I am trying to build is contained within the attached .nb file. Feel free to reduce the amount of iterations for convenience and speed if you wish.

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*)

h2 = Plot[
Table[PDF[NormalDistribution[0, \[Sigma]], x], {\[Sigma],
1}], {x, -6, 6}, PlotStyle -> Red];
S[off_, \[Alpha]_] = Non - \[Alpha]*Noff;
hist = Histogram[S[off, \[Alpha]], Automatic, "ProbabilityDensity",
PlotLabel -> "Signal"]

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 17 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",
PlotRange -> {{0, 100000}, {0, 8}}]
hist1 = Histogram[S2[off, \[Alpha]], "Log", "ProbabilityDensity",
PlotLabel -> "Formula 17 LOG"]
hist11 = Histogram[S2[off, \[Alpha]], Automatic, "ProbabilityDensity",
PlotLabel -> "Formula 17"]
Show[hist11, h2]
ProbabilityScalePlot[S2[off, \[Alpha]], "Normal",
PlotLabel -> "Formula 17"]

Attachment: LI and MA.nb, URL: ,

Subject (listing for 'Using Statistics with an If Statement')
Author Date Posted
Using Statistics with an If Statement William Duhe 07/16/13 08:10am
Re: Using Statistics with an If Statement Bill Simpson 07/20/13 2:09pm
Next Comment >Help | Reply To Topic