Group Abstract Group Abstract

Message Boards Message Boards

Does LinearModelFit show the correct equation?

Posted 11 years ago
POSTED BY: Juan David
6 Replies
Posted 11 years ago

If you the objective allows all calculations to be performed in Mathematica (rather than reproduced in Excel), then using the Interpolation function works great:

data = {{0., 0.}, {0.05, 0.4651}, {0.1, 0.6433}, {0.15, 0.7298}, {0.2,
     0.779}, {0.25, 0.81}, {0.3, 0.831}, {0.35, 0.8462}, {0.4, 
    0.8576}, {0.45, 0.8664}, {0.5, 0.8736}, {0.55, 0.8796}, {0.6, 
    0.8848}, {0.65, 0.8895}, {0.7, 0.8941}, {0.75, 0.8989}, {0.8, 
    0.9045}, {0.85, 0.9118}, {0.9, 0.9231}, {0.95, 0.9445}, {1., 1.}};
f = Interpolation[data]
Show[{ListPlot[data], Plot[f[x], {x, 0, 1}, PlotRange -> All]}]
f[0.756]

with output

Interpolation figure

But if you need the fitted equation outside of Mathematica (like in Excel), then determining how Mathematica deals with the interpolation object might be possible but I don't know if that's available. If providing predictions to others is the objective, does turning this into a CDF document achieve that?

POSTED BY: Jim Baldwin
Posted 11 years ago
POSTED BY: Updating Name
Posted 11 years ago

Excellent about the use of StringReplace! I'm embarrassed to say that all these years I've been editing those output equations by hand. Thank you!

I wouldn't necessarily recommend polynomials at all. I should have asked initially how your data was generated. As a statistician, I'm always suspicious of data with such a smooth connected set of points. Is this one run of some experiment? Are the points generated by a much more complex formula and you're trying to approximate that with something that faster to run? Is the process that generates the data inducing a serial correlation? In other words, what is the data generation process? (I ask because LinearModelFit as used assumes that the errors are independent and identically distributed - which is important if you want to make inferences about the parameters or predictions.)

POSTED BY: Jim Baldwin
Posted 11 years ago

Actually, if you use CForm rather than FortranForm, you'll have to do a lot less text editing to get the equation into Excel.

POSTED BY: Jim Baldwin
Posted 11 years ago
Attachments:
POSTED BY: Jim Baldwin
Posted 11 years ago

Hi, Jim! Thank you for your reply. It was very useful.

At first I would like to recommend you this function in case you want to edit an expression in short time:

StringReplace[" 4.5289452342107005e-7 + 15.253009862753892*x - \ 172.24927366903987x2 + 1400.184945935208x**3 - \ 8217.174010285653x4 + 34923.988960709925x**5 - \ 107985.66964678626x6 + - 243429.0999193785x*7 - 398597.880639793x**8 + \ 467992.1952924235x9 - 383346.5309523954x**10 + \ 207812.90625504x11 - 66956.90230299356x**12 + \ 9703.778442430377x13", {"." -> ",", "x" -> "A2", "*" -> "^"}]

"\" at the end of rows has to be removed manually, they appear when you copy text to excel.

Also I would like to discuss about fitting data to polynomia. I assume you suggest an InterpolatingPolinomial. I did it and the results were good, but the expression does not fit well near edges.

enter image description here

¿So what is the correct thing?

Thank you again. Have a nice day.

Attachments:
POSTED BY: Juan David
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard