# Package and data
library("SemiMarkov")
data("asthma", package = "SemiMarkov")
head(asthma)
# Data description using table.state
table.state(asthma)
# Semi-Markov model with three states (Weibull distribution)
states <- c("1", "2", "3")
mtrans <- matrix(FALSE, nrow = 3, ncol = 3)
mtrans[1, 2:3] <- c("W", "W")
mtrans[2, c(1, 3)] <- c("W", "W")
mtrans[3, c(1, 2)] <- c("W", "W")
BMI <- as.data.frame(asthma$BMI)
# Estimation of a semi-Markov model with BMI as covariate
fit <- semiMarkov(data = asthma, states = states, mtrans = mtrans, cov = BMI)
# Display estimation results for distribution parameters
fit$table.dist
# Display estimation results for regression coefficients
fit$table.coef
# Plot of the hazard rates of the waiting time and hazard rate of the semi-Markov process
plot(hazard(fit, cov = 0), hazard(fit, cov = 1), transitions = "13")
plot(hazard(fit, cov = 0, type = "lambda"), hazard(fit, cov = 1, type = "lambda"),
transitions = "13", legend.pos = c(3.75, 0.119), cex = 0.8)
# A model with two covariates where the null hypothesis of the Wald test is modified
SEV <- as.data.frame(asthma$Severity)
fit2 <- semiMarkov(data = asthma, cov = data.frame(BMI, SEV), states =
states, mtrans = mtrans, cov_tra = list(c("13", "31"), "23"),
Wald_par = c(rep(0, 12), rep(-1, 3)))
# Semi-Markov model with upper and lower bounds for some regression coefficients
fit3 <- semiMarkov(data = asthma, cov = BMI, states = states, mtrans = mtrans,
ineqLB = list(c("coef", 1, -0.2), c("coef", 4, -0.1)),
ineqUB = list(c("coef", 1, 0.2), c("coef", 4, 0.1)))
# Semi-Markov model with equality constraint between two distribution parameters
fit4 <- semiMarkov(data = asthma, cov = BMI, states = states, mtrans = mtrans,
eqfun = list(c("dist", 7, 9, 1)))
# Semi-Markov model with equality constraint between three regression coefficients
fit5 <- semiMarkov(data = asthma, cov = BMI, states = states, mtrans = mtrans,
eqfun = list(c("coef", 3, 4, 1), c("coef", 3, 6, 1)))