0
$\begingroup$

I have a long list of descriptive statistical quantities for a univariate list of data. The problem is that the set number of significant figures is ignored by the N[...,sigs] for most expressions. In the code they are easily identified with a comment (* sigs not working *).

Why are they not returned in requested precision of 3 significant figures? How can I fix this?

raw = {1.32, 1.37, 1.43, 1.32, 1.36, 1.33, 1.38, 1.35, 1.48, 1.28, 
   1.31, 1.52, 1.51, 1.33, 1.32, 1.27, 1.35, 1.40, 1.27, 1.39, 1.50, 
   1.31, 1.34, 1.48, 1.36, 1.33, 1.40, 1.29, 1.35, 1.36, 1.33, 1.30, 
   1.28, 1.32, 1.34, 1.33, 1.29, 1.34, 1.34, 1.29, 1.35, 1.52, 1.29, 
   1.38, 1.40, 1.28, 1.36, 1.36, 1.32, 1.62, 1.36, 1.34, 1.33, 1.33, 
   1.30, 1.31, 1.33, 1.32, 1.36, 1.41};
    sigs = 3;
    {"n", n = Length[raw]}
    {"range", range = N[Max[raw] - Min[raw], sigs]}
    {"midrange", 
     midrange = N[Min[raw] + range/2, sigs]}(* sigs not working *)
    {"μ ", μ = N[Mean[raw], sigs]}(* sigs not working *)
    {"median", median = N[Median[raw], sigs]}
    {"mode", mode = N[Commonest[raw][[1]], sigs]}
    {"rms", rms = N[RootMeanSquare[raw], sigs]}(* sigs not working *)
    {"σ2", σ2 = 
      N[Variance[raw], sigs]}(* sigs not working *)
    {"σ", σ = 
      N[Sqrt[σ2], sigs]}(* sigs not working *)
    {"σmean", σmean = 
      N[MeanDeviation[raw], sigs]}(* sigs not working *)
    {"Cvar", Cvar = N[σ/μ, sigs]}(* sigs not working *)
    {"Es", Es = 
      N[(6745/10000) StandardDeviation[raw], 
       sigsup]}(* sigs not working *)
    {"Em", Em = N[Es/Sqrt[n], sigsup]}(* sigs not working *)
    {"skew", skew = N[Skewness[raw], sigsdn]}(* sigs not working *)
    {"kurt", kurt = N[Kurtosis[raw], sigsdn]}(* sigs not working *)
$\endgroup$
  • 3
    $\begingroup$ Don’t use the machine-precision number .6745. That will force the conversion of your result to MachinePrecision. You could use 6745/10000, .6745`3, or SetPrecision[.6745, sigs] instead. $\endgroup$ – MarcoB May 26 at 4:51
  • 1
    $\begingroup$ You can try Es = N[Rationalize[.6745] σ, sigs] and wrap Rationalize around most other constants which include a decimal point that you put in your code. The rules are a little more complicated than that, but this should be a simple rule to get you most of the way there $\endgroup$ – Bill May 26 at 5:10
  • $\begingroup$ @MarcoB thank you it worked. but now i have another problem. for some odd reason all the other expressions that worked before are no longer setting precision. would you mind looking at it for me? the expressions that aren't working are commented $\endgroup$ – Jules Manson May 26 at 6:05
  • 1
    $\begingroup$ Your edit appeared to have removed the assignment to raw which I think might have been something like raw={1,2,3,4,5} If I insert that near the top most of it starts working again. But it starts failing at cvar which I assume is another mixup. Does this give you enough to start tracking that down? $\endgroup$ – Bill May 26 at 6:58
  • 2
    $\begingroup$ If I change raw={1.32,..} to raw=Rationalize[{1.32,..}] then everything down to cvar starts working. And the reason it fails there is that if you copy and paste exactly your code above into a new fresh notebook and you look closely you should see that sigsup and sigsdn are blue, not black, which is supposed to let you notice that you haven't assigned values to either of those. If I change sigs=3; to sigs=3;sigsup=3;sigsdn=3; and run your code then everything appears to work now. Please verify that. $\endgroup$ – Bill May 26 at 7:44

Your Answer

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

Browse other questions tagged or ask your own question.