Numerical methods for determining the Weibull parameters in R

I'm trying to estimate the parameters of the Weibull distribution by some numerical methods (namely Graphical, Modified maximum likelihood and Equivalent energy) in R language. My problem is that I'm not getting success in calculate their equations in R like a function. Could someone help me with that?

OBS.: I would like to do the calculations like this:

mm = function(val){
  sigma = sd(val);
  vmedia = mean(val);
  cte = (sigma/vmedia)^2;
  KSUP = 10;
  KINF = 0;
  repeat {
    mmk = (KSUP + KINF)/2;
    tentativa = (gamma(1 + 2/mmk) - (gamma(1 + 1/mmk)^2))/(gamma(1 + 1/mmk)^2);
    err = cte - tentativa;
    if (abs(err) > 1e-05) {
      if (err < 0) {
        KINF = mmk;
      } else {
        KSUP = mmk;
      }
    } 
    else {break;}
  }
  mmc = vmedia/gamma(1+1/mmk);
  return(c(mmk, mmc));
}
source("momento.R")
m=mm(val)
mmk=m[1]
mmc=m[2]
mmk
mmc

your code sources a mystery file, I removed that.
your code doesnt appear in relation to any particular weibull distribution to calculate the parameters of, so i added code to make one.


an_example_weibel <- sort(rweibull(n = 100000, 
                                        shape = 0.3,
                                        scale = 1))

#see it 
plot(an_example_weibel)


mm = function(val){
  sigma = sd(val);
  vmedia = mean(val);
  cte = (sigma/vmedia)^2;
  KSUP = 10;
  KINF = 0;
  repeat {
    mmk = (KSUP + KINF)/2;
    tentativa = (gamma(1 + 2/mmk) - (gamma(1 + 1/mmk)^2))/(gamma(1 + 1/mmk)^2);
    err = cte - tentativa;
 
    if (abs(err) > 1e-05) {
      if (err < 0) {
        KINF = mmk;
      } else {
        KSUP = mmk;
      }
    } 
    else {break;}
  }
  mmc = vmedia/gamma(1+1/mmk);
  return(c(mmk, mmc));
}

mm(an_example_weibel)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.