Session 1 Flashcards
what takes you to the general help page
help.start()
lists the arguments of a function
args(<function>)</function>
takes you to the help page for <function></function>
?<function></function>
runs examples for <function></function>
example(<function>)</function>
lists functions that contan text “abc” in name
apropos(“abc”)
lists all functions that have something to do with abc
??abc
define a vector
c()
calculate the number of entries in a vector
length()
find the third entry in a vector
<vector>[3]
</vector>
use one line to find the first, fourth, and sixth entry in a vector
<vector>[c(1,4,6)]
</vector>
Define the following matrix, name its elements and find A^2
rows <- c(“row1”, “row2”)
columns <- c(“column1”, “column2”)
A <- matrix(c(1,2,3,4), nrow = 2, ncol = 2, byrow = TRUE, dimnames = list(rows,columns))
B <- A%*%A
install the markov chain package
load the markov chain package
install.packages(“markovchain”)
library(markovchain)
A no claims discount system has three levels of discount: low, medium, and high.
Define the transition matrix as follows: 0.6, 0.4, 0, 0.5, 0, 0.5, 0.1, 0.7, 0.2
Create a markov chain object describing the system. Print the object and note the detail provided.
discountlevels <- c(“low”, “medium”, “high”)
transitions <- matrix(c(etc), nrow = 3, ncol = 3, byrow = TRUE, dimname = list(discountlevels, discountlevels))
NCDsystem <- new(“markovchain”, states = discountlevels, byrow =TRUE, transitionMatrix = transitions)
NCDsystem
NCD system, 3 levels of discount.
Transition matrix: 0.6, 0.4, 0, 0.5, 0, 0.5, 0.1, 0.7, 0.2
a) Find the 3 step transition matrix using matrix multiplication and using the markovchain package
b) Assuming the distribution at t=0 is 0.6, 0.2, 0.2 find the distribution at t=3 using matrix multiplication and using the markovchain package
discountlevels <- c(“low”, “medium”, “high”)
transitions <- matrix(c(etc), nrow = 3, ncol = 3, byrow = TRUE, dimname = list(discountlevels, discountlevels))
NCDsystem <- new(“markovchain”, states = discountlevels, byrow =TRUE, transitionMatrix = transitions)
a) i) transitions3 <- transitions%%transitions%%transitions
ii) MC3 <- NCDsystem^3
b) #distribution after n steps
initdist <- c(0.6, 0.2, 0.2)
i) dist3.mmult <- initdist%%transitions3
dist3.mchain <- initdistMC3
assess whether a system is irreducible or aperiodic using
is.irreducible(<markovchain>)
period(<markovchain>)</markovchain></markovchain>