# Downloading the neccessary packages
install.packages("markovchain", repos = "http://cran.us.r-project.org")
## 
## The downloaded binary packages are in
##  /var/folders/s4/qp5wvr717qj094rlqhb65ygc0000gn/T//Rtmpp3C8wI/downloaded_packages
library(markovchain)
## Loading required package: Matrix
## Package:  markovchain
## Version:  0.10.0
## Date:     2024-11-14 00:00:02 UTC
## BugReport: https://github.com/spedygiorgio/markovchain/issues
# Defining the states and symbols
states <- c("Checkin", "Waiting", "Exam", "Checkout")
symbols <- c("πŸ“", "⏳", "🩺", "πŸ’³")
names(symbols) <- states
# Defining the transition matrix (rows = from, columns = to)
transition_matrix <- matrix(c(
  # To: Checkin Waiting  Exam  Checkout
       0.0,   0.8,    0.2,   0.0,     # From: Checkin
       0.0,   0.1,    0.8,   0.1,     # From: Waiting
       0.0,   0.0,    0.2,   0.8,     # From: Exam
       0.0,   0.0,    0.0,   1.0      # From: Checkout (absorbing)
), byrow = TRUE, nrow = 4)
# Creating the Markov chain
clinic_chain <- new("markovchain", 
                    states = states,
                    transitionMatrix = transition_matrix,
                    name = "ClinicProcess")
# Simulating the Markov process
set.seed(123)  # For reproducibility
n_steps <- 10
initial_state <- "Checkin"
simulated_states <- rmarkovchain(n = n_steps, object = clinic_chain, t0 = initial_state)
# Translating to symbols
symbolic_sequence <- symbols[simulated_states]
# Results
cat("State sequence:\n", paste(simulated_states, collapse = " β†’ "), "\n")
## State sequence:
##  Waiting β†’ Exam β†’ Checkout β†’ Checkout β†’ Checkout β†’ Checkout β†’ Checkout β†’ Checkout β†’ Checkout β†’ Checkout
cat("Symbolic process:\n", paste(symbolic_sequence, collapse = " β†’ "), "\n")
## Symbolic process:
##  ⏳ β†’ 🩺 β†’ πŸ’³ β†’ πŸ’³ β†’ πŸ’³ β†’ πŸ’³ β†’ πŸ’³ β†’ πŸ’³ β†’ πŸ’³ β†’ πŸ’³

For this project, I’m mimicking the waiting room at a doctor’s office. A patient arrives at the clinic and begins their visit at the check in desk, πŸ“, where their information is recorded. From there, the patient moves to the waiting room, ⏳, waiting for their turn. Then, they are called in for their Examination 🩺, where the provider assesses their condition and discusses any concerns. After the exam, the patient moves to Checkout, πŸ’³, where they finalize paperwork or payment before leaving the clinic. Some patients may stay in Checkout a bit longer if needed, but once there, the process is complete. This summarizes the journey through the healthcare system, from arrival to departure, flows as a cycle of coordinated care.