Steinar
2011-Dec-17 09:57 UTC
[R] Problem with reproducing log likelihood estimated with ghyp package
I was playing around with the ghyp package and simulated series of t-distributed variables when suddenly i was not able to reproduce the log likelihood values reported by the package. When trying to reproduce the likelihood values, I summed the log(dt(x,v)) values and it worked with some simulated series but not all. Is there any obvious flaws with this script? library("ghyp") series_1=rt(10000,4) #simulating 10000 relation of student t variables with df=4 #Which implies a standrad deviation equal to sqrt(2) series_2=series_1/sqrt(2)*5 #To get student t distributed variabler with standard #deviation equal to 5 I rescale the first series #When i check the first series with the ghyp package, the result coincides with #the sum of log likelihood calculated with dt(x, df, ncp, log = FALSE) fit_1=fit.tuv(series_1, silent=T, symmetric=T) fit_1 sum(log(dt(series_1,coef(fit_1)$nu,0))) #The two log likelihood estimates is approximatly equal, and the parameters are #sensible. #When I check series 2, i get a very different result. The estimate for mu and nu #is still sensible, but the log likelihood is very different from what i get with #dt(x, df, ncp, log = FALSE) fit_2=fit.tuv(series_2, silent=T, symmetric=T) fit_2 sum(log(dt(series_2,coef(fit_2)$nu,0))) #This is very different -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-reproducing-log-likelihood-estimated-with-ghyp-package-tp4207833p4207833.html Sent from the R help mailing list archive at Nabble.com.
peter dalgaard
2011-Dec-18 09:53 UTC
[R] Problem with reproducing log likelihood estimated with ghyp package
On Dec 17, 2011, at 10:57 , Steinar wrote:> I was playing around with the ghyp package and simulated series of > t-distributed variables when suddenly i was not able to reproduce the log > likelihood values reported by the package. When trying to reproduce the > likelihood values, I summed the log(dt(x,v)) values and it worked with some > simulated series but not all. > > Is there any obvious flaws with this script?Try rethinking your definition of the likelihood. I would expect that the likelihood depends on the scale and position parameters via (x-mu)/sigma or so. As far as I can tell, you are de facto setting mu=0 and sigma=1, which might sort of work if you are simulating with mu=0 and sigma=1, but not when sigma=5.> library("ghyp") > series_1=rt(10000,4) > > #simulating 10000 relation of student t variables with df=4 > #Which implies a standrad deviation equal to sqrt(2) > > series_2=series_1/sqrt(2)*5 > > #To get student t distributed variabler with standard > #deviation equal to 5 I rescale the first series > > #When i check the first series with the ghyp package, the result coincides > with > #the sum of log likelihood calculated with dt(x, df, ncp, log = FALSE) > > fit_1=fit.tuv(series_1, silent=T, symmetric=T) > fit_1 > sum(log(dt(series_1,coef(fit_1)$nu,0))) > > #The two log likelihood estimates is approximatly equal, and the parameters > are > #sensible. > > #When I check series 2, i get a very different result. The estimate for mu > and nu > #is still sensible, but the log likelihood is very different from what i get > with > #dt(x, df, ncp, log = FALSE) > > fit_2=fit.tuv(series_2, silent=T, symmetric=T) > fit_2 > sum(log(dt(series_2,coef(fit_2)$nu,0))) > > #This is very different > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Problem-with-reproducing-log-likelihood-estimated-with-ghyp-package-tp4207833p4207833.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Steinar
2011-Dec-18 16:20 UTC
[R] Problem with reproducing log likelihood estimated with ghyp package
Thank you very much for your answer. I did not think about the scale influencing the log likelihood score. The first simulation was zero mean student t distributed variables with variance=v/(v-2). And as far as I can understand, that is exactly what dt(x,v) assumes. This also gave me the same result as the ghyp package. Scaling the variance to get t distributed variables with variance=5^2 gave a totally different likelihood score for the reason you mentioned. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-reproducing-log-likelihood-estimated-with-ghyp-package-tp4207833p4211249.html Sent from the R help mailing list archive at Nabble.com.