Как подобрать и построить уравнение двойного экспоненциального убывания первого порядка в R? - PullRequest
0 голосов
/ 13 июля 2020

Я пытаюсь подогнать и построить (используя ggplot2) двойное уравнение экспоненциального затухания первого порядка "y = [a1 exp (-k1t)] + [a2 exp (-k2t) ] "к моим экспериментальным данным (радиоактивный распад) с помощью функции nls, но я не могу этого сделать, поскольку отображаются следующие предупреждающие сообщения:

Предупреждающие сообщения: 1: In (function (formula, data = parent.frame (), start, control = nls.control (),: Для некоторых параметров не указаны начальные значения. Инициализация «a1», «k1», «a2», «k2» на «1.». Рассмотрите возможность указания start или использования модели selfStart 2: Ошибка вычисления в stat_smooth(): матрице сингулярного градиента при начальных оценках параметров.

Эта ошибка, вероятно, связана с неправильным начальным предположением для a1, k1, a2 и k2. Поэтому я заметил, что R может «угадать» мои стартовые параметры с помощью функции самозапуска (SSasymp). Однако я не могу реализовать эту функцию для уравнения двойного экспоненциального затухания первого порядка, которое является обязательным для моих экспериментальных данных (оба отсека a1 и a2 и необходимы). Я смог подобрать простое уравнение экспоненциального затухания, используя SSasymp, эта строка прокомментирована в коде, но, к сожалению, не соответствует моим потребностям. Мне также нужно зачитать параметры соответствия, которые будут представлены на статистические тесты. Это код, который я использую:

Fig1a <- ggplot(CREMglucose, aes(x = Day, y = Mean, color = factor(Fert, levels = c("Control", "Ammonium nitrate", "Ammonium sulfate", "Diammonium phosphate", "Potassium nitrate", "Struvite", "Urea")))) +
  geom_point(aes(size = factor(Fert, levels = c("Control", "Ammonium nitrate", "Ammonium sulfate", "Diammonium phosphate", "Potassium nitrate", "Struvite", "Urea")), shape = factor(Fert, levels = c("Control", "Ammonium nitrate", "Ammonium sulfate", "Diammonium phosphate", "Potassium nitrate", "Struvite", "Urea"))), alpha = 0.7, show.legend = FALSE) +
  geom_errorbar(aes(ymin = Mean - se, ymax = Mean + se), size = 0.2, show.legend = FALSE) +
  #geom_smooth(method = "nls", formula = y ~ SSasymp(x, Asym, R0, lrc), se = FALSE, lwd = 0.4, show.legend = FALSE) +
  geom_smooth(method = "nls", formula = y ~ (a1 * exp(-k1 * x)) + (a2 * exp(-k2 * x)), start = list(a1 = 1, k1 = 0.01, a2 = 1, k2 = 0.01), se = FALSE, lwd = 0.4, show.legend = FALSE) +
  xlab(expression('Time after compound addition (d)')) +
  ylab(expression({}^{14}*'C remaining (% of the total added)')) +
  coord_cartesian(xlim = c(0, 21), ylim = c(0, 100)) +
  scale_x_continuous(breaks = c(0, 4, 8, 12, 16, 20)) +
  scale_y_continuous(breaks = c(0, 20, 40, 60, 80, 100)) +
  scale_shape_manual(values = c(6, 0, 15, 1, 16, 2, 17)) +
  scale_size_manual(values = c(2.2, 2.2, 2.3, 2.2, 2.3, 2.2, 2.3)) +
  annotate("text", x = 17.5, y = 100, label = "(a) Glucosamine", size = 3.5, fontface = "bold") +
  theme(axis.text.y = element_text(size = 10, color = "black"),
        axis.text.x = element_blank(),
        axis.title.y = element_text(size = 10),
        axis.title.x = element_blank(),
        legend.text = element_blank(),
        legend.title = element_blank(),
        panel.background = element_blank(),
        panel.grid.major = element_line(color = "gray96", size = 0.50), 
        panel.grid.minor = element_line(color = "gray96", size = 0.30),
        axis.line = element_line(color = "black", size = 0.5),
        panel.border = element_rect(color = "black", fill = NA, size = 0.5))
Fig1a

В дополнение к моим данным:

Fert    Day CREMglucose
Control 0.00    100 
Control 0.00    100 
Control 0.00    100 
Control 0.00    100 
Control 0.08    94 
Control 0.08    95 
Control 0.08    94 
Control 0.08    93 
Control 0.17    89 
Control 0.17    91 
Control 0.17    89 
Control 0.17    89 
Control 0.33    85 
Control 0.33    86 
Control 0.33    86 
Control 0.33    85 
Control 1.00    81 
Control 1.00    81 
Control 1.00    83 
Control 1.00    81 
Control 2.00    79 
Control 2.00    78 
Control 2.00    81 
Control 2.00    79 
Control 3.00    77 
Control 3.00    77 
Control 3.00    80 
Control 3.00    78 
Control 5.00    75 
Control 5.00    75 
Control 5.00    78 
Control 5.00    77 
Control 8.00    74 
Control 8.00    74 
Control 8.00    77 
Control 8.00    75 
Control 11.00   73 
Control 11.00   72 
Control 11.00   76 
Control 11.00   74 
Control 15.00   72 
Control 15.00   71 
Control 15.00   74 
Control 15.00   73 
Control 20.00   70 
Control 20.00   70 
Control 20.00   73 
Control 20.00   72 
Ammonium nitrate    0.00    100 
Ammonium nitrate    0.00    100 
Ammonium nitrate    0.00    100 
Ammonium nitrate    0.00    100 
Ammonium nitrate    0.08    96 
Ammonium nitrate    0.08    97 
Ammonium nitrate    0.08    96 
Ammonium nitrate    0.08    95 
Ammonium nitrate    0.17    93 
Ammonium nitrate    0.17    94 
Ammonium nitrate    0.17    92 
Ammonium nitrate    0.17    91 
Ammonium nitrate    0.33    86 
Ammonium nitrate    0.33    88 
Ammonium nitrate    0.33    86 
Ammonium nitrate    0.33    85 
Ammonium nitrate    1.00    78 
Ammonium nitrate    1.00    78 
Ammonium nitrate    1.00    80 
Ammonium nitrate    1.00    79 
Ammonium nitrate    2.00    74 
Ammonium nitrate    2.00    74 
Ammonium nitrate    2.00    76 
Ammonium nitrate    2.00    75 
Ammonium nitrate    3.00    71 
Ammonium nitrate    3.00    71 
Ammonium nitrate    3.00    74 
Ammonium nitrate    3.00    73 
Ammonium nitrate    5.00    68 
Ammonium nitrate    5.00    68 
Ammonium nitrate    5.00    71 
Ammonium nitrate    5.00    70 
Ammonium nitrate    8.00    66 
Ammonium nitrate    8.00    65 
Ammonium nitrate    8.00    69 
Ammonium nitrate    8.00    68 
Ammonium nitrate    11.00   64 
Ammonium nitrate    11.00   64 
Ammonium nitrate    11.00   67 
Ammonium nitrate    11.00   66 
Ammonium nitrate    15.00   63 
Ammonium nitrate    15.00   62 
Ammonium nitrate    15.00   65 
Ammonium nitrate    15.00   64 
Ammonium nitrate    20.00   61 
Ammonium nitrate    20.00   59 
Ammonium nitrate    20.00   63 
Ammonium nitrate    20.00   62 
Ammonium sulfate    0.00    100 
Ammonium sulfate    0.00    100 
Ammonium sulfate    0.00    100 
Ammonium sulfate    0.00    100 
Ammonium sulfate    0.08    95 
Ammonium sulfate    0.08    97 
Ammonium sulfate    0.08    95 
Ammonium sulfate    0.08    93 
Ammonium sulfate    0.17    91 
Ammonium sulfate    0.17    94 
Ammonium sulfate    0.17    91 
Ammonium sulfate    0.17    88 
Ammonium sulfate    0.33    85 
Ammonium sulfate    0.33    88 
Ammonium sulfate    0.33    85 
Ammonium sulfate    0.33    84 
Ammonium sulfate    1.00    79 
Ammonium sulfate    1.00    79 
Ammonium sulfate    1.00    81 
Ammonium sulfate    1.00    79 
Ammonium sulfate    2.00    77 
Ammonium sulfate    2.00    76 
Ammonium sulfate    2.00    78 
Ammonium sulfate    2.00    77 
Ammonium sulfate    3.00    75 
Ammonium sulfate    3.00    74 
Ammonium sulfate    3.00    76 
Ammonium sulfate    3.00    75 
Ammonium sulfate    5.00    73 
Ammonium sulfate    5.00    71 
Ammonium sulfate    5.00    74 
Ammonium sulfate    5.00    72 
Ammonium sulfate    8.00    71 
Ammonium sulfate    8.00    68 
Ammonium sulfate    8.00    72 
Ammonium sulfate    8.00    69 
Ammonium sulfate    11.00   69 
Ammonium sulfate    11.00   66 
Ammonium sulfate    11.00   70 
Ammonium sulfate    11.00   68 
Ammonium sulfate    15.00   68 
Ammonium sulfate    15.00   65 
Ammonium sulfate    15.00   69 
Ammonium sulfate    15.00   67 
Ammonium sulfate    20.00   66 
Ammonium sulfate    20.00   63 
Ammonium sulfate    20.00   67 
Ammonium sulfate    20.00   65 
Diammonium phosphate    0.00    100 
Diammonium phosphate    0.00    100 
Diammonium phosphate    0.00    100 
Diammonium phosphate    0.00    100 
Diammonium phosphate    0.08    95 
Diammonium phosphate    0.08    95 
Diammonium phosphate    0.08    95 
Diammonium phosphate    0.08    94 
Diammonium phosphate    0.17    90 
Diammonium phosphate    0.17    90 
Diammonium phosphate    0.17    90 
Diammonium phosphate    0.17    89 
Diammonium phosphate    0.33    83 
Diammonium phosphate    0.33    82 
Diammonium phosphate    0.33    83 
Diammonium phosphate    0.33    82 
Diammonium phosphate    1.00    76 
Diammonium phosphate    1.00    75 
Diammonium phosphate    1.00    77 
Diammonium phosphate    1.00    76 
Diammonium phosphate    2.00    73 
Diammonium phosphate    2.00    71 
Diammonium phosphate    2.00    74 
Diammonium phosphate    2.00    73 
Diammonium phosphate    3.00    71 
Diammonium phosphate    3.00    69 
Diammonium phosphate    3.00    72 
Diammonium phosphate    3.00    71 
Diammonium phosphate    5.00    68 
Diammonium phosphate    5.00    65 
Diammonium phosphate    5.00    69 
Diammonium phosphate    5.00    68 
Diammonium phosphate    8.00    65 
Diammonium phosphate    8.00    63 
Diammonium phosphate    8.00    66 
Diammonium phosphate    8.00    65 
Diammonium phosphate    11.00   64 
Diammonium phosphate    11.00   61 
Diammonium phosphate    11.00   64 
Diammonium phosphate    11.00   63 
Diammonium phosphate    15.00   62 
Diammonium phosphate    15.00   59 
Diammonium phosphate    15.00   62 
Diammonium phosphate    15.00   62 
Diammonium phosphate    20.00   60 
Diammonium phosphate    20.00   57 
Diammonium phosphate    20.00   60 
Diammonium phosphate    20.00   59 
Potassium nitrate   0.00    100 
Potassium nitrate   0.00    100 
Potassium nitrate   0.00    100 
Potassium nitrate   0.00    100 
Potassium nitrate   0.08    97 
Potassium nitrate   0.08    98 
Potassium nitrate   0.08    96 
Potassium nitrate   0.08    96 
Potassium nitrate   0.17    93 
Potassium nitrate   0.17    95 
Potassium nitrate   0.17    93 
Potassium nitrate   0.17    92 
Potassium nitrate   0.33    87 
Potassium nitrate   0.33    90 
Potassium nitrate   0.33    88 
Potassium nitrate   0.33    87 
Potassium nitrate   1.00    79 
Potassium nitrate   1.00    80 
Potassium nitrate   1.00    82 
Potassium nitrate   1.00    81 
Potassium nitrate   2.00    75 
Potassium nitrate   2.00    75 
Potassium nitrate   2.00    78 
Potassium nitrate   2.00    78 
Potassium nitrate   3.00    73 
Potassium nitrate   3.00    72 
Potassium nitrate   3.00    76 
Potassium nitrate   3.00    76 
Potassium nitrate   5.00    70 
Potassium nitrate   5.00    70 
Potassium nitrate   5.00    73 
Potassium nitrate   5.00    73 
Potassium nitrate   8.00    67 
Potassium nitrate   8.00    67 
Potassium nitrate   8.00    71 
Potassium nitrate   8.00    71 
Potassium nitrate   11.00   65 
Potassium nitrate   11.00   65 
Potassium nitrate   11.00   69 
Potassium nitrate   11.00   69 
Potassium nitrate   15.00   63 
Potassium nitrate   15.00   63 
Potassium nitrate   15.00   67 
Potassium nitrate   15.00   67 
Potassium nitrate   20.00   61 
Potassium nitrate   20.00   60 
Potassium nitrate   20.00   64 
Potassium nitrate   20.00   65 
Struvite    0.00    100 
Struvite    0.00    100 
Struvite    0.00    100 
Struvite    0.00    100 
Struvite    0.08    95 
Struvite    0.08    96 
Struvite    0.08    94 
Struvite    0.08    95 
Struvite    0.17    90 
Struvite    0.17    92 
Struvite    0.17    89 
Struvite    0.17    90 
Struvite    0.33    85 
Struvite    0.33    86 
Struvite    0.33    86 
Struvite    0.33    87 
Struvite    1.00    81 
Struvite    1.00    82 
Struvite    1.00    83 
Struvite    1.00    83 
Struvite    2.00    78 
Struvite    2.00    79 
Struvite    2.00    81 
Struvite    2.00    81 
Struvite    3.00    77 
Struvite    3.00    77 
Struvite    3.00    80 
Struvite    3.00    80 
Struvite    5.00    75 
Struvite    5.00    75 
Struvite    5.00    78 
Struvite    5.00    78 
Struvite    8.00    73 
Struvite    8.00    73 
Struvite    8.00    76 
Struvite    8.00    77 
Struvite    11.00   72 
Struvite    11.00   72 
Struvite    11.00   75 
Struvite    11.00   76 
Struvite    15.00   71 
Struvite    15.00   70 
Struvite    15.00   74 
Struvite    15.00   75 
Struvite    20.00   69 
Struvite    20.00   69 
Struvite    20.00   72 
Struvite    20.00   73 
Urea    0.00    100 
Urea    0.00    100 
Urea    0.00    100 
Urea    0.00    100 
Urea    0.08    98 
Urea    0.08    98 
Urea    0.08    99 
Urea    0.08    98 
Urea    0.17    96 
Urea    0.17    95 
Urea    0.17    97 
Urea    0.17    96 
Urea    0.33    90 
Urea    0.33    89 
Urea    0.33    93 
Urea    0.33    90 
Urea    1.00    76 
Urea    1.00    74 
Urea    1.00    80 
Urea    1.00    79 
Urea    2.00    67 
Urea    2.00    66 
Urea    2.00    69 
Urea    2.00    70 
Urea    3.00    62 
Urea    3.00    61 
Urea    3.00    62 
Urea    3.00    64 
Urea    5.00    54 
Urea    5.00    53 
Urea    5.00    53 
Urea    5.00    55 
Urea    8.00    47 
Urea    8.00    45 
Urea    8.00    44 
Urea    8.00    47 
Urea    11.00   42 
Urea    11.00   40 
Urea    11.00   39 
Urea    11.00   41 
Urea    15.00   37 
Urea    15.00   35 
Urea    15.00   35 
Urea    15.00   37 
Urea    20.00   33 
Urea    20.00   31 
Urea    20.00   30 
Urea    20.00   32 

Кто-нибудь знает, как подобрать и построить это уравнение в R?

...