From david.meyer at wu-wien.ac.at  Sat May 17 16:10:12 2008
From: david.meyer at wu-wien.ac.at (david.meyer at wu-wien.ac.at)
Date: Sat, 17 May 2008 16:10:12 +0200 (CEST)
Subject: [Rd] HoltWinters fitted level parameter not bounded between 0
	(PR#11478)
Message-ID: <20080517141012.0D0B2282EFF1@mail.pubhealth.ku.dk>

An update on this:

I just patched HoltWinters() to use optimize() in the univariate case, 
and it now computes the correct value.

David

John Bodley wrote:
> Hi,
> 
> Thanks for the quick response. I upgraded by version of R on Windows to the
> latest (2.7.0) and re-ran the analysis and get the same result of 48.87989.
> 
> The original time series was a non-regular zoo() object and I converted it
> to a time series with daily granularity by setting the values of the
> undefined dates to zero. I initially wondered if the zeros were maybe an
> issue, i.e., I know multiplicative Holt-Winters requires non-negative
> values, so I tried shifting the values, which should change the level,
> though the fitted alpha values should be the same:
> 
>> delta <- 10 ^ seq(-3, 0);
>> sapply(delta, function(delta) HoltWinters(x + delta, beta = 0, gamma =
> 0)$alpha);
>      alpha      alpha      alpha      alpha
> 48.8798912 48.8798912 48.8798912  0.6881547
> 
> Note that by applying a shift,  I also obtained varying values of alpha,
> similar to that of what David achieved by changing the initial conditions.
> 
> Thanks
> -John
> 
> On Fri, May 16, 2008 at 4:20 AM, David Meyer <david.meyer at wu-wien.ac.at>
> wrote:
> 
>> I get John's value (48.8789) in 2.7.0 and R-devel (both on Ubuntu). Really
>> seems to be a numeric issue:
>>
>>> HoltWinters(x, beta = 0, gamma = 0)$alpha
>>   alpha
>> 48.87989
>>
>>> HoltWinters(x * 1.0000000001, beta = 0, gamma = 0)$alpha
>>    alpha
>> 0.6881547
>>
>>> HoltWinters(x * 1.00000000001, beta = 0, gamma = 0)$alpha
>>   alpha
>> 48.87989
>>
>> Providing starting values seems to help, but not always:
>>
>>> HoltWinters(x, beta = 0, gamma = 0, l.start = 0.00001)$alpha
>>   alpha
>> 48.88999
>>> HoltWinters(x, beta = 0, gamma = 0, l.start = 0.0001)$alpha
>>    alpha
>> 0.6880582
>>
>> Yes, it's easy to use optimize() instead of optim() in the univariate
>> cases, will do.
>>
>> David.
>>
>>
>> Prof Brian Ripley wrote:
>>
>>> It doesn't do it on my system (I get a value of about 0.688 in R 2.7.0
>>> patched on Linux), and 2.5.1 is not current.  Does a better starting value
>>> help?
>>>
>>> However, HoltWinters is using optim() in a case it is not designed for
>>> (one-dimensional optimization): see the note on its help page.  I think this
>>> could easily be changed, but as HoltWinters is contributed code I am Cc:ing
>>> the author for comment.
>>>
>>> On Fri, 16 May 2008, john.bodley at gmail.com wrote:
>>>
>>>  Full_Name: John Bodley
>>>> Version: 2.5.1 (2007-06-27)
>>>> OS: Windows XP
>>>> Submission from: (NULL) (12.144.182.66)
>>>>
>>>>
>>>> I was fitting a number of time series in R using the stats::HoltWinters
>>>> method
>>>> to define a single exponential smoothing model, i.e., beta = gamma = 0.
>>>>
>>>> I came across an example where the fitted value of alpha was not defined
>>>> in the
>>>> [0, 1] interval which seems to violate the lower and upper bound
>>>> constraints
>>>> used for the optim method. On my computer the following code returns a
>>>> value of
>>>> 48.87989.
>>>>
>>>> R code:
>>>>
>>>> x <- c(
>>>> 0,
>>>> 0.000843170320404722,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0.0103773584905660,
>>>> 0.00832466181061394,
>>>> 0.0038560411311054,
>>>> 0,
>>>> 0,
>>>> 0.00484966052376334,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0.00274348422496571,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0.0207064555420219,
>>>> 0.0334975369458128,
>>>> 0.0334975369458128,
>>>> 0.00338983050847458,
>>>> 0.00483675937122128,
>>>> 0,
>>>> 0,
>>>> 0.00224971878515186,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0.00135685210312076,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0.0035377358490566,
>>>> 0.0035377358490566,
>>>> 0.00501002004008016,
>>>> 0.0107632093933464,
>>>> 0,
>>>> 0,
>>>> 0.0143329658213892,
>>>> 0.0330459770114943,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0,
>>>> 0.0109890109890110,
>>>> 0,
>>>> 0.00118623962040332,
>>>> 0.007380073800738,
>>>> 0.00695410292072323,
>>>> 0.0104895104895105,
>>>> 0.00278551532033426,
>>>> 0.00278551532033426
>>>> );
>>>>
>>>> # Single exponential smoothing
>>>> m <- stats::HoltWinters(x, beta = 0, gamma = 0);
>>>> m$alpha
>>>>
>>>> ______________________________________________
>>>> R-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>>
>> --
>> Dr. David Meyer
>> Department of Information Systems and Operations
>>
>> Vienna University of Economics and Business Administration
>> Augasse 2-6, A-1090 Wien, Austria, Europe
>> Tel: +43-1-313 36 4393
>> Fax: +43-1-313 36 90 4393
>> HP:  http://wi.wu-wien.ac.at/~meyer/ <http://wi.wu-wien.ac.at/%7Emeyer/>
>>
> 

-- 
Dr. David Meyer
Department of Information Systems and Operations

Vienna University of Economics and Business Administration
Augasse 2-6, A-1090 Wien, Austria, Europe
Tel: +43-1-313 36 4393
Fax: +43-1-313 36 90 4393
HP:  http://wi.wu-wien.ac.at/~meyer/



[Rd] HoltWinters fitted level parameter not bounded between 0 (PR#11478)
david.meyer at wu-wien.ac.at