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?
2 Answers
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.
-
$\begingroup$ 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? $\endgroup$– pikachuAug 5, 2020 at 8:56
-
$\begingroup$ 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). $\endgroup$ Aug 5, 2020 at 8:58
-
$\begingroup$ 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. $\endgroup$– pikachuAug 5, 2020 at 9:05
-
$\begingroup$ So my answer still applies. Something random was happening, and you can fix that by setting the seed. $\endgroup$ Aug 5, 2020 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.
set.seed(15)
beforehand ? $\endgroup$