R/stationary.R

Defines functions stationary

Documented in stationary

# 
# compute the stationary distribution of a transition matrix
# 
# Ingmar Visser, 09-2009
# 

stationary <- function(tpm) {
	if(!(nrow(tpm)==ncol(tpm))) stop("Stationary distribution only defined for square matrices.")
	nr <- nrow(tpm)
	rs <- all.equal(rowSums(tpm),rep(1,nr))
	if(!(rs==TRUE)) stop("Rows of the transition probability matrix should sum to unity.")
	e1 <- as.double(eigen(t(tpm))$vectors[,1])
	e1 <- e1/sum(e1)
	return(e1)
}

Try the depmixS4 package in your browser

Any scripts or data that you put into this service are public.

depmixS4 documentation built on Jan. 23, 2020, 3 p.m.