Search code examples
rregressiondrc

Regression of multiple dose-response curves using the drc package in R


I am trying to fit regressions (4 or 5 PL) through my experimental data. I have several compounds inhibiting my enzyme of interest. Each has it's own range between 0-100% enzyme activity. All the data is in one dataframe and dinstinguished by one column specifying my compound ('toxin'). Therefore I want to have a regression for each of the toxins/compounds individually. I tried the following code

drc <- drm(avg ~ conc, data = testdata, toxin, fct = LL.5())

which gives the two following errors:

Error in optim(startVec, opfct, hessian = TRUE, method = optMethod, control = list(maxit = maxIt, : non-finite finite-difference value [24] Error in drmOpt(opfct, opdfct1, startVecSc, optMethod, constrained, warnVal, : Convergence failed

After reading some posts on SO, this error was often solved by not using a log scale for the concentration ('conc'). In my case, the data is not log-transformed, therefore I do not really know how to proceed as I do not really understand what the error-message is telling me.

I tried the same command with only a subset of the data (only one of the toxins) and that works.

Here is the data:

    testdata <- structure(list(toxin = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("toxin1", 
"toxin2", "toxin3", "toxin4", "toxin5", "toxin6", "NC", "PC", 
"toxin7"), class = "factor"), conc = c(80, 230, 690, 2060, 
6170, 18520, 55560, 116700, 5e+05, 1500000, 10, 30, 100, 290, 
860, 2600, 7700, 23300, 70000, 210000, 0.25, 0.76, 2.29, 6.69, 
29.57, 61.73, 185.19, 555.56, 1666.67, 5000, 0.1, 0.3, 0.91, 
2.74, 8.23, 24.69, 74.07, 222.22, 666.67, 2000, 0.19, 0.39, 0.78, 
1.56, 3.125, 6.25, 12.5, 25, 50, 100, 0.05, 0.14, 0.41, 1.23, 
3.7, 11.11, 33.33, 100, 300, 900, 0.25, 0.76, 2.29, 6.69, 20.57, 
61.73, 185.19, 555.56, 1666.67, 5000), avg = c(93.7392909656605, 
109.438977761257, 102.50389863782, 97.8565582988098, 98.7749196390328, 
94.6820096545283, 88.3878644123183, 74.6531623906189, 59.8033994067719, 
33.1521812859023, 84.3458578131283, 80.8432075369312, 80.5041552022783, 
74.3806536115552, 65.867746238255, 46.7093609589345, 25.2625895634089, 
16.5991924099889, 9.8338847737454, 9.1267136985971, 96.7637675923354, 
100.217322048861, 106.911067427548, 105.869274152439, 104.26295691452, 
99.924974639669, 105.178112603458, 100.834869287621, 97.0640881891228, 
100.517438616909, 102.664029650058, 104.079019894009, 106.005108031173, 
101.539083701953, 98.0496674854621, 67.7840816081928, 39.3101865930841, 
38.410593148271, 8.98193991681226, 7.22314661576326, 84.0614720922454, 
82.7675961061481, 65.2085894181738, 37.3278677636159, 24.9075938602538, 
14.3617392491638, 10.7917687047216, 8.37929257644196, 8.42895771412019, 
12.9194757988616, 76.5674185459266, 65.8625860764468, 47.7169920989096, 
29.6780563387259, 7.69651805994566, 4.34554390880982, 4.33821927277971, 
0.39797595095055, 2.38671848257005, 5.89474149920234, 107.319075979956, 
110.227548845268, 116.828640966343, 107.913632096559, 110.071386130938, 
106.575197414688, 105.043139402911, 98.236919454246, 104.052659508375, 
84.6763301224036), sd = c(7.49544951952132, 14.9170973650272, 
1.03754566304896, 3.87773637652399, 9.17174603323541, 2.0257944547102, 
0.874956239047901, 3.35155947287539, 1.91936941393018, 2.02594096726786, 
1.60035835782164, 1.25579403370456, 3.52866856497447, 4.04640886982452, 
7.37920326517342, 6.40246869316039, 4.77482079353957, 4.68322190067079, 
1.74780492483205, 0.738821067897037, 5.42050977224004, 12.2951096302121, 
9.08089564089922, 7.46281702965045, 9.52060311645085, 6.66339041948764, 
9.04568668161887, 10.9590666295114, 6.25902541715453, 4.96928340386536, 
10.8885949633507, 15.9830841613276, 7.11298501037955, 8.54768106201583, 
12.7115587453605, 5.72457692384765, 4.62110397186864, 50.9817341717873, 
2.96030364454981, 2.83464116977327, 10.7124422767561, 10.3544552730142, 
9.05103847553877, 13.233995551835, 4.26528894064237, 2.18416799462023, 
1.17346307923401, 5.46453008680512, 3.09705214055433, 10.1345046611914, 
2.11845922287944, 3.11915150865922, 6.31893385595251, 14.1295842962481, 
1.33224797602539, 2.11901484197009, 5.05792906176149, 2.08503325893712, 
3.05243406958019, 8.68923158027763, 8.49552648053034, 7.45485150355005, 
8.70510335269844, 7.13998242209083, 6.32588028411456, 4.75860842345735, 
4.09767898578108, 7.04991004776136, 9.37260366463128, 7.20137530818876
)), .Names = c("toxin", "conc", "avg", "sd"), row.names = c(NA, 
-70L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = list(
    toxin), drop = TRUE, indices = list(0:9, 10:19, 20:29, 30:39, 
    40:49, 50:59, 60:69), group_sizes = c(10L, 10L, 10L, 10L, 
10L, 10L, 10L), biggest_group_size = 10L, labels = structure(list(
    toxin = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 9L), .Label = c("toxin1", 
    "toxin2", "toxin3", "toxin4", "toxin5", "toxin6", "NC", 
    "PC", "toxin7"), class = "factor")), row.names = c(NA, 
-7L), class = "data.frame", vars = list(toxin), drop = TRUE, .Names = "toxin"))

Solution

  • The error message is telling you that the function could not find a solution for at least one of your data subsets. In your case, toxin3 is the offending dataset. If I run the following code which omits toxin3, I get a converged result and a nice nice plot showing the results.

    drc <- drm(avg ~ conc, data = testdata, curveid=toxin, subset=toxin %in% c("toxin1","toxin2","toxin4","toxin5","toxin6","toxin7"), fct = LL.5())
    plot(drc)
    

    The reason toxin 3 fails is that the data describe a flat line that could be fit by any number of sets of LL.5() parameters. One way to get around these this would be to fit each curve separately in a loop (or apply function) and use try/catch to handle any datasets that throw a convergence error.