I am quite new to R and I could not find an appropriate answer to my question, neither in the web nor in this forum. So I hope somebody can help me with clarification. I modelled some (simplified) regression trees with rpartexample regression tree, based on only 1 oder 2 predictors to analyse what connections are between them and the dependant variable. Here is the code I cosntructed after reading many threads and manuals. Maybe, it helps:
mydata <- GWM_regression
df <- data.frame(mydata)
set.seed(123)
rows <- sample(nrow(df))
dfshuffle <- df[rows, ]
set.seed(123)
dfshuffle03 <- na.exclude(subset(dfshuffle))
set.seed(123)
sample <- sample.int(n = nrow(dfshuffle03), size = floor(.9*nrow(dfshuffle03)), replace = F)
dfshuffle03_train <- dfshuffle03[sample, ]
dfshuffle03_test <- dfshuffle03[-sample, ]
set.seed(123)
m3 <- rpart (Detection_rate ~ DIF_2018, data = dfshuffle03_train,
method="anova", control = rpart.control(minsplit=20, cp=0, maxdepth=3))
bestcp_m3 <- m3$cptable[which.min(m3$cptable[,"xerror"]),"CP"]
m3.pruned <- prune(m3, cp = bestcp_m3)
rpart.plot(m3.pruned, digits=3, extra=101, fallen.leaves=T, tweak=1, branch=1,
varlen=-13)
The tree I got showed some terminal nodes, whose elements I would like to extract to plot them on a map. I used 90% of the data set for training purposes (maybe too much I know) so not alle elements of my original data are considered by the tree, but I need to know which ones are sorted in which subset.
Is there any chance, to extract these data (as csv. oder txt.) from a regression tree model?