Open the file examples/cain/CaoPetzold2006_Schlogl.xml.
(Note that this model is used in the
Plotting Histograms
section of the
Visualization and Analysis
chapter.)
For the "Time Series" method, change the number of frames
to 6. Thus, we record the state every two time units.
Generate 100 trajectories and then click the export button
in the simulation output panel.
In the export configuration window, deselect the
"Time in first column" checkbox. Then export
the time series data with the base name "schlogl".
In R, we first read the data into a data frame, which has 6 rows and 100 columns. We extract the row for time t = 10 as a matrix. Then we plot a histogram of the data.
> schlogl <- read.csv('schlogl.csv') > dim(schlogl) [1] 6 100 > x <- as.matrix(schlogl[6,]) > hist(x)
Next we customize the histogram. We increase the number of breaks, which increases the number of bins. We switch from frequency to probability density. Finally, we specify a main title and the y axis label.
> hist(x, breaks=31, freq=F, main='Population at t = 10', xlab='Population')
Another possibility for visualizing the probability distribution is to use kernel density estimation. This gives a smoothed version of the distribution. We plot the density and then use the rug() function to show the data points below the graph.
> plot(density(x), main='Probabilty density at t = 10', xlab='Population') > rug(jitter(x))
Note that you may directly export histogram data from Cain. However, when working with R, it is usually better to export the raw time series data.