Start by loading the needed libraries:
In our case, we will need a special distribution:
Then, let us create a smmparametric object to represent the semi-Markov chain associated to the system:
# State space
states <- c("1", "2", "3")
# Initial distribution
alpha <- c(1, 0, 0)
# Transition matrix
p <- matrix(data = c(0, 1, 0,
0.95, 0, 0.05,
1, 0, 0), nrow = 3, byrow = TRUE)
# Distribution matrix
distr <- matrix(c(NA, "geom", NA,
"dweibull", NA, "dweibull",
"dweibull", NA, NA),
nrow = 3, ncol = 3, byrow = TRUE)
param1 <- matrix(c(NA, 0.8, NA,
0.3, NA, 0.5,
0.6, NA, NA),
nrow = 3, ncol = 3, byrow = TRUE)
param2 <- matrix(c(NA, NA, NA,
0.5, NA, 0.7,
0.9, NA, NA),
nrow = 3, ncol = 3, byrow = TRUE)
parameters <- array(c(param1, param2), c(3, 3, 2))
# Create smmparametric model
factory <- smmparametric(states = states, init = alpha, ptrans = p,
type.sojourn = "fij", distr = distr, param = parameters)After that, we are able to simulate a sequence of sample sizes \(M = 10,000\):
Thanks to the smmR package, we can estimate any
semi-Markov model with one or several discrete sequences. In our case,
we are going to introduce a non-parametric
estimation:
The estimate \(\hat{p}\) of the transition matrix \(p\) is:
See the vignette textile-factory for more details.