Learn R Programming

spuRs (version 2.0.2)

CMCSimulation: A function to simulate a continuous time Markov chain.

Description

This function simulates a continuous time finite state space Markov chain with known rate matrix Q, state space 0,1,..,n and initial state i for the time period (0,T). If plotflag is TRUE it also produces a plot.

Usage

CMCSimulation(Q,i,Tend,plotflag = FALSE)

Arguments

Q

the rate matrix.

i

the initial state.

Tend

the end of the simulation period (0,T).

plotflag

flag indicating if plot needed

Value

Returns the matrix (statehist,timehist) containing the realisation of the chain for the specified period. The function also produces a plot of the realisation. \

Details

We assume that Q is well defined rate matrix.

References

Jones, O.D., R. Maillardet, and A.P. Robinson. 2009. An Introduction to Scientific Programming and Simulation, Using R. Chapman And Hall/CRC.

See Also

MCSimulation

Examples

Run this code
# NOT RUN {
Q <- matrix(c(-24,24,0, 2,-14,12, 0,4,-4), 
            nrow = 3, ncol = 3, byrow = TRUE)
CMCSimulation(Q,0,1)
# }

Run the code above in your browser using DataLab