Helena Richter
2009-Feb-28 13:08 UTC
[R] Implementation of quasi-bayesian maximum likelihood estimation for normal mixtures
Hi, as you can see in the topic, I am trying to fit a normal mixture distribution with the approach suggested by Hamilton (1991). Since I couldn't find any existing packages including the quasi-bayesian mle, I have to write my own function. Unfortunately, I have absolutely no experience in doing this. If you're not familiar with the QB-MLE, I attached the formula as pdf. The idea is to extend the usual MLE with prior beliefs about the values sigma_n and sigma_b. My priors are already included in the code below. I intend to try a mixture of two normal distributions with same mean, and variances 1 and 5 as starting values. This is what I've done so far: > R <-read.table("C:\\...\\rendite.txt", header=F) > qbmle <- function(p, data){ mu <- mean(data); (-sum(log(p[1]/p[2]*exp(-0.5*(data-mu)^2/p[2]^2)+(1-p[1])/p[3]*exp(-0.5*data^2/p[3]^2)))-2.772*log(p[2]^2)-2.772*log(p[3]^2) - 2.772/p[2]^2 - 13.86/p[3]^2 )} > start <-c(0.9, 1, 5) > out <- nlm(qbmle, start, data=R) The result is: error in nlm(...): non-finite value for nlm, plus a lot of warnings, and the following output: > out $minimum [1] -27513.60 $estimate [1] 3.478212e+04 -2.146767e+03 -3.806269e-02 $gradient [1] -5.971628e-02 1.939856e-03 -2.946156e+02 $code [1] 5 $iterations [1] 49 So, what did I do wrong? How can I implement any non-negative constraints, and a restriction for p to be between 0 and 1? I'm sorry to bother you with such a beginner's question and am very helpful for any remarks. I don't have to use the qb-mle so if you think there's a better way to do the estimation tell me. Thanks a lot, Helena -------------- next part -------------- A non-text attachment was scrubbed... Name: formula.pdf Type: application/pdf Size: 33969 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090228/82248d12/attachment-0002.pdf>
Seemingly Similar Threads
- Fitting distributions to financial data using volatility model to estimate VaR
- Is it possible to use EGARCH and GJR in R?
- different results across versions for glmer/lmer with the quasi-poisson or quasi-binomial families: the lattest version might not be accurate...
- rails-y way to handle quasi-numeric type
- Quasi-binomial GLM and model selection