-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmarkov.R
More file actions
21 lines (15 loc) · 747 Bytes
/
markov.R
File metadata and controls
21 lines (15 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#function for calculating matrix powers
matrixPower = source('matrixPower.R');
#markov chain n-step probability distribution given initial distribution
markov <- function(initialDistribution, probabilityMatrix, n){
#n-step probability matrix
nstepProbabilityMatrix = matrixPower(probabilityMatrix, n);
#probability distribution given initial distribution
probabilityDistribution = initialDistribution %*% nstepProbabilityMatrix;
return(probabilityDistribution);
}
P <- matrix(c(1,0,0,0,0,0,0.06,0.03,0.91,0,
0,0,0.06,0,0.03,0.91,0,0,0.04,0,0,0.03,0.93,0,
0.04,0,0,0,0.03,0.93,0,0,0,0,0,1),nrow=6,byrow=T)
states <- c("Drop","Fr","So","Jr","Se","Grad")
init <- c(0,1,0,0,0,0)