Search code examples
rmathstatisticscurve-fittingnormal-distribution

After fitting the cumulative distribution in R creating the normal distribution from fitted parameters


After successfully fitting my cumulative data with Gompertz function, I need to create normal distribution from fitted function.

This is the code so far:

      df <- data.frame(x = c(0.01,0.011482,0.013183,0.015136,0.017378,0.019953,0.022909,0.026303,0.0302,0.034674,0.039811,0.045709,0.052481,0.060256,0.069183,0.079433,0.091201,0.104713,0.120226,0.138038,0.158489,0.18197,0.20893,0.239883,0.275423,0.316228,0.363078,0.416869,0.47863,0.549541,0.630957,0.724436,0.831764,0.954993,1.096478,1.258925,1.44544,1.659587,1.905461,2.187762,2.511886,2.884031,3.311311,3.801894,4.365158,5.011872,5.754399,6.606934,7.585776,8.709636,10,11.481536,13.182567,15.135612,17.378008,19.952623,22.908677,26.30268,30.199517,34.673685,39.810717,45.708819,52.480746,60.255959,69.183097,79.432823,91.201084,104.712855,120.226443,138.038426,158.489319,181.970086,208.929613,239.883292,275.42287,316.227766,363.078055,416.869383,478.630092,549.540874,630.957344,724.43596,831.763771,954.992586,1096.478196),
                 y = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00044816,0.00127554,0.00221488,0.00324858,0.00438312,0.00559138,0.00686054,0.00817179,0.00950625,0.01085188,0.0122145,0.01362578,0.01514366,0.01684314,0.01880564,0.02109756,0.0237676,0.02683182,0.03030649,0.0342276,0.03874555,0.04418374,0.05119304,0.06076553,0.07437854,0.09380666,0.12115065,0.15836926,0.20712933,0.26822017,0.34131335,0.42465413,0.51503564,0.60810697,0.69886817,0.78237651,0.85461023,0.91287236,0.95616228,0.98569093,0.99869001,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999,0.99999999))

library(drc)
fm <- drm(y ~ x, data = df, fct = G.3())

options(scipen = 10) #to avoid scientific notation in x axis

plot(df$x, predict(fm),type = "l", log = "x",col = "blue",
           main = "Cumulative function distribution",xlab = "x", ylab = "y")

points(df,col = "red")

legend("topleft", inset = .05,legend = c("exp","fit")
       ,lty = c(NA,1), col = c("red", "blue"), pch = c(1,NA), lwd=1, bty = "n")


summary(fm)

And this is the following plot: enter image description here

My idea is now to transform somehow this cumulative fit to the normal distribution. Is there any idea how could I do that?


Solution

  • I was thinking of the cumdiff (for lack of a better term). The link helped a lot.

    EDIT

     plot(df$x[-1], Mod(df$y[-length(df$y)]-df$y[-1]), log = "x", type = "b",  
          main = "Normal distribution for original data", 
          xlab = "x", ylab = "y")
    

    yielding:

    For original data set

    ADDITION

    In order to get the Gaussian from the fittedfunction:

    df$y_pred<-predict(fm)
    plot(df$x[-1], Mod(df$y_pred[-length(df$y_pred)]-df$y_pred[-1]), log = "x", 
         type = "b", main="Normal distribution for fitted function", 
         xlab = "x", lab = "y")
    

    yielding:

    Fitted data