Noori Selina

Discussion 10.

Chapter 11, exercise 1 - 1 It is raining in the Land of Oz. Determine a tree and a tree measure for the next three days’ weather. Find w(1), w(2), and w(3) and compare with the results obtained from P, P2, and P3.

library(markovchain)
## Package:  markovchain
## Version:  0.9.5
## Date:     2023-09-24 09:20:02 UTC
## BugReport: https://github.com/spedygiorgio/markovchain/issues
weatherStates <- c("Rain", "Nice", "Snow")
byRow <- TRUE
weatherMatrix <- matrix(data = c(0.5, 0.25, 0.25,
                                  0.5, 0.0, 0.5,
                                  0.25, 0.25, 0.5), byrow = byRow, nrow = 3,
                        dimnames = list(weatherStates, weatherStates))
mcWeather <- new("markovchain", states = weatherStates, byrow = byRow, transitionMatrix = weatherMatrix, name = "Weather")

initialState <- c(1, 0, 0)
day_one <- initialState * mcWeather
day_two <- initialState * (mcWeather ^ 2)
day_three <- initialState * (mcWeather ^ 3)

print("Probabilities for Day 1:")
## [1] "Probabilities for Day 1:"
print(day_one)
##      Rain Nice Snow
## [1,]  0.5 0.25 0.25
print("Probabilities for Day 2:")
## [1] "Probabilities for Day 2:"
print(day_two)
##        Rain   Nice  Snow
## [1,] 0.4375 0.1875 0.375
print("Probabilities for Day 3:")
## [1] "Probabilities for Day 3:"
print(day_three)
##         Rain     Nice     Snow
## [1,] 0.40625 0.203125 0.390625

The computed probabilities for each day match the probabilities listed in the respective rows of the transition matrices provided in the book (P1, P2, and P3), confirming the accuracy of the predictions for the next three days’ weather in the Land of Oz.