BYOM, byom_doseresp_propazo.m

BYOM is a General framework for simulating model systems in terms of ordinary differential equations (ODEs) or explicit functions. This package only supports explicit functions, which are calculated by simplefun.m, which is called by call_deri.m. The files in the BYOM engine directory are needed for fitting and plotting. Results are shown on screen but also saved to a log file (results.out).

The model: Log-logistic dose response fitting.

This script: Example for survival data, using the binomial likelihood function as the error model. Data for propiconazole in Gammarus pulex from Nyman et al, 2012 (DOI 10.1007/s10646-012-0917-0). This script demonstrates how to calculate and plot ECx for a range of x-values, and how to use weight factors.

Contents

Initial things

Make sure that this script is in a directory somewhere below the BYOM folder.

clear, clear global % clear the workspace and globals
global DATA W X0mat % make the data set and initial states global variables
global glo          % allow for global parameters in structure glo
global pri zvd      % global structures for optional priors and zero-variate data
diary off           % turn of the diary function (if it is accidentaly on)
% set(0,'DefaultFigureWindowStyle','docked'); % collect all figure into one window with tab controls
set(0,'DefaultFigureWindowStyle','normal'); % separate figure windows

pathdefine % set path to the BYOM/engine directory
glo.basenm  = mfilename; % remember the filename for THIS file for the plots
glo.saveplt = 0; % save all plots as (1) Matlab figures, (2) JPEG file or (3) PDF (see all_options.txt)

The data set

Data are entered in matrix form, time in rows, scenarios (exposure concentrations) in columns. First column are the exposure times, first row are the concentrations or scenario numbers. The number in the top left of the matrix indicates how to calculate the likelihood:

% Full data set with observed number of survivors, time in days, conc in uM
% Note: this is the matrix format used for GUTS analysis
D = [-2	0	8.1	12	14	18	24	29	36
    0	20	20	20	20	21	20	20	20
    1	19	20	19	19	21	17	11	11
    2	19	20	19	19	20	6	4	1
    3	19	20	19	18	16	2	0	0
    4	19	19	17	16	16	1	0	0];

% Select one time point from the data set for dose-response analysis
T = 4; % e.g., 4 days (end of experiment)
ind_T = find(D(2:end,1)==T); % index to the requested time point
DATA{1} = [D(1,:)' D(ind_T+1,:)']; % select concentrations and survivors and put them into columns

% Weight factors is now the initial number of animals at t=0 in each
% replicate in the data set.
W{1} = D(2,2:end)'; % copy row at t=0 and turn it into a column
% There are 20 or 21 individuals in each treatment, so we need weights

Initial values for the state variables

Initial states, scenarios in columns, states in rows. First row are the 'names' of all scenarios.

X0mat(1,:) = DATA{1}(1,2); % take second element of first row is the scenario (exposure duration)
X0mat(2,:) = 0;  % initial values state 1 (not used)

Initial values for the model parameters

Model parameters are part of a 'structure' for easy reference.

glo.logsc = 0; % plot the dose-response curve on log-scale

% syntax: par.name = [startvalue fit(0/1) minval maxval];
par.ECx  = [20   1 0 1e6]; % ECx, with x in glo.x_EC (initial value not used)
par.Y0   = [0.9  1 0 1];   % control response (survival probability)
par.beta = [16   1 0 100]; % slope factor of the log-logistic curve
% Note: start value for ECx is estimated from the data set for each x.

Time vector and labels for plots

Specify what to plot. If time vector glo.t is not specified, a default is used, based on the data set. Note that t is now used for the exposure concentrations!

% specify the y-axis labels for each state variable
glo.ylab{1} = 'survival probability';
% specify the x-axis label (same for all states)
glo.xlab    = ['concentration (',char(181),'M)'];
glo.leglab1 = 'time '; % legend label before the 'scenario' number
glo.leglab2 = '(d)';   % legend label after the 'scenario' number

prelim_checks % script to perform some preliminary checks and set things up
% Note: prelim_checks also fills all the options (opt_...) with defauls, so
% modify options after this call, if needed.

Calculations and plotting

Here, the functions are called that will do the calculation and the plotting. Profile likelihoods are used to make robust confidence intervals. Note that the dose-response curve is plotted on a log scale for the exposure concentration. If the control is truly zero, it is plotted as an open symbol, at a low concentration on the x-axis. However, for the fitting, it is truly zero.

opt_optim.fit  = 1; % fit the parameters (1), or don't (0)
opt_optim.it   = 0; % show iterations of the optimisation (1, default) or not (0)
opt_plot.annot = 1; % extra subplot in multiplot for fits: 1) box with parameter estimates, 2) overall legend

% Optimisation and profiling is done three times to obtain EC50, EC20 and
% EC10 with their confidence intervals. An initial value for ECx is
% estimated from the data set by interpolation (this might not work for all
% data sets, so you may need to provide manual starting values)). The
% results are collected in a string that is passed to calc_and_plot in the
% global glo for annotation.

