R/calc.trans.R

Defines functions calc.trans

Documented in calc.trans

calc.trans <- function(x)
{
# calculates the transition matrix given the time series of states
# ----------------------------------------------------------------
# x: vector of states
    x <- factor(x)
    if(length(x) > 1){
        tbl <- table(x[1:(length(x)-1)], x[2:length(x)])
        return(tbl / rowSums(tbl))
    }
    else return(table(x[1], x[1]) / sum(table(x[1])))
}

Try the klaR package in your browser

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

klaR documentation built on March 31, 2023, 3:03 p.m.