Re: Generating best-fit line formula for arbitrary list
- To: mathgroup at smc.vnet.net
- Subject: [mg103380] Re: Generating best-fit line formula for arbitrary list
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sat, 19 Sep 2009 05:26:08 -0400 (EDT)
- References: <h8vkcn$8sl$1@smc.vnet.net>
On 2009.09.18. 11:37, Kelly Jones wrote:
> Mathematica's Fit function can find the best-fit line for a given List:
>
> Fit[Table[Prime[n],{n,1,20}],{1,x},x]
>
> I want Mathematica to spit out the formula for linear regression for
> an arbitrary list. This fails:
>
> Fit[s,{1,x},x]
>
> since "First argument s in Fit is not a list or a rectangular array".
>
> This works:
>
> t = Table[s[n],{n,1,20}]
> Fit[t,{1,x},x]
>
> but is ugly and unhelpful, since it mentions each of the 20 terms
> individually, and doesn't generalize to an arbitrary-size list.
>
> I'm looking for things like Mean[t] or Apply[Plus,t^2] in the answer.
>
> Can I make Mathematica give me the general formula here?
>
I think the simple answer here is no, you can't. Why don't you look up
the answer in a textbook/encyclopedia?
http://mathworld.wolfram.com/LeastSquaresFitting.html