Search code examples
rcurve-fittingexponential-distribution

I have try to fit my exponential function using stat_smooth and ggplot function graph but it did not fit properly. How to use the proper formula?


DATA

Theoritical Strength
26.88 3.16
28.57 4.21
30.94 2.97
33.90 3.06
37.24 2.87
39.76 2.95
41.89 2.70
44.37 1.25
27.20 5.04
26.54 6.69
29.21 4.42
33.26 3.15
34.80 3.20
37.87 3.11
41.88 2.95
44.13 2.26
26.42 7.07
24.02 8.72
29.73 6.38
31.10 3.85
33.16 3.00
36.76 3.28
43.26 3.18
42.06 2.73
26.73 9.44
23.03 9.72
27.07 6.98
29.04 4.67
31.83 3.55
36.29 3.89
39.45 3.55
42.17 3.37
23.51 10.44
21.98 10.90
27.21 8.13
28.63 5.76
30.92 3.96
35.57 3.94
38.33 3.88
40.91 3.58
25.15 13.05
19.44 15.91
25.94 10.37
28.03 5.17
31.25 4.04
35.31 4.24
37.02 4.31
38.89 3.99
25.12 15.66
18.36 19.86
25.05 12.82
27.58 6.07
28.83 4.11
33.76 4.17
34.48 4.30
37.32 3.97
21.27 20.49
16.61 25.53
22.68 16.58
25.63 6.34
28.15 4.40
32.80 3.99
35.27 4.59
36.75 4.35
CODE

S1_mean_2 = ggplot(data = df1, aes(x=C_Theoritical_P_Per_mean, y=Strength_mean))+
  geom_point(size=3.0)+
  stat_smooth(method=lm, formula= (y~(exp(x))))+
  stat_poly_eq(formula = (y~exp(x)), label.x=0.5, label.y=0.85,
               aes(label = paste(..rr.label..)), 
               parse = TRUE, size = 3.5)+
  stat_regline_equation(label.x=30, label.y=25)+
  theme_minimal()+
  xlab("Total P") +
  ylab("Strength")+
  ggtitle("Strength vs Total P") +
  theme(
    plot.title = element_text(color="red", size=14, face="bold.italic"),
    axis.title.x = element_text(color="black", size=14, face="bold"),
    axis.title.y = element_text(color="black", size=14, face="bold"),
    axis.line.x = element_line(colour = 'black', size=0.5, linetype='solid'),
    axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid')
  )
print(S1_mean_2)

Results

img

Needed function

img

But in excel I got almost good curve img


Solution

  • In the data one see that many points are not close to the x-axis. This is not consistent with a exponential model on the form y=b * exp(c * x) with c<0. This leads to try a model of the form y=a+b * exp(c * x) .

    Also it is important to specify the criteria of fitting (LMSE or LMSRE or LMAE or etc.) This is missing in the question. For example with criteria Least Mean Square Error the result of non linear regression is :

    enter image description here

    ADDITION after the comments.

    I used the method described in https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

    This is very simple since it doesn't require initial guessing and the calculus is linear (not iterative) :

    enter image description here

    enter image description here

    Note that the values of a, b, c are slightly different from the above ones. This is correct because the criteria of fitting are not the same. If we want exactly the above values (LMSE) one have to refine with classical non-linear regression. In fact the results are so close than one cannot see any difference between the respective blues curves on the graphs.