Hello! 
This is the readme file to explain MATLAB codes demonstrating MCMC simulation. 

There are two parts of MATLAB codes.
The 1st part consists of 4 functions with names starting with AA, is to simulate data sets.
The 2nd part consists of 9 functions with names starting with A,  is to run MCMC sampling.

Readers can easily run two main functions (AA4_main & A7_main) by clicking ‘run’ button without typing anything in MATLAB.
First, AA4_main simulates 24 data sets from all alternative models.
Then, A7_main runs a single MCMC chain of each alternative model from each data set, including 1 experimental data and 24 simulated data.

The code is motivated to demonstrate a quick result within a few minutes on each sampling.
Therefore, simulation draws a single chain with 200,000 samples, whereas the actual simulation has been done at least 3 chains with each 2,000,000 samples.
Also, the default setting of this simulation (both data simulation and MCMC sampling) is to repeat only once.
Readers can change the iteration number 'J' in the sub-function (A6_local_run) and also repeat the simulation more than once by changing the repetition number located at for-loop in both main functions (AA4_main & A7_main).

This demo is written together with incorporating qualitative information which however is commented at the likelihood function (A4_likelihood_prior).
Readers can uncommented those parts to introduce RORC knocked-out (for details see Section S5).

The following states the role of each function.
It can also be found in the beginning of each file. 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

PART 1:

%% AA1_para_true
% is a function to output the true parameter vector, including 14-dimensional theta and 3-dimensional alpha.

%% AA2_simulate_data
% is a function to simulate a data set, given an alternative model (M,H).
% The function uses the true parameters in AA1_para_true and sets some of them to be zero depending on the alternative model.
% The system is solved and represented in RPKM values, which are then mapped into read counts.
% The data (without initial values) is then simulated according to likelihood using experimental dispersions.

%% AA3_plot_data
% is a function to plot dynamics of STAT3 and RORC mRNA, with their data points.
% The data points and true responses are represented by circles and solid lines respectively;
% and the dashed lines represent Th17 cell dynamics.
% The controlled and variable groups are represented in black and blue color respectively.

%% AA4_main
% is a function to simulate data sets from all 24 alternative models.
% Readers can simply run this function to simulate 24 data sets and to plot the figures.

PART 2:

%% A0_Th0_analytical
% is a function to solve MDEs of Th0 analytically, using Eq. (S2).
% The matrix exponential is carried out by built-in function 'expm'.
% The result is then used in A1_Th0_analytic.

%% A1_Th_numerical
% is a function to solve MDEs numerically, using Eq. (S2).
% The matrix exponential is carried out by built-in function 'expm'.
% At non-integer time points, matrix exponentials are calculated individually.
% At integer time points, matrix exponentials are first calculated at t=1.

%% A1_Th0_analytic
% is a function to output analytical solution of MDEs of Th0.
% The analytical solution is carried out from Eq. (S2), by solving matrix exponential analytically in A0_Th0_analytical.

%% A2_Th0_solution
% is a function to solve MDEs of Th0, first analytically using A1_Th0_analytic.
% If the analytical solution fails, this function output the numerical solution using A1_Th_numerical.

%% A3_MDE_output
% is a function to output solutions of both Th0 and Th17, given the initial values from the experimental data.
% The output solutions can be replicate-independent and -dependent.

%% A4_likelihood_prior
% is a function to calculate likelihood and prior value, given the sampling parameters (theta and alpha).
% The system is solved and represented in RPKM values, which are then mapped into read counts for calculating likelihood.
% The prior is calculated by the log-normally distributed parameters only.
% The commented part is the qualitative information mentioned in Section S5.
% Readers can uncommented those to incorporate it into the statistical model.

%% A5_popMCMC
% is a function to run a single chain population MCMC sampling for different temperatures.
% MCMC initially requires a good starting point at each temperature by a posterior threshold value.
% popMCMC consists of local and global moves randomly chosen at each iteration.
% Only during the first half period, which is assumed as burn-in, 
% there is an adaptive process to update the proposal covariance every 500th iteration for drawing better samples.
% This MCMC process outputs in total 2000 thinned samples including burn-in.

%% A6_local_run
% is a function to run a single chain MCMC sampling locally, for an alternative model, given one data set.
% This takes around 1-3 minutes to run a chain of 200,000 samples.
% Two resulting figures show parameter posterior distribution and power posterior distribution of 2000 thinned samples, including burn-in that is separated by a vertical dashed line.
% While the model matches with the corresponding correct model, horizontal red dashed lines represent the true parameters in the figure of parameter posterior distribution.
% Remind that the reliable simulation has been done for at least 3 chains with each 2,000,000 samples.
% Readers can increase the sampling size by adjusting 'J' in the following code.

%% A7_main
% is a function to run a single chain MCMC sampling locally, for all 24 alternative models, given all data files.
% This takes around 1-3 minutes to run a chain of 200,000 samples.
% Readers can simply run this function to generate MCMC chains.
% There is a 'pause' between each sampling and please press any key to continue.
