The fitdistr()
function in R is used to fit probability distributions to data.
Here is an example of how to use fitdistr()
to fit a normal distribution to a sample data:
main.r219 chars12 lines
In the above code, we first create a sample data using the rnorm()
function with a mean of 10 and a standard deviation of 2.
We then load the MASS
package which contains the fitdistr()
function.
Lastly, we use fitdistr()
to fit the normal distribution to the data and store the result in the fit
object. We can then view the estimated parameters of the normal distribution using fit$estimate
.
Note that fitdistr()
can be used to fit a variety of different distributions including the gamma distribution, exponential distribution, and Weibull distribution.
gistlibby LogSnag