How to combine an If statement with Statistics
- To: mathgroup at smc.vnet.net
- Subject: [mg131387] How to combine an If statement with Statistics
- From: William Duhe <wjduhe at loyno.edu>
- Date: Wed, 17 Jul 2013 01:50:24 -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
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"]
- Follow-Ups:
- Re: How to combine an If statement with Statistics
- From: Bob Hanlon <hanlonr357@gmail.com>
- Re: How to combine an If statement with Statistics