Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm fitting data, and I want to put the parameter table generated by NoninearModelFit into the plot. How can I do that in a reasonable way? I want to format the parameter table so that it only shows two decimal places and doesn't show the t-statistic and P-Values.

share|improve this question
1  
You might look at using a combination of Epilog and Inset in your plot. –  image_doctor Aug 18 at 12:49
2  
Posting some code would be very useful, if only to save us time making up bogus data. –  Yves Klett Aug 18 at 13:08
    
@YvesKlett I post an answer to illustrate extracting values from model object, then a way to format numbers, then Inset...this seemed long for comment...but agree entirely with your comments on this and some similar questions...there seems to be something in the 'weather'. Fortunately, this was code I had lying around. –  ubpdqn Aug 18 at 13:28

1 Answer 1

up vote 5 down vote accepted

I post this for illustrative purposes. You can access values. I suggest looking at the properties of your model, e.g. if your model is nlm then nlm["Properties"].

Some data and model:

wd = WeatherData["Brisbane", 
   "Temperature", {{2004, 1, 1}, {2013, 12, 31}, "Day"}];
vl = QuantityMagnitude /@ wd["Values"];
bnl = NonlinearModelFit[Thread[{Range[Length[vl]], vl}], 
   a + d Cos[b x + c], {{a, 20}, {b, Pi/180}, {c, 2}, {d, 10}}, x];
param = bnl["ParameterTableEntries"];

Visualizing:

pl = Plot[bnl[x], {x, 1, 3600}, PlotStyle -> {Red, Thick}, 
   Epilog -> 
    Inset[Grid[
      Join @@@ 
       Thread[{{{a}, {b}, {c}, {d}}, 
         Map[NumberForm[#, 2] &, param[[All, {1, 2}]], {2}]}], 
      Frame -> True], {2000, 6}], PlotRange -> {0, 35}, 
   PlotLabel -> TraditionalForm[a + d Cos[b x + c]]];
cp = Show[pl, ListPlot[vl], Frame -> True]

enter image description here

The inset has parameter estimate and standard error. This could grid could have been in much better ways and note the order of graphics in Show is important. This could be made "nicer" to suit personal preferences and style. I just post it as motivation.

Post script: as m_goldberg correctly comments the function produces 2 significant figures not two decimal places). Feel free to adapt as seen fit.

share|improve this answer
1  
+1. I hate to be spoil-sport, but the OP asked for two decimal places, not two significant figures. Personally, I think two significant figures would be more useful. –  m_goldberg Aug 18 at 13:07
    
@m_goldberg well spotted (as usual)...just adapted some "code lying around"...will add a comment –  ubpdqn Aug 18 at 13:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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