# My Data has negative and positive numbers, can I still use it to get the PDF?

I have data that reflects the arrival time of a flight. {3, -2, 16, 13, -6, 5, 4, -7, 7, 0……..n} this is for 8:45am and has 150 elements "arrivals" The positive values represent the time in minutes past the planned time,{“late”} and the negative, is before planned time {“early”} My question, I would like to find the time of arrival with the highest probability. Can I use this data as is?

-
Is your question related to Mathematica (TM)? If not, you're in the wrong site –  belisarius Feb 23 '13 at 1:08
Yes this is a question directed to mathematica. –  Bob Brooks Feb 23 '13 at 1:24
Histogram[data,Automatic,"Probability"] seems like a good start. To say anything about highest probability you need to make some assumptions about the underlying distributions. You can try to fit various distributions to the data. –  ssch Feb 23 '13 at 1:33
On a related note, anyone know how DistributionFitTest is supposed to be interpreted? sets = 100; size = 10000; data = RandomVariate[NormalDistribution[], {sets, size}]; Histogram[DistributionFitTest[#, Automatic] & /@ data] It's all over the place –  ssch Feb 23 '13 at 1:53
@ssch, As far as I understand DistributionFitTest gives you back the p-value from the test which is going to vary for each set but most of the results of the actual test are what you expect sets=100;size=10000;data=RandomVariate[NormalDistribution[x,{sets,size}];Tally[‌​(DistributionFitTest[#,Automatic,"ShortTestConclusion"] & /@ data)] –  Martin John Hadley Feb 23 '13 at 2:20

For the sake of giving a (hopefully) useful answer.

Lets generate 150 arrival times where negative values indicate early and positive times indicate late arrivals. Here I'm assuming that people are as likely to be late as early and the distribution of arrival times is BinomialDistribution[20, 1/2]. This further assumes that people tend to be about 10 minutes early or 10 minutes late.

SeedRandom[1];
arrival =
RandomChoice[{-1, 1}, 150]*
RandomVariate[BinomialDistribution[20, 1/2], 150];


Now there are a number of things available to us in Mathematica for working with this data.

Lets compute the expected arrival time.

Expectation[a, a \[Distributed] arrival]

(* -(109/75) *)


Or we could say, what is the probability someone is late?

Probability[a > 0, a \[Distributed] arrival]

(* 13/30 *)


We can estimate distributions from the data. Here a mixture of normals is used which is a little silly given that the data is discrete but normal is known to be a reasonable approximation to the binomial distribution with large enough samples and we expect a bimodal distribution given the setup.

 est = EstimatedDistribution[arrival,
MixtureDistribution[{1/2, 1/2}, {NormalDistribution[a, b],
NormalDistribution[c, d]}]]

(* MixtureDistribution[{1/2, 1/2}, {NormalDistribution[9.75385, 2.15571],
NormalDistribution[-10.0235, 2.35635]}] *)


We can plot all sorts of things and assess the goodness of fit to our chosen distribution.

Show[Plot[PDF[est, x], {x, -25, 25}], SmoothHistogram[arrival]]


We should keep in mind here that the p-value will probably be larger than it should be since I've estimated the distribution from the data first...

DistributionFitTest[arrival, est]

(* 0.107467 *)


We can always check further with a QuantilePlotwhich claims it doesn't fit so well in the body of the distribution...

QuantilePlot[arrival, est]


The bottom line is that there is nothing special about negative arrival times as far as Mathematica is concerned. It is happy to work with them just like any other data.

-
Thank you @AndyRoss, I think this will do just fine! –  Bob Brooks Feb 23 '13 at 20:44