MathGroup Archive 2001

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

Search the Archive

Re: Fitting data to line with a specific slope

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30629] Re: [mg30618] Fitting data to line with a specific slope
  • From: BobHanlon at aol.com
  • Date: Fri, 31 Aug 2001 19:58:05 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2001/8/31 4:28:34 AM, cdneish at interchange.ubc.ca writes:

>I am attempting to fit my data to a line of the form
>
>    y = -3.2 x + intercept,
>
>but I cannot figure out how to do this with Mathematica.
>
>The function "Fit" takes only basis functions, so I cannot specify that
>I
>would like the slope to be -3.2.  I also tried "NonlinearFit," but the
>following code
>
>    NonlinearFit[data, intercept - 3.2 x, x, intercept]
>
>yielded the following error message:
>
>Tranpose::nmtx : The first two levels of the one-dimensional list {} cannot
>be transposed
>Tranpose::nmtx : The first two levels of the one-dimensional list {-3.2}
>cannot be transposed
>NonlinearFit::lnnosvd : NonlinearFit was unable to obtain the singular
>value
>decomposition for the design matrix of the linear model.
>NonlinearFit::fitfail : The fitting algorithm failed.
>
>
>It is possible that my data does not fit a line with slope -3.2 very well.
>Could this be the source of the errors?
>
>Any advice regarding these problems would be greatly appreciated.
>

I do not encounter the error message that you saw

Needs["Graphics`Colors`"];

data = Table[{x, -3.2x+5+3(2Random[]-1)}, {x, 0, 10}];

intercept = Fit[data /. {x_, y_} :> {x, 3.2x+y}, {1}, x]

4.870101185989491

Plot[-3.2x+intercept, {x, 0, 10}, 
    PlotStyle -> Blue, 
    Epilog -> {Red, AbsolutePointSize[3], Point /@ data}];

Needs["Statistics`NonlinearFit`"];

Clear[intercept];

NonlinearFit[data, -3.2x+ intercept, x, intercept]

4.8701011859894905 - 3.2*x


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: RE: Curl
  • Next by Date: Transparent evalaution of a notebook
  • Previous by thread: Re: Curl
  • Next by thread: Re: Fitting data to line with a specific slope