x_EC = [50 20 10]; % values for x in ECx to run through

for i = 1:length(x_EC) % run through all x values
    glo.x_EC  = x_EC(i); % the x in the ECx; put in global variable glo
    % First, find starting value for ECx by interpolation
    par.ECx(1) = interp1(DATA{1}(2:end,1),DATA{1}(2:end,2:end),DATA{1}(2,2)*(100-glo.x_EC)/100,'linear','extrap');
    % Do optimisation
    par_out = calc_optim(par,opt_optim); % start the optimisation
    disp(['x in ECx is: ',num2str(glo.x_EC)])
    % Calculate confidence intervals by profiling
    Xing = calc_proflik(par_out,'ECx',opt_prof); % calculate a profile
    % Create text line to go into the figure window
    str_ecx{i} = sprintf('EC%1.0f: %6.4g (%4.4g - %4.4g)',glo.x_EC, par_out.ECx(1),Xing([1 end],1));
end

% Add a line to clarify the likelihood function used
switch DATA{1}(1)
    case -2
        str_ecx{end+1} = ['Binomial likelihood used'];
    case -1
        error('The multinomial likelihood cannot be used for dose-response data in this package');
    case 1
        str_ecx{end+1} = ['Normal likelihood used'];
    case 0
        str_ecx{end+1} = ['Normal likelihood used (log transformed)'];
    case 0.5
        str_ecx{end+1} = ['Normal likelihood used (sqrt transformed)'];
    otherwise
        str_ecx{end+1} = ['Normal likelihood used (power ',num2str(DATA{1}(1)),' transformed)'];
end

glo.str_extra = str_ecx; % place the collected strings into the global
calc_and_plot(par_out,opt_plot); % calculate model lines and plot them (the plot is for the last fit)
Goodness-of-fit measures for each data set (R-square)
   NaN

=================================================================================
Results of the parameter estimation with BYOM version 4.2
=================================================================================
   Filename      : byom_doseresp_propazo 
   Analysis date : 09-Aug-2018 (11:17) 
   Data entered  :
     data state 1: 8x1, continuous data, power -2.00 transf.
   Search method: Nelder-Mead simplex direct search, 2 rounds. 
     The optimisation routine has converged to a solution
     Total 106 simplex iterations used to optimise. 
     Minus log-likelihood has reached the value 43.6367 (AIC=93.2735). 
=================================================================================
ECx         20.07 (fit: 1, initial: 18.28) 
Y0         0.8893 (fit: 1, initial: 0.9) 
beta        16.03 (fit: 1, initial: 16) 
=================================================================================
Time required: 0.1 secs
x in ECx is: 50
  
95% confidence interval from the profile
=================================================================================
ECx        interval:      18.55 - 23.58 
 
Time required: 1.0 secs
Goodness-of-fit measures for each data set (R-square)
   NaN

=================================================================================
Results of the parameter estimation with BYOM version 4.2
=================================================================================
   Filename      : byom_doseresp_propazo 
   Analysis date : 09-Aug-2018 (11:17) 
   Data entered  :
     data state 1: 8x1, continuous data, power -2.00 transf.
   Search method: Nelder-Mead simplex direct search, 2 rounds. 
     The optimisation routine has converged to a solution
     Total 107 simplex iterations used to optimise. 
     Minus log-likelihood has reached the value 43.6367 (AIC=93.2735). 
=================================================================================
ECx         18.41 (fit: 1, initial: 16) 
Y0         0.8893 (fit: 1, initial: 0.9) 
beta        16.03 (fit: 1, initial: 16) 
=================================================================================
Time required: 1.1 secs
x in ECx is: 20
  
95% confidence interval from the profile
=================================================================================
ECx        interval:      16.02 - 23.29 
 
Time required: 1.9 secs
Goodness-of-fit measures for each data set (R-square)
   NaN

=================================================================================
Results of the parameter estimation with BYOM version 4.2
=================================================================================
   Filename      : byom_doseresp_propazo 
   Analysis date : 09-Aug-2018 (11:17) 
   Data entered  :
     data state 1: 8x1, continuous data, power -2.00 transf.
   Search method: Nelder-Mead simplex direct search, 2 rounds. 
     The optimisation routine has converged to a solution
     Total 107 simplex iterations used to optimise. 
     Minus log-likelihood has reached the value 43.6367 (AIC=93.2735). 
=================================================================================
ECx          17.5 (fit: 1, initial: 16) 
Y0         0.8893 (fit: 1, initial: 0.9) 
beta        16.03 (fit: 1, initial: 16) 
=================================================================================
Time required: 2.0 secs
x in ECx is: 10
  
95% confidence interval from the profile
=================================================================================
ECx        interval:      14.59 - 23.07 
 
Time required: 3.0 secs
Plots result from the optimised parameter values.