# 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.