Search code examples
rdistributiondata-fittingmodel-fitting

distribution fitting in R


I want to fit a distribution. If I have a dataset I can do it quite easy:

library("fitdistrplus")
data_raw <- c(1018259, 1191258, 1265953, 1278234, 1630327, 1780896, 1831466, 1850446, 1859801, 1928695, 2839345, 2918672, 3058274, 3303089, 3392047, 3581341, 4189346, 5966833, 11451508)
fitdist(data_raw, "lnorm")

This is what I would do to fit a lognormal distribution to my dataset.
But what if I don't have a dataset just the mean, standard deviation and some quantiles. For example:

Mean: 2965042
std.dev: 2338555

Quantiles:
0.1: 1251014
0.5: 1928695
0.8: 3467765
0.9: 4544843
0.95: 6515300
0.999: 11352784

How would you proceed to fit an estimation for this kind of data?

Thank you and best regards
Norbi


Solution

  • Just fit the model with nls:

    DF <- read.table(text = "0.1: 1251014
                     0.5: 1928695
                     0.8: 3467765
                     0.9: 4544843
                     0.95: 6515300
                     0.999: 11352784 ", sep = ":")
    plot(V1 ~ V2, data = DF, 
         xlim = c(0, 1.2e7),ylim = c(0, 1))
    
    
    fit <- nls(V1 ~ plnorm(V2, meanlog, sdlog), data = DF, 
               start = list(meanlog = 13, sdlog = 2), trace = TRUE, algorithm = "port",
               lower = c(0, 0))
    
    summary(fit)
    
    curve(plnorm(x, coef(fit)[[1]], coef(fit)[[2]]), add = TRUE, col = "blue")
    

    resulting plot