0
$\begingroup$

In R, I can fit a Probability Density Function to some empirical data using the following code:

energy <- rnorm(30) * 20
dens <- density(energy)
sum(dens$y)*diff(dens$x[1:2])
hist(energy,probability=TRUE)
lines(density(energy),col="red")

This produces the following graph of the Probability Density Function (PDF):

enter image description here

Howevever, I would like to fit a student-t distribution to this data instead. I'm wondering if its possible to do this and if its possible to plot the result like in the diagram above?

$\endgroup$
3
  • 1
    $\begingroup$ 'Fit a distribution to data' is equivalent to 'estimate the parameters from data'. Some common methods include maximum likelihood or method of moments. In R see, for example, the fitdistr function in MASS, which comes with R (?MASS::fitdistr), which has an example of fitting a t-distribution. It's certainly possible to do this with a t-distribution and plot the fitted distribution. However, see the warning in the example I mentioned. $\endgroup$
    – Glen_b
    Commented Oct 21, 2013 at 23:25
  • 1
    $\begingroup$ For threads on this topic, please search our site. $\endgroup$
    – whuber
    Commented Oct 21, 2013 at 23:29
  • $\begingroup$ In addition, questions that are only about how to do something in R, when the OP does not have a substantive statistical question, are off-topic for CV (see our help page). That is, this Q would be off-topic even if it weren't a duplicate. Note that some of such questions might be on-topic on Stack Overflow, but they need to be legitimate programming questions, & not just 'what is the package / function for this'. $\endgroup$ Commented Oct 21, 2013 at 23:37

1 Answer 1

3
$\begingroup$

Have a look at function fit.st in package QRM.

library(QRM)
fit.st(energy )
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.