make.markov.chain: Generate Markov chains from a set of transition matrices

View source: R/make.markov.chain.r

make.markov.chainR Documentation

Generate Markov chains from a set of transition matrices

Description

Generate Markov chains from a set of transition matrices

Usage

make.markov.chain(boxtrans = boxtrans, s.init = 3, sorder = rep(1:4, 1000))

Arguments

boxtrans

list of transition matrices. Ususally this will be seasonal; winter, spring, summer and fall

s.init

starting area

sorder

order of the seasons. 1-4 is winter, spring, summer and fall

Details

need to make sure not to get into an impossible scenario where the prob is zero of moving out of the current area... this happens for fish going into the Med from the West

Value

a vector of area categories corresponding to the boxes used in the simulation phase

Examples

# simulate 100 chains (fish) for 100 cycles (years) with randomized starting seasons
xx = sapply(sample(1:4, 100, replace = T ), function(x) make.markov.chain(boxtrans, s.init = x, sorder = rep(1:4, 1000)))

# plot two chains (fish) for 50 cycles (years)
image.plot(1:200, 1:2,(xx[1:200,1:2]), nlevel = 7, zlim = c(1,7), xlab = 'cycle', ylab = 'chain (fish)', axes = T)
barplot(table(xx[1:200,]))

galuardi/SatTagSim documentation built on Oct. 22, 2024, 10:18 a.m.