问题描述
我有一个数据列表
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?
推荐答案
您可以使用最大似然函数 mle
解决此问题。这是您的操作方法:
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
需要使用对数似然函数来确定最佳参数(在正态分布的情况下为 mu
(平均值)和 sigma
(开发人员))。它采用对数可能性 -sum(log(ll))
的负和作为数值过程的一部分,以找到最佳分布参数。然后返回估计的参数:
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
这篇关于如何针对R中的频率和强度拟合正态分布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!