MathGroup Archive 2006

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

Search the Archive

Re: Weights option to Regress command not behaving as expected


The equivalence of the two weighted results is due to the symmetry in 
the data.  If we break that symmetry by, for instance, replacing the 
first response with a 1, the two weightings provide different results.

In[1]:= << Statistics`LinearRegression`

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

In[3]:= forwardweights = Table[1/n, {n, 1, 100}];

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

In[5]:= newdata = binaryjumpdata;

In[6]:= newdata[[1, 2]] = 1;

In[7]:= BestFit /.
          Regress[newdata, {1, x}, x, RegressionReport -> {BestFit},
            Weights -> forwardweights]

Out[7]= 0.211485 + 0.00591118 x

In[8]:= BestFit /.
          Regress[newdata, {1, x}, x, RegressionReport -> {BestFit},
            Weights -> backweights]

Out[8]= -0.0710847 + 0.0115066 x


Darren Glosemeyer
Wolfram Research

Stern wrote:
> 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: Merging graphic objects, exporting graphics and much more worries...
  • Next by Date: 3 second question
  • Previous by thread: Re: Conceptual Issues with NonlinearRegress[]
  • Next by thread: 3 second question