Reputation: 83
Consider the density f arining from a mixture f(x) = πf1(x) + (1 − π)f2(x) where f1 ∼ N(0, 1) and f2 ∼N(μ,1). Write an R function for the log-likelihood function of the parameter (π, μ) that takes as input a vector of observations x from f
I know that to incorporate f(x) into the log function, you use the dnorm function to get f1 and f2.
f1 = dnorm(x, 0, 1)
f2 = dnorm(x, u, 1)
and then we would do
LL=sum(log(f(x))
But overall I am unsure how to actually execute this problem. Any help would be greatly appreciated. Thanks!
Upvotes: 1
Views: 223
Reputation: 101024
From the link https://stephens999.github.io/fiveMinuteStats/intro_to_em.html, I guess you might have already know how to construct the log-likelihood function.
Below is an example that might work for your goal
f <- function(X,p,u) sum(log(p*dnorm(X,0,1) + (1-p)*dnorm(X,u,1)))
Upvotes: 1