MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Generating best-fit line formula for arbitrary list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103379] Re: Generating best-fit line formula for arbitrary list
  • From: Erik Max Francis <max at alcyone.com>
  • Date: Sat, 19 Sep 2009 05:25:56 -0400 (EDT)
  • References: <h8vkcn$8sl$1@smc.vnet.net>

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?

It's not really clear what you're looking for.  Naturally if you feed it 
arbitrary data it's going to give you complex answers.  It's showing 
what you did with arbitrary data.  It's ugly because it's got a lot of 
work to do and it's got only symbolic data to work with.  Your other 
examples look nicer simply because there was less work for Mathematica 
to do to get them.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Never do an enemy a small injury.
    -- Nicolo Machiavelli


  • Prev by Date: Re: Generating best-fit line formula for arbitrary list
  • Next by Date: Modifying Default Stylesheet?
  • Previous by thread: Re: Generating best-fit line formula for arbitrary list
  • Next by thread: Find Selected Function?