Fitting t-distribution in R: scaling parameter

How do I fit the parameters of a t-distribution, i.e. the parameters corresponding to the ‘mean’ and ‘standard deviation’ of a normal distribution. I assume they are called ‘mean’ and ‘scaling/degrees of freedom’ for a t-distribution?

The following code often results in ‘optimization failed’ errors.

fitdistr(x, "t")

Do I have to scale x first or convert into probabilities? How best to do that?


fitdistr uses maximum-likelihood and optimization techniques to find parameters of a given distribution. Sometimes, especially for t-distribution, as @user12719 noticed, the optimization in the form:

fitdistr(x, "t")

fails with an error.

In this case you should give optimizer a hand by providing starting point and lower bound to start searching for optimal parameters:

fitdistr(x, "t", start = list(m=mean(x),s=sd(x), df=3), lower=c(-1, 0.001,1))

Note, df=3 is your best guess at what an “optimal” df could be. After providing this additional info your error will be gone.

Couple of excerpts to help you better understand the inner mechanics of fitdistr:

For the Normal, log-Normal, geometric, exponential and Poisson distributions the closed-form MLEs (and exact standard errors) are used, and start should not be supplied.

For the following named distributions, reasonable starting values will be computed if start is omitted or only partially specified: “cauchy”, “gamma”, “logistic”, “negative binomial” (parametrized by mu and size), “t” and “weibull”. Note that these starting values may not be good enough if the fit is poor: in particular they are not resistant to outliers unless the fitted distribution is long-tailed.

Source : Link , Question Author : user12719 , Answer Author : Sergey Bushmanov

Leave a Comment