# Predict function of MST object in R returns different values when executing the same code, why?

I am using MST function from MST (multivariate survival tree) package in R to train survival tree. However when I want to predict the node for one selected observation, the output is different. I have not changed the code, just ran the same rows multiple times. I am using the tree selected as the best tree when penalty log_n is used, see documentation (TLDR: n is number of out of bootstrap samples, but the tree is already selected and does not change during prediction). There is no factor issue, as suggested by other answers. Any idea what could be wrong?

• What happens when you run set.seed(15) beforehand ? – Robert Long Aug 5 '20 at 8:40
• looks like it stays the same, something must be random in the prediction of decision tree. it does not make sense to me, when the final tree does not change anymore – pikachu Aug 5 '20 at 8:41
• I also do not have any missing values, which are sometimes treated randomly in DT model... – pikachu Aug 5 '20 at 8:43

I don't know what that function is doing specifically (questions specific to software are off topic here anyway) but from your description (eg bootstrap, or random sampling relating to the treatment of missing values) then there will be some random sampling happening. Therefore setting a seed for the randon number generator prior to running the code should ensure repeatability. Just because the final tree doesn't change doesn't mean that the exact same process has created it - you can think of the final tree in this case as a "limiting value" which will be obtained every time for the parameters that you choose when you run it.

• but I have problems in prediction, which is based on the fixed final tree. Sorry, I just realized the question is offtopic and should be on stack overflow, how can I migrate it there? – pikachu Aug 5 '20 at 8:56
• You need to ask a new question on SO and make it more focussed. I have answered the question that you asked here (about why you get different values from the same code). – Robert Long Aug 5 '20 at 8:58
• Sorry, I have found out where is the problem. I have one categorical variable which has many levels. However for the split only part of those levels were used and if the observation has different value it is treated as "missing" and in prediction process decides randomly. It has nothing to do with bootstrap, that is used only in training process. – pikachu Aug 5 '20 at 9:05
• So my answer still applies. Something random was happening, and you can fix that by setting the seed. – Robert Long Aug 5 '20 at 9:07

I have figured it out. I have one categorical variable which has many levels. However for the split only part of those levels were used and if the observation has different value it is treated as "missing" and in prediction process decides randomly. Thus the observation is sent to left or right way randomly, if the level is not used in split.