At 08:50 AM 5/31/00 +0100, John.Gavin@ubsw.com wrote:
>
>Hi,
>
>How can I fit a t-distribution to a sample?
With some difficulty.
>
>For example,
>
>dat <- rt(1000, 5) * 5 + 10
>tfit <- function(df, x) sum(log( dt( ( x - 10 ) / 5 , df) ) )
>optimize(tfit, c(0,100), x = dat , max = T )$maximum
>
>works for a random sample from t-distribution,
>in that it returns an estimate of the degrees of freedom,
>that seems fairly stable, when the mean and st dev are known.
One dimensional optimization is usually a relatively simple problem, though
in this case the objective function can have multiple stationary points.
>If the mean, variance and degrees of freedom are unknown
>then the following example doesnt seem to work well
>
>mu <- 7 ; sd <- 3 ; df <- 10
>dat <- data.frame(xx = rt(1000, df) * sd + mu )
>startVals <- list(mu = mean(dat$xx) , sd = stdev(dat$xx) , df = 20)
>ms( ~ -log(dt( (xx - mu) / sd , df) ) , data = dat, start = startVals,
trace =
>F)
>rm(dat, tfit, mu, sd, df, startVals)
what you call mu and sd are really just location and scale parameters.
Your formula for the negative log-likelihood is incorrect and should be
~ -log(dt((xx - mu)/sd, df)) + log(sd)
but I very much doubt that will solve the problem completely. Once the df
parameter of the t-distribution climbs above about 8 there is really very
little shape difference in the t family so you will most likely need
enormous samples to fix an estimate of it. For fixed df the location and
scale parameters should be relatively easy to estimate. In fact this gives
quite a good robust estimator of location and scale.
>VR3, vol 1, page 263 offers a similar example for a mixture model
of normals. This is the catch. We fixed our df at the easiest possible
value, infinity.
>but can someone suggest a way of adding partial derivatives,
>improving the starting values or improving my code?
Derivatives might help, but I'd re-think the issue about whether you really
need to estimate the df parameter. Even if you do manage to get one your
standard error will be enormous with anything like ordinary samples.
>
>I am using SPlus 2000 R2 on NT4.
>
>Thanks for your time.
>
>Regards,
>
>John.
>
>John Gavin
>Quantitative Risk: Models and Statistics
>UBS Warburg,
>1st floor, 1 Finsbury Ave., London EC2M 2PP.
>john.gavin@ubsw.com
>+44 (0) 20 7567 4289
>
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|