Checking fits#
Check every fit before using its parameters. A fit can converge and still describe the data poorly, or return a parameter the data do not determine.
The examples on this page use the IC₅₀ tutorial dataset: two inhibitors, three independent experiments
each, with technical triplicates.
import matplotlib.pyplot as plt
import bindcurve as bc
data = bc.DoseResponseData.from_csv("../tutorials/data/ic50.csv", format="wide")
results = bc.fit(data, "ic50")
The experiment table#
results.experiments() has one row per fit, that is, per independent
experiment of each compound:
results.experiments()
| compound_id | experiment_id | success | message | warnings | n_data | rss | r_squared | ymin | ymin_stderr | ymax | ymax_stderr | IC50 | IC50_stderr | hill_slope | hill_slope_stderr | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | inhibitor_a | exp_1 | True | `ftol` termination condition is satisfied. | None | 11 | 1.836502 | 0.999878 | 4.521992 | 0.309105 | 94.671635 | 0.384181 | 67.754019 | 1.343892 | 1.046084 | 0.019801 |
| 1 | inhibitor_a | exp_2 | True | `ftol` termination condition is satisfied. | None | 11 | 16.761434 | 0.999023 | 2.921499 | 1.001466 | 100.672909 | 1.213162 | 75.135651 | 4.481710 | 0.963821 | 0.051435 |
| 2 | inhibitor_a | exp_3 | True | `ftol` termination condition is satisfied. | None | 11 | 12.324292 | 0.999355 | 1.777391 | 0.921444 | 103.382595 | 0.892147 | 134.704492 | 6.285989 | 1.008740 | 0.043799 |
| 3 | inhibitor_b | exp_1 | True | `ftol` termination condition is satisfied. | None | 11 | 27.737383 | 0.998019 | 5.338058 | 2.016768 | 97.445304 | 0.873941 | 1434.410084 | 96.319489 | 1.389277 | 0.111311 |
| 4 | inhibitor_b | exp_2 | True | `ftol` termination condition is satisfied. | None | 11 | 4.190714 | 0.999758 | 8.480239 | 0.623360 | 104.984125 | 0.342225 | 944.570218 | 19.862690 | 1.566379 | 0.045515 |
| 5 | inhibitor_b | exp_3 | True | `ftol` termination condition is satisfied. | None | 11 | 10.039911 | 0.999367 | 4.104765 | 1.268512 | 103.450061 | 0.523559 | 1570.257777 | 60.500640 | 1.372416 | 0.061722 |
Column |
Meaning |
|---|---|
|
Whether the optimizer converged |
|
Optimizer or error message |
|
Quality warnings for converged fits, described below |
|
Number of concentrations fitted |
|
Residual sum of squares of the replicate means |
|
Coefficient of determination of the replicate means |
parameter |
Fitted value of each free parameter |
parameter |
Its standard error within this experiment |
\(R^2\) is close to 1 for almost any sigmoidal data set and says little about whether the model is appropriate. Use it together with the plots below, not on its own.
Quality warnings#
bindcurve flags converged fits whose estimates may not be supported by the
data. fit then emits a UserWarning with the number of flagged fits, the
warnings column gives the reasons, and the N_flagged column of
results.summary() counts them per compound.
Warning |
Meaning |
What to do |
|---|---|---|
name lies outside the tested concentration range. |
The IC₅₀ or \(K_d\) was extrapolated beyond the highest or lowest concentration. |
Extend the concentration range. Otherwise report the value only as above or below the tested range. |
name is poorly determined: its standard error exceeds the estimate. |
The data constrain the parameter only weakly, typically because a plateau or the midpoint is not well covered. |
Add concentrations around the midpoint and on both plateaus, or fix a parameter whose value is independently known. |
Standard errors could not be estimated. |
Some parameters cannot be separated from each other with these data, for example flat data or too few concentrations. |
Check the data and the concentration range, and consider fixing a parameter whose value is known. |
Flagged fits are still included in the summary statistics. To leave one out, remove its rows from the data and fit again:
table = data.table
keep = ~((table["compound_id"] == "inhibitor_b") & (table["experiment_id"] == "exp_2"))
results = bc.fit(bc.DoseResponseData(table[keep]), "ic50")
Plots#
Plot each fit over its data. The replicate means should lie on the curve, with both plateaus and the midpoint covered by measured concentrations:
fig, ax = plt.subplots(figsize=(5, 3.5))
bc.plot_fits(results, compounds="inhibitor_a", ax=ax)
ax.set_xlabel("inhibitor (nM)")
ax.set_ylabel("activity (% of control)")
ax.legend()
plt.show()
Residuals show systematic deviations more clearly. For a good fit they scatter randomly around zero. A trend, such as residuals that are positive at both ends and negative in the middle, means that the model does not describe the shape of the curve:
fig, ax = plt.subplots(figsize=(5, 2.5))
bc.plot_residuals(results, compounds="inhibitor_a", ax=ax)
ax.set_xlabel("inhibitor (nM)")
ax.set_ylabel("residual (%)")
ax.legend()
plt.show()
Common problems#
No lower or upper plateau. The concentration range does not cover the whole curve. The IC₅₀ is then poorly determined; extend the range, or fix the missing plateau if its value is known independently.
Hill slope far from 1. Very steep or shallow curves can come from compound aggregation, solubility limits, depletion or more complex binding. Check the data before interpreting the IC₅₀.
Systematic residuals. The model does not match the data, for example a three-state model applied to incomplete displacement. Consider a different model.
Large differences between independent experiments. Compare the experiment-level values in
results.experiments(). An outlying experiment can have a technical cause, such as a pipetting or dilution error.