[R] Fitting 4 moments distribution w/ Mixture Gaussian
Sam R
samuel.penagos at hotmail.com
Mon Mar 14 18:16:48 CET 2011
Hello,
I know that Mclust does the fitting on its own but I am trying to implement
an optimization with the aim to generate a the mixture gaussian with the
combine moments as closed as possible to the moment of my return
distribution.
The objective is to Min Abs((Mean Ret - MeanFit)/Mean Fit) + Abs((Std Ret
-Stdev Fit)/Stdev) + Abs((Sk Ret-Sk fit)/Sk Fit) + Abs((Kurt Ret- Kurt Fit))
Taking into account that I fix the weight between the two gaussians at
(0.2;0.8) I implemented the below code in R:
distance <-function(parameter,x) {
u=mean(x)
s=sd(x)
sk=skewness(x)
kurt=kurtosis(x)
d1=dnorm(x,parameter[1],parameter[2])
d2=dnorm(x,parameter[3],parameter[4])
dfit=0.2d1+0.8d2
ufit=mean(dfit)
sdfit=sd(dfit)
skfit=skewness(fit)
kurtfit=kurtosis(fit)
abs((u-ufit)/ufit)+abs(s-sdfit)/sdfit)+abs((sk-skfit)/skfit)+abs((kurt-kurtfit)/kurtfit))
}
Parameter<-c(0,0.01,0,0.01) ' starting point of the optimization
opp<-optim(parameter,distance,x=conv)
1/ could anybody tell me whether it is the right approach ?
2/ should I add some constraint like
ufit=0.2*mean(d1)+0.8*mean(d2)...
thank you very much in advance for your time and help.
Sam
--
View this message in context: http://r.789695.n4.nabble.com/Fitting-4-moments-distribution-w-Mixture-Gaussian-tp3354436p3354436.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list