From: Jouni Helske <jounihelske_at_gmail.com>

Date: Mon, 30 Apr 2012 14:37:19 +0300

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 30 Apr 2012 - 12:09:02 GMT

Date: Mon, 30 Apr 2012 14:37:19 +0300

Dear all,

I'd like to discuss about a possible bug in function StructTS of stats package. It seems that the function returns wrong value of the log-likelihood, as the added constant to the relevant part of the log-likelihood is misspecified. Here is an simple example:

*> data(Nile)
*

> fit <- StructTS(Nile, type = "level")

> fit$loglik

[1] -367.5194

When computing the log-likelihood with other packages such as KFAS and FKF, the loglikelihood value is around -645.

For the local level model, the likelihood is defined by -0.5*n*log(2*pi) - 0.5*sum(log(F_t) + v_t^2/sqrt(F_t)) (see for example Durbin and Koopman (2001, page 30). But in StructTS, the likelihood is computed like this:

loglik <- -length(y) * res$value + length(y) * log(2 * pi),

where the first part coincides with the last part of the definition, but the constant part has wrong sign and it is not multiplied by 0.5. Also in case of missing observations, I think there should be sum(!is.na(y)) instead of length(y) in the constant term, as the likelihood is only computed for those y which are observed.

This does not affect in estimation of model parameters, but it could have effects in model comparison or some other cases.

Is there some reason for this kind of constant, or is it just a bug?

Best regards,

Jouni Helske

PhD student in Statistics

University of Jyväskylä

Finland

[[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 30 Apr 2012 - 12:09:02 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

*
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.
Archive generated by hypermail 2.2.0, at Thu 17 May 2012 - 11:31:14 GMT.
*

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel.
Please read the posting
guide before posting to the list.
*