# Birth-Death

The models in this section deal with the birth-death process, which is comprised of the birth reaction X → 2X and the death reaction X → 0.

## dsmts-001-01

Importing SBML.
Use the file open button in the tool bar to import the file `examples/sbml/dsmts31/dsmts-001-01.xml`. One other thing to note is that the SBML model does not specify a size for the Cell compartment. However, Cain requires that compartments have a defined size, so it was given the default, unit size.

Reference solutions.
Now open the Cain file `examples/cain/dsmts31/dsmts-001-01.xml`. First select `Reference` in the methods list. Note that the output type is `Statistics, Transient Behavior`. The methods that store only statistics (and not trajectories or histograms) are used for storing solutions that have been generated outside of Cain. The reference (analytical) solution from the DSMTS has been imported. In the simulation output panel, click the plot button to bring up the plot configuration window. At the top of this window select the "Statistics" tab. In the plot configuration window shown below we have specified plotting the mean with the standard deviation shown as error bars.

The resulting plot of the analytical solution is shown below.

The reference solutions from the DSMTS have been imported in all of the examples in this directory. Now we will show how to import such a solution. First select `TimeSeries` in the methods list. As we will import a solution to compare with it, clone the method with the clone button . Then rename the clone method from "TimeSeries1" to "Ref". In the method editor change the category (the second pull-down list) from "Time Series, Uniform" to "Statistics, Transient Behavior". In the launcher panel note that only the import button is enabled. Click this button to import the solution. Select the file `dsmts-001-01.txt`, which is a text file that contains the means and standard deviations. Each line in the file contains the data for one time frame. (You can examine the file with your favorite text editor.) Now the result appears in the simulation output panel. You can plot the solution, examine it in a table, or use it for analysis of other solutions. Since the solution was already imported before, you can now delete your output and the method that you created.

Generating trajectories.
Now select the `TimeSeries` method in the methods list. It uses the direct method and records the state at the times [0, 1, ..., 50]. Specify that 10,000 trajectories should be generated in the launcher panel. Then start the simulation by clicking the launch button .

Return to the plot configuration window. (Click the plot button in the simulation output panel if you closed it.) At the top of the window select the "Time Series" tab. Note that the "BithDeath01, TimeSeries" output is selected in the pull-down menu. In the radio button groups select `Species` and `Mean`. Uncheck the `Legend` button since there is only one species. Fill in an appropriate title and axes labels. The resulting configuration window is shown below.

Below is the plot of the empirical mean and standard deviation of the species population.

Comparing empirical and reference solutions.
Below we plot the empirical and analytical means and standard deviation of the population. The empirical solutions are plotted with a dotted line and circles. The reference solutions are plotted with a solid line. First we plot the empirical solution using the "Time Series" tab of the plot configuration window. Then we add the plot of the reference solution by using the "Plot" button in the "Statistics" tab. (See the Significance Testing section for detailed instructions on how to produce the plots.)

From the plots above we see that the empirical solution appears to agree with the reference solution. Now we use Student's t-test to test the null hypotheses that the empirical means are equal to the analytical means. The test yields a p-value that is the probability of obtaining a test statistics that is at least as extreme as the observed result, assuming that the null hypothesis is true. See the Significance Testing section for more information.

Click the p-value button in the simulation output panel to open the p-value analysis window shown below. In the left column select the "BirthDeath01, TimeSeries" output. In the right column select the reference solution. Click the "Calculate" button to compute the p-value for all of the species and all of the frames. The row headers list the frame times. The column headers list the species.

Click the "Plot" button to show a plot of p-value versus frame number. We see that the p-values are consistent with a correct stochastic simulation method.

Histogram of species population.
Next we will study the distribution of species populations at t = 50. Select the `Histogram` method in the methods list panel. Note that we record a single frame at the end of the simulation. Launch a simulation to generate 10,000 trajectories. Select the `Histograms` tab in the plot configuration window. Select the `Filled` field in the table. Uncheck the `Legend` button. Fill in an appropriate title and axes labels. The resulting plot configuration window is shown below.

Below is the distribution of species populations at time t = 50.

## dsmts-001-02

This model is the same as the one before, except that the rate parameters Lambda and Mu are declared local to the reactions. Cain does not have local parameters, so they are left undefined. After importing `examples/sbml/dsmts31/dsmts-001-02.xml`, one needs to define Lambda and Mu in the parameters editor panel. Because of the local parameters, the reactions are not recognized as having mass-action kinetics.

In order to use the mass-action solvers, we need to edit the reactions to reflect this.

Open `examples/cain/dsmts31/dsmts-001-02.xml` to see the result.

## dsmts-001-03

This model is the same as dsmts-001-01, except that the rate parameters Lambda and Mu have values 1 and 1.1, respectively. The population decays more rapidly than before.

## dsmts-001-04

This model is the same as dsmts-001-01, except that the initial population of X is 10. Below are plots of the mean and standard deviation of the population. As before, we compare the empirical solution using 10,000 trajectories with the analytical solution.

Note that because the population is small, stochastic effects are very noticable. Open `examples/cain/dsmts31/dsmts-001-04.xml` and select `AllReactions` in the methods list panel. This method uses a solver that records every reaction event. (In general, it is only feasible to use such solvers when the total number of reaction events is small. This is typically the case when the species populations are small.) Generate five trajectories and plot the result. Below we see that the trajectories have quite different behaviors.

## dsmts-001-05

This model is the same as dsmts-001-01, except that the initial population of X is 10,000. Below is a plot of the mean and standard deviation of the population. Note that the standard deviation is relatively smaller than before. Since the initial population is higher, there are more reaction events in each trajectory. Thus we generated only 1,000 trajectories in analyzing the mean population.

Now because the population is larger, stochastic effects are less important. Open `examples/cain/dsmts31/dsmts-001-05.xml` and select `TimeSeries` in the methods list panel. Generate five trajectories and plot the result. Below we see that the trajectories are distinct, but have similar behavior.

## dsmts-001-06

In this model death reaction X → 0 is replaced by X → Sink. Sink is declared to be boundary condition, i.e. the `boundaryCondition` attribute in the `species` element is true. Thus, despite the reaction X → Sink, the value of Sink remains 0. Cain does not support boundary conditions. So one must either make Sink a parameter, or change the reaction so that the amount of Sink is constant.

Open `examples/cain/dsmts31/dsmts-001-06.xml`, and select `TimeSeries` in the methods list panel. Generate a single trajectory and plot the result. Below appears that the Sink species has not been plotted. It has been in fact been plotted, but the line coincides with the bottom frame of the plotting window. One may use the toolbar in the plotting window to pan or zoom in order to see the Sink line.

One may also change the axes limits in the plot configuration window. Enter "-5" for the lower bound in the `Y axis limits` field. The resulting plot is shown below.

## dsmts-001-07

This model is the same as dsmts-001-06, except that Sink is not a boundary condition. Now there are two reacting species. We generate 10,000 trajectories and plot the mean and standard deviation. The empirical solutions are shown with dotted lines and markers. The reference solutions are shown with solid lines.

## dsmts-001-08

This model is the same as dsmts-001-01, except that the Cell compartment has size 1. This has no effect on the simulation results.

## dsmts-001-09

This model is the same as dsmts-001-01, except that the Cell compartment has size 2. Again, this has no effect on the simulation results because the species amounts are measured in substance units.

## dsmts-001-10

This model is the same as dsmts-001-01, except that the Cell compartment has size 1. Also, the species are measured in concentration units, not substance units. Ordinarily Cain would not correctly interpret the initial amounts because it assumes that they are given in substance units. However, in this case the result is correct because the compartment has unit size.

## dsmts-001-11

This model is the same as dsmts-001-10, except that the Cell compartment has size 2. Since the species are measured in concentration units, Cain does not correctly calculate the initial amounts. One must enter the correct initial amount of 200 for X in the species editor.

## dsmts-001-12

This model is the same as dsmts-001-01, except that the rate law for the birth reaction is written `Lambda*X*0.5*2`. Cain recognizes this as a mass-action rate law with propensity factor `Lambda`.

## dsmts-001-13

This model is the same as dsmts-001-01, except that Lambda has the value 0.2 and the rate law for the birth reaction is written `Lambda*X*0.5`. This is recognized as a mass-action rate law with propensity factor `0.5*Lambda`.

## dsmts-001-14

This model is the same as dsmts-001-01, except that the rate law for the birth reaction is written `Lambda*X/2/0.5`. This is recognized as a mass-action rate law with propensity factor `Lambda`.

## dsmts-001-15

This model is the same as dsmts-001-01, except that the rate law for the birth reaction is written `Lambda*(X/2)/0.5`. This is recognized as a mass-action rate law with propensity factor `Lambda`.

## dsmts-001-16

This model is the same as dsmts-001-01, except that the rate law for the birth reaction is written `Lambda*X/(2/2)`. This is recognized as a mass-action rate law with propensity factor `Lambda`.

## dsmts-001-17

This model is the same as dsmts-001-08, except that the unit compartment volume is explicitly included in the rate laws. One may use compartment sizes in the same way that one uses parameter values.

## dsmts-001-18

This model is the same as dsmts-001-17, except that the compartment volume is 0.5.

## dsmts-001-19

This model is the same as dsmts-001-01, except that there is an assignment rule that defines a new species y = 2 X. Cain does not support assignment rules.