I am trying to knitr my document/report in a non-standard way? (Maybe?)
I run the analysis chronologically (1,2,3, model, result, end).
However, I would like to REPORT the Logistic regression first and all else as an appendix.
For example: Complete order is:
- run and cache analysis (1,2,3, model, result, end), Works well!
- switch the order (model, result, 1,2,3, end)
- knit report, When I knit report at step #3 I get the error:
Quitting from lines 24-29 (2021-12-02-heart-disease-logistic-regression-report.rmd)
Error in eval(expr, p) : object 'training_set' not found
Calls: <Anonymous> ... train -> train.formula -> eval.parent -> eval -> eval
Execution halted
Example code:
Appendix 5 - Create Data Partition & Setup Cross-Validation
# Partition data into training and testing sets
set.seed(1000)
index <- createDataPartition(df_clean$TenYearCHD, p = 0.8, list = FALSE)
training_set <- df_clean[index, ]
# Create model, 10X fold CV repeated 5X
tcontrol <- trainControl(method = "repeatedcv",
number = 10,
repeats = 5)
Model and result code chunk
model_obj <- train(TenYearCHD ~ ., # line 24...
data = training_set,
trControl = tcontrol,
method = "glm",
family = "binomial")
summary(model_obj) # line 29
```