Session 1 Flashcards

1
Q

what takes you to the general help page

A

help.start()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

lists the arguments of a function

A

args(<function>)</function>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

takes you to the help page for <function></function>

A

?<function></function>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

runs examples for <function></function>

A

example(<function>)</function>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

lists functions that contan text “abc” in name

A

apropos(“abc”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

lists all functions that have something to do with abc

A

??abc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

define a vector

A

c()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

calculate the number of entries in a vector

A

length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

find the third entry in a vector

A

<vector>[3]
</vector>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

use one line to find the first, fourth, and sixth entry in a vector

A

<vector>[c(1,4,6)]
</vector>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define the following matrix, name its elements and find A^2

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

install the markov chain package
load the markov chain package

A

install.packages(“markovchain”)
library(markovchain)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

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 <- initdist
MC3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

assess whether a system is irreducible or aperiodic using

A

is.irreducible(<markovchain>)
period(<markovchain>)</markovchain></markovchain>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

the steady state of a system can be found using

A

steadyStates(<markovchain>)</markovchain>

17
Q

generate a sample path for a defined markov chain

A

rmarkovchain(<n>, <chain>, t0 = "starting state", include.t0 = TRUE)</chain></n>

18
Q

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)

Generate a 15 step sample path starting in the medium state using a seed of 123

A

set.seed(123)
rmarkovchain(15, NCDsystem, t0=”medium”, include.t0=TRUE)

19
Q

how to import a data set called states.csv

A

download the data set
save to working directory (?)

import using data <- read.csv(“states.csv”, header=TRUE)

20
Q

using read.csv will import the data as a dataframe, how will we convert the states to a list

A

list(data$State)

21
Q

fit a markov chain to a list and obtain an estimate

A

fitchain <- markovchainFit(listname)
estimate <- fitchain$estimate

22
Q

what function is used to convert the generator matrix to the transition matrix

A

generatorToTransitionMatrix()

23
Q

Create the jump chain (step 1)

consider a three state model with transition intensities: -0.7, 0.1, 0.6, 0.4, -0.9, 0.5, 0.1, 0.6, -0.7

create the generator matrix
convert this to the required transition matrix
generate a 500 step sample path using a seed of 123

step 2 simulate the waiting times
returning to the markov jump process from question 6
extract the parameters for the exponential waiting times from the generator matrix
simulate 500 waiting times using a seed of 79

A

step 2

states <- c(“state1”, “state2”, “state3”)

generator <- matrix(c(etc), nrow = 3, ncol =3, byrow = TRUE, dimnames = list(states, states)

generator

P <- generatorToTransitionMatrix(generator)

mchain <- new(“markovchain”, transitionMatrix=P, states = states)

set.seed(123)
Samplepath <- rmarkovchain(500, mchain, include.t0=TRUE)
head(Samplepath)

lambda.i <- abs(diag(generator))
lambda.i

set.seed(79)
waiting times <- rexp(500, lambda.i[Samplepath])

head(waiting times)