How to fit normal distribution with respect to frequency and intensity in R?

青春壹個敷衍的年華 提交于 2019-12-24 20:17:35

问题


I have a list of data

frequency x1,x2,...,xn
     i.e. 10,20,...,5000.
Intensity y1,yx,...,yn
          0,0,...,50,60,50,...,0

where I want to fit a normal distribution to the data.

I found some website online such as (http://www.di.fc.ul.pt/~jpn/r/distributions/fitting.html) through the procedure like,

my_data <- rnorm(250, mean=1, sd=0.45)# unkonwn distribution parameters
fit <- fitdistr(my_data, densfun="normal")

but obviously, those methods won't work.

How to fit the above data to a normal distribution?


回答1:


You can use the maximum likelihood function, mle, to solve this problem. Here is how you would do that:

my_data <- rnorm(250, mean=1, sd=0.45)# unkonwn distribution parameters

logLik <- function(sigma, mu){
  ll <- vapply(my_data,
               function(x) dnorm(x, mean = mu, sd = sigma),
               FUN.VALUE = numeric(1))
  -sum(log(ll))
}

mle(logLik, start = list(sigma = 1, mu = 1))

mle requires a log-likehood function that it uses to determine the optimal parameters (which in the case of a normal distribution are mu (mean) and sigma (st. dev.)). It takes the negative sum of the log-likelihood -sum(log(ll)) as part of a numerical procedure to find the best parameters for the distribution. It then returns the estimated parameters:

Call:
mle(minuslogl = logLik, start = list(sigma = 1, mu = 1))

Coefficients:
    sigma        mu 
0.4595003 0.9724402 


来源:https://stackoverflow.com/questions/54850011/how-to-fit-normal-distribution-with-respect-to-frequency-and-intensity-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!