Reputation: 1601
I'm trying to determine the optimal cutoff for a continuous variable to predict a binary outcome. The R package OptimalCutpoints seems ideal but I can't get it to work.
Here's my data in dataframe 'example'
id outcome value
200 Favorable -75.2
201 Favorable -34.0
202 Favorable -35.2
203 Favorable -23.3
204 Unfavorable -25.0
205 Favorable -10.6
206 Favorable -19.3
207 Favorable 0.0
208 Favorable -149.8
209 Favorable 0.8
210 Favorable 9.6
211 Unfavorable 5.1
212 Favorable -8.4
213 Favorable -1.3
214 Favorable 0.0
215 Unfavorable 0.0
216 Favorable -26.2
217 Favorable -119.1
218 Favorable 7.2
219 Unfavorable -37.0
When I try to run
optimal.cutpoint.ROC01 <- optimal.cutpoints(X = "value", status = "outcome", tag.healthy = 'Favorable', methods = "ROC01", data = example)
I get
Error: Unsupported index type: NULL
Traceback:
1. optimal.cutpoints(X = "value", status = "outcome", tag.healthy = "Favorable",
. methods = "ROC01", data = example)
2. optimal.cutpoints.default(X = "value", status = "outcome", tag.healthy = "Favorable",
. methods = "ROC01", data = example)
3. levels(data[, categorical.cov])
4. data[, categorical.cov]
5. `[.tbl_df`(data, , categorical.cov)
6. check_names_df(j, x)
7. check_names_df.default(j, x)
8. stopc("Unsupported index type: ", class(j)[[1L]])
9. abort(paste0(...))
Not sure where to go from here.
Upvotes: 1
Views: 1814
Reputation: 104
I've seen the same "Unsupported index type: NULL" error from OptimalCutpoints with data sets imported using the readxl library. readxl returns a "tibble" which is a superset of data.frame with some extra features e.g. it can cope with punctuation marks in column names.
Some older packages don't like tibbles and will throw errors when presented with one. Try coercing your data to a regular data.frame before calling OptimalCutpoints e.g.
example <- as.data.frame(example)
Upvotes: 7