1

Possible Duplicate:
Fitting a density curve to a histogram in R
best fitting curve from plot in R

I have a set of data that when plotted in a histogram is a Gaussian distribution. I have read the data in from a .csv file that looks like this:

"values"
1.29989
1.15652
1.27818
1.19699
1.28243
1.19433
1.10991
...

using data<-read.csv("~/peak.csv") ... so I create a histogram using hist(data$values). I want to be able to fit a Gaussian to this histogram and compare the fitted function's sigma and mean to the sigma and mean calculated from the data.

Everywhere that I have looked mentions nls and glm but I cannot figure out how to use these functions to fit a Gaussian to a histogram, even after doing ?nls and ?glm. Please help?

Community
  • 1
  • 1
user2009074
  • 13
  • 1
  • 3

1 Answers1

5

If you want to use the built in functions you can do it like this:

library("MASS")
data<-read.csv("~/peak.csv")
fitdistr(data, "normal")

Just keep in mind that for a gaussian this is just calculating the mean and standard deviation.

kith
  • 5,486
  • 1
  • 21
  • 21