Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Weights option to Regress command not behaving as expected

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70804] Weights option to Regress command not behaving as expected
  • From: Stern <nycstern at gmail.com>
  • Date: Sat, 28 Oct 2006 05:21:42 -0400 (EDT)
  • References: <c2baae590610041434g12698b38uef586f9c10381b1d@mail.gmail.com>

I am looking to run regressions to fit a curve to a time series, and I
want older data to weigh less in the fitting than newer data does.
However, I can't seem to make this work as expected.

For the sake of example, imagine 100 periods with a binary time series
-- it's 0 until time 50, then 1 until time 100.

binaryjumpdata =
Transpose[{Table[x,{x,1,100}],Flatten[Union[{Table[0,{50}],Table[1,{50}]}]]}];

 simplefit =
  BestFit/.Regress[binaryjumpdata,{1,x},x,RegressionReport\[Rule]{BestFit}];

Out = -0.257576+0.0150015 x

Fine. Now, compare the following two weighting functions:

forwardweights = Table[1/n, {n, 1, 100}]);

backweights = Table[1/(100-n+1), {n, 1, 100}]);

forwardweights drops from 1 to .01, while backweights runs the other
way, from .01 to 1. Applying these two weighting lists to the
binaryjumpdata curve and running the Regress function *should* produce
different best fit line. Forwardweights should produce a lower line,
and backweights should produce a higher one. However,

weightedfit =
  BestFit/.Regress[binaryjumpdata,{1,x},x,RegressionReport\[Rule]{BestFit},
      Weights->forwardweights]

and

reverseweightedfit =
  BestFit/.Regress[binaryjumpdata,{1,x},x,RegressionReport\[Rule]{BestFit},
      Weights\[Rule]backweights]

The answer is different from that of the unweighted series, as
expected, but both the forward and reverse application of the weights
produce the exact same output -- -0.0941409+0.0117652  x

Clearly, the Weights command is not doing what I expect. What am I missing?

Thanks in advance for any help.

Michael Stern


  • Prev by Date: Re: DownValues and Cases
  • Next by Date: Re: Bug in RowReduce of a matrix with symbolic entries
  • Previous by thread: Re: DisplayTogether & PlotLegend incompatibility
  • Next by thread: "unload" a package