Open paroussisc opened 6 years ago
I also used R
to verify my workings:
pdf <- function(x, y, alpha, beta)
{
k <- (alpha + 1) * (beta + 1)
return(k * x ^ alpha * y ^ beta)
}
nll <- function(par, x, y)
{
alpha <- par[1]
beta <- par[2]
return (-sum(log(pdf(x, y, alpha, beta))))
}
x <- runif(10,-0.1, 0.1) + 0.5
y <- runif(10,-0.1, 0.1) + 0.2
par <- c(0.1, 0.1)
o <- optim(par, nll, x = x, y = y)
a <- o$par[1]
b <- o$par[2]
print("optim vs analytical:")
print(-10 / (sum(log(x))) - 1 - a)
print(-10 / (sum(log(y))) - 1 - b)
Chapter 4 solutions.