5
$\begingroup$

The Standard table fo parameters of NonlinearModelFit is obtained from

 NonlinearModelFit[{{0, 1}, {1, 2}, {3, 3}}, a + b*x, {a, b}, x]
 %["ParameterTable"]]

I woud like to manipulate the numbers in this tabe to my taste.

For some of this I could "ParameterTableEntries", but this gives just the numerical values, not the name of the parameters.

So I would like to know if there is an way to get the fit parameters names in the right order.

My best guess is to manipulate the output of InputForm[%["ParameterTable"]], but I failed so far because of my poor pattern search skills ... any idea?

Thanks, Roberto

$\endgroup$
  • 1
    $\begingroup$ try fit = NonlinearModelFit[{{0, 1}, {1, 2}, {3, 3}}, a + b*x, {a, b}, x]; fit /@ fit["Properties"] any of it of interest to you? $\endgroup$ – chris Mar 25 '15 at 18:25
  • 1
    $\begingroup$ it seems fit["ParameterTableEntries"] is what you want? $\endgroup$ – chris Mar 25 '15 at 18:30
  • $\begingroup$ no Chris, this is not what I want, as I have pointed out in my original message this function gives only the numerical values, not the names of the paramters, which is what I am ultimately after. $\endgroup$ – Rho Phi Mar 25 '15 at 22:42
  • 1
    $\begingroup$ this then: 'fit["ParameterTable"] // First // First // Flatten // Take[#, {1, 6}] &' $\endgroup$ – chris Mar 25 '15 at 23:20
6
$\begingroup$

Assuming you have typed

 fit = NonlinearModelFit[{{0, 1}, {1, 2}, {3, 3}}, a + b*x, {a, b}, x]

Using this great answer

you can type

  StringProperties[NonlinearModelFit]

{BestFit,BestFitParameters,Data,Function,Response,FitResiduals,StandardizedResiduals,StudentizedResiduals,ANOVATable,ANOVATableDegreesOfFreedom,ANOVATableEntries,ANOVATableMeanSquares,ANOVATableSumsOfSquares,EstimatedVariance,CorrelationMatrix,CovarianceMatrix,ParameterBias,ParameterConfidenceIntervals,ParameterConfidenceIntervalTable,ParameterConfidenceIntervalTableEntries,ParameterConfidenceRegion,ParameterErrors,ParameterPValues,ParameterTable,ParameterTableEntries,ParameterTStatistics,CurvatureConfidenceRegion,FitCurvatureTable,FitCurvatureTableEntries,MaxIntrinsicCurvature,MaxParameterEffectsCurvature,HatDiagonal,SingleDeletionVariances,MeanPredictionBands,MeanPredictionConfidenceIntervals,MeanPredictionConfidenceIntervalTable,MeanPredictionConfidenceIntervalTableEntries,MeanPredictionErrors,PredictedResponse,SinglePredictionBands,SinglePredictionConfidenceIntervals,SinglePredictionConfidenceIntervalTable,SinglePredictionConfidenceIntervalTableEntries,SinglePredictionErrors,AdjustedRSquared,AIC,AICc,BIC,RSquared}

then you can type

StringProperties[NonlinearModelFit, All]

and get

Mathematica graphics

You will easily see that what you want is

  fit["ParameterTableEntries"] 

( 1.14286 0.225877 5.05964 0.124222 0.642857 0.123718 5.19615 0.121038 )

Update

If you want the headers this ought to do it

 fit["ParameterTable"] // First // First // Flatten // 
 Take[#, {1, 6}] &
$\endgroup$
  • $\begingroup$ Great way to get the information on the parameters, but I am not after the table entries, I am after the table headings, i.e. the names of the fit parameters. I think there is no way to miss that "parameters names" is what I am after, so I have to down-vote this answer. Sorry. $\endgroup$ – Rho Phi Mar 25 '15 at 22:44
  • $\begingroup$ Dear Chris, Thanks for this attempt. Your {1,6} seems to be specific to a case you were trying, as it does not work on the example I posted. I think is more general to do Drop[(%["ParameterTable"] // First // First)[[All, 1]], 1] which returns the whole column of parameters. $\endgroup$ – Rho Phi Mar 26 '15 at 8:44
  • $\begingroup$ @RobertoFranceschini well you can now answer your own question. $\endgroup$ – chris Mar 26 '15 at 9:15
1
$\begingroup$
data = Table[{x, Exp[.2 + .3 x + .1 Sin[x] + RandomReal[{-.2, .2}]]},
             {x, RandomReal[5, 100]}]; 
nlm = NonlinearModelFit[data, Exp[a + b Sin[x] + c Cos[x]], {a, b, c}, x];
pt = nlm["ParameterTable"];

You can also use Part as follows to access the row labels, column labels and the content of pt:

rowlabels = Sequence[1, 1, 2 ;;, 1];
collabels = Sequence[1, 1, 1, 2 ;;];
content = Sequence[1, 1, 2 ;;, 2 ;;];

pt[[rowlabels]]
(* {a, b, c} *)

pt[[collabels]]
(* {"Estimate", "Standard Error", "t-Statistic", "P-Value"} *)

pt[[content]]
(* {{1.00159, 0.0252967, 39.5938, 1.10726*10^-61},
    {-0.375734, 0.0304626, -12.3343, 1.3907*10^-21},
    {-0.157534, 0.0357183, -4.41046, 0.0000267067}} *)

pt[[content]] == nlm["ParameterTableEntries"]
(* True *)

Row[Labeled[#, #2, Top] & @@@ {{pt,"ParameterTable\n"},
    {MapAt[Style[2 #, Red, 20] &, pt, {{1, 1, 2, 4}}], 
     "ParameterTable\nwith part {1,1,2,4} modified"}}, Spacer[10]]

enter image description here

$\endgroup$
1
$\begingroup$
Drop[(%["ParameterTable"] // First // First)[[All, 1]], 1]
$\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.