Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation of AR1 likelihood in BayesianTools #169

Closed
florianhartig opened this issue Nov 13, 2018 · 1 comment
Closed

Calculation of AR1 likelihood in BayesianTools #169

florianhartig opened this issue Nov 13, 2018 · 1 comment
Labels

Comments

@florianhartig
Copy link
Owner

From a user

I think that there should be a n factor in front of the term log(2*pi), due to the product of n gaussian densities.

I noticed this problem when trying to write my own likelihood function a() instead of a numeric constant a.

function (predicted, observed, sd, a)
{
if (any(is.na(observed)))
stop("AR1 likelihood cannot work with NAs included, split up the likelihood")
if (sd <= 0)
return(-Inf)
if (abs(a) >= 1)
return(-Inf)
n = length(observed)
res = predicted - observed
ll = 0.5 * (-log(2 * pi) - n * log(sd^2) + log(1 - a^2) -
(1 - a^2)/sd^2 * res[1]^2 - 1/sd^2 * sum((res[2:n] -
a * res[1:(n - 1)])^2))
return(ll)
}
<environment: namespace:BayesianTools>

@florianhartig
Copy link
Owner Author

florianhartig commented Nov 13, 2018

You're right, there was an n missing, it should have been

  ll =  0.5 * (  - n * log(2*pi)
                 - n * log(sd^2) 
                 + log( 1- a^2 )
                 - (1- a^2) / sd^2 * res[1]^2
                 - 1 / sd^2 * sum( (res[2:n] - a * res[1:(n-1)])^2)

The issue was fixed with commit
9bb16f9 to the master branch

Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant