paroussisc / stats

Repo to track the material I cover on Wednesdays
MIT License
1 stars 0 forks source link

Core Statistics - Chapter 4 - Exercises #10

Open paroussisc opened 6 years ago

paroussisc commented 6 years ago

Chapter 4 solutions.

paroussisc commented 6 years ago

screenshot from 2018-10-24 09-46-51

20181031_081728

paroussisc commented 6 years ago

screenshot from 2018-10-24 09-50-50

20181031_081803

paroussisc commented 6 years ago

screenshot from 2018-10-24 09-51-43

20181024_094822

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)
paroussisc commented 6 years ago

screenshot from 2018-10-24 09-52-39

20181031_092829