Thanks for answering, in ret i've the returns of FTSE MIB (the benchmark stock market index in Italy) and i'm estimating the parametres of the distribution of the returns of the index using different methods.
I need the mle and i found this two function and i could not understand why the result were different: it's possibile that i obtain different result because in the mle() i don't need to know the original distribution and in the fitdistr() i don't need to know the function i had to maximize? In addition to that i'm going to use quadratic programming for portfolio optimization. Il Martedì 24 Dicembre 2013 17:53, Ben Bolker <bbol...@gmail.com> ha scritto: Tia Borrelli <tiaborrelli <at> yahoo.it> writes: > > Hello, i'm using R for the exploration of a time series and i'm stuck in a problem with the fitting of the distribution. > What's the difference between "fitdistr" and "mle"? Hard to say without a reproducible example. In the example below the answers are not identical (different starting values etc.) but they're closer than in your example. (I assume that what you're really doing is more complicated than the trivial example shown here, since the MLEs of the Normal distribution parameters are very easy ...) set.seed(101) ret <- rnorm(10000,mean=-1.5e-5,sd=1.69e-2) MASS::fitdistr(ret,densfun="normal") ## mean sd ## 7.419639e-05 1.678380e-02 ## (1.678380e-04) (1.186794e-04) library(stats4) loglink <- function(media=0, devstd=1){ -sum(dnorm(ret, mean=media, sd=devstd, log=TRUE)) } mle(loglink) ## media devstd ## 7.402637e-05 1.680457e-02 > library(MASS) > fitting <- fitdistr(ret,densfun="normal") > print(c(mean(ret),sd(ret))) > ------------------------------------------------------------- > The output of fitdistr is: > mean sd > -1.526547e-05 1.692554e-02 > ( 5.105564e-04) ( 3.610179e-04) > ------------------------------------------------------------- > > library(stats4) > loglink <- function(media=0, devstd=1){ > -sum(dnorm(ret, mean=media, sd=devstd, log=TRUE)) > } > mle(loglink) > ------------------------------------------------------------- > > The output of mle is: > Call: > mle(minuslogl = loglink) > > Coefficients: > media devstd > -1.593559e-05 1.695075e-02 > > Thank you for the help. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.