简体   繁体   中英

Fit a Weibull cumulative distribution to mass passing data in R

I have some particle size mass-passing cumulative data for crushed rock material to which I would like to fit a Weibull distribution using R. I have managed to do this in Excel using WEIBULL.DIST() function using the cumulative switch set to TRUE.
I then used excel SOLVER to derive the alpha and beta parameters using RMSE to get the best fit. I would like to reproduce the result in R.

(see attached spreadsheet here )

The particle data and cumulative mass passing % is are the following vectors

d.mm <- c(20.001,6.964,4.595,2.297,1.741,1.149,
          0.871,0.574,0.287,0.082,0.062,0.020)
m.pct <- c(1.00,0.97,0.78,0.49,0.27,0.20,0.14,
         0.11,0.07,0.03,0.025,0.00)

This is the plot to which I would like to fit the Weibull result:

plot(log10(d.mm),m.pct)

... computing the function for a vector of diameter values as per the spreadsheet

   d.wei <- c(seq(0.01,0.1,0.01),seq(0.2,1,0.1),seq(2,30,1))

The values I've determined as best for the Weibull alpha and beta in Excel using Solver are 1.41 and 3.31 respectively So my question is how to reproduce this analysis in R (not necessarily the Solver part) but fitting the Weibull to this dataset?

The nonlinear least squares function nls is the R version of the Execl's solver.

The pweibull will calculate the probability distribution for the Weibull distribution. The comments in the code should explain the step-by-step solution

d.mm <- c(20.001,6.964,4.595,2.297,1.741,1.149,
          0.871,0.574,0.287,0.082,0.062,0.020)
m.pct <- c(1.00,0.97,0.78,0.49,0.27,0.20,0.14,
           0.11,0.07,0.03,0.025,0.00)

#create data frame store data
df<-data.frame(m.pct, d.mm)

#data for prediction
d.wei <- c(seq(0.01,0.1,0.01),seq(0.2,1,0.1),seq(2,30,1))

#solver (provided starting value for solution)
# alpha is used for shape and beta is used for scale
fit<-nls(m.pct~pweibull(d.mm, shape=alpha, scale=beta), data=df, start=list(alpha=1, beta=2))
print(summary(fit))

#extract out shape and scale
print(summary(fit)$parameters[,1])

#predict new values base on model
y<-predict(fit, newdata=data.frame(d.mm=d.wei))

#Plot comparison
plot(log10(d.mm),m.pct)
lines(log10(d.wei),y, col="blue")

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM