R 拟合对数正态分布或泊松分布
我有一个1096个数字的向量,是一个测量站在3年内测得的氮氧化物的日平均浓度。 您可以观察图像中的分布类型: 我使用以下命令来绘制直方图:R 拟合对数正态分布或泊松分布,r,normal-distribution,data-fitting,poisson,model-fitting,R,Normal Distribution,Data Fitting,Poisson,Model Fitting,我有一个1096个数字的向量,是一个测量站在3年内测得的氮氧化物的日平均浓度。 您可以观察图像中的分布类型: 我使用以下命令来绘制直方图: NOxV<-scan("NOx_Vt15-17.txt") hist.NOxVt<-hist(NOxV, plot = FALSE, breaks = 24) plot(hist.NOxVt, xlab = "[NOx]", ylab = "Frequenze assolute", main = "Istogramma freq. ass.
NOxV<-scan("NOx_Vt15-17.txt")
hist.NOxVt<-hist(NOxV, plot = FALSE, breaks = 24)
plot(hist.NOxVt, xlab = "[NOx]", ylab = "Frequenze assolute", main = "Istogramma freq. ass. NOx 15-17 Viterbo")
points(hist.NOxVt$mids, hist.NOxVt$counts, col= "red")
NOxVR随附的MASS
软件包中有一个内置功能fitdire
:
生成要查看的数据示例(查看参数以获得与图片类似的内容):
my_poisson = function(params, x){
exp(-params)*params^x/factorial(x)
}
y<-hist.NOxVt$counts/1096;
x<-hist.NOxVt$mids;
z <- nls( y ~ exp(-a)*a^x/factorial(x), start=list(a=1) )
set.seed(101)
z <- rlnorm(1096,meanlog=4.5,sdlog=0.8)
library(MASS)
f1 <- fitdistr(z,"lognormal")
f2 <- fitdistr(z,"Gamma")
hist(z,col="gray",breaks=50,freq=FALSE)
with(as.list(coef(f1)),
curve(dlnorm(x,meanlog,sdlog),
add=TRUE,col="red",lwd=2))
with(as.list(coef(f2)),
curve(dgamma(x,shape=shape,rate=rate),
add=TRUE,col="blue",lwd=2))