## File: ExportRProbability.htd

package info (click to toggle)
cain 1.10+dfsg-2
• area: main
• in suites: stretch
• size: 29,856 kB
• sloc: cpp: 49,612; python: 14,988; xml: 11,654; ansic: 3,644; makefile: 133; sh: 2
 file content (88 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download | duplicates (4)
 `12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788` `````` Probability Distributions

Probability Distributions

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)    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.

``````