0

I'm building a Markov Chain in R using the 'markovchain' library, I re-ran the code and always got slightly different results, despite no changes to the data going in.

I tested setting the seed to try to eliminate variation from a random seed, and still got small variations in the result. Can anyone explain why this may be?

Sample code below makes a selection of customer pathways leading to a binary responce, results at the bottom

Cheers Iain

#Create input vectors
uid <- c(1:90)
resp <- rep(c(0,1,0,0,0,1,0,0,1,0), times=9)
non_resp <- 1-resp
state1  <- rep(c('Email','DD'), times=45)
state2  <- rep(c(' > Email',' > DD',''), times=30)
state3  <- rep(c(' > Email',' > Email',' > DD','',' > Email',' > DD','','',' > Email'), times=10)
state4  <- rep(c(' > Email',' > DD','',' > Email',' > DD'), times=18)
path <- paste0(state1,state2,state3,state4)

#Create dataframe
df <- data.frame(uid, path, resp, non_resp)

#Build model
model_df <- markov_model(df,
                        var_path = 'path',
                        var_conv = 'resp',
                        var_null = 'non_resp',
                        out_more = TRUE)


model_df2 <- markov_model(df,
                         var_path = 'path',
                         var_conv = 'resp',
                         var_null = 'non_resp',
                         out_more = TRUE)
#Look at attribution
model_df$result
model_df2$result

Result

model_df$result
  channel_name total_conversions
1        Email          14.80159
2           DD          12.19841
model_df2$result
  channel_name total_conversions
1        Email          14.83336
2           DD          12.16664
  • 1
    Are you using the `ChannelAttribution` package? It looks like `markov_model()` has a `seed` argument you can set to ensure reproducibility: https://www.rdocumentation.org/packages/ChannelAttribution/versions/1.14/topics/markov_model – Marius Oct 18 '18 at 05:19
  • 1
    How can you use Markov Chains and not know that they are stochastic? – Roland Oct 18 '18 at 06:46
  • Cheers Marius, that's what I was looking for. It seems if you want reproducible results you have to set the seed within the function. – Iain Third Oct 18 '18 at 22:28

0 Answers0