3
$\begingroup$

Here is data.csv:

Src,Dst,Size,Arrival,Delay,SrcClk,TrgClk,Nhops,Route,SrcErr,TrgErr
12,22,100,1199145666.72,10.483,2107,107,12,7774334,0.002,0.048
12,22,100,1199145696.88,10.42,2107,107,12,7774334,0.002,0.048
12,22,100,1199145725.14,10.41,2107,107,12,7774334,0.002,0.048
12,22,100,1199145755.39,10.396,2107,107,12,7774334,0,0.048
12,22,100,1199145784.63,10.391,2107,107,12,7774334,0,0.048

I load this data via the following command:

d = SemanticImport["myData.csv", {"Integer", "Integer", "Integer", "String", "Real",
"String", "String", "Integer", "Integer", "Real", "Real"}, Delimiters -> ","]

Then I want to create an EmpiricalDistribution of the data via:

delays = d[All, "Delay"]
e = EmpiricalDistribution[ delays ]

but then it triggers the error:

"EmpiricalDistribution::rectn: Rectangular array of real numbers is expected at position 1 in EmpiricalDistribution"

I've no idea why

$\endgroup$
  • 1
    $\begingroup$ Looks like EmpiricalDistribution isn't handling Head == Dataset. Does EmpiricalDistribution[Normal@delays] do what you expect? $\endgroup$ – bobthechemist Mar 5 '15 at 15:03
  • $\begingroup$ It does work thanks ! If you set a proper answer (if I dare ask: with a bit more explanation), I can upvote it :) $\endgroup$ – mattator Mar 5 '15 at 16:02
2
$\begingroup$

The documentation for EmpiricalDistribtuion states that it operates on a List, multiple Lists or a set of Rules. If we look at the Head of your symbol, delays, we see that it is Dataset, which is not one of the argument forms that EmpiricalDistribution understands. The documentation for Normal states that it will convert a symbol with Head = Dataset to a List, allowing you to use the modified symbol in EmpiricalDistribtuion.

EmpiricalDistribution[Normal@delays]
| improve this answer | |
$\endgroup$
1
$\begingroup$
delays = d[All, "Delay"];
e = delays[EmpiricalDistribution];
(* or e = Query[EmpiricalDistribution][delays] *)

Through@{Mean, Variance, Quantile[#,.3]&}@e
(* {10.42, 0.0010972, 10.396} *)
Query[{Mean, Variance, Quantile[#, .3] &}][delays]//Normal
(* {10.42, 0.0010972, 10.396} *)

Plot[CDF[e,x],{x,10,11}]
delays[Plot[CDF[EmpiricalDistribution[#],x],{x,10,11}]&] 
Query[Plot[CDF[EmpiricalDistribution[#],x],{x,10,11}]&][delays]

all give

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.