samedi 27 février 2021

Setting two manual cutpoints in cutpointr (R)?

I've downloaded the cutpointr package in R and want to use oc_manual (cutpoints from the literature) but need to set two manual outpoints depending on another variable (which can take on the value of 0 or 1). I'm having some difficulty doing this. R keeps running various errors whenever I try to add an ifelse statement or stratify. What is a work around for this? Thanks in advance!

Example:

mtcars
library(cutpointr)
data(mtcars)
opt_cut_manual <- cutpointr(mtcars, mpg, vs, method = oc_manual, 
                       cutpoint = 20, boot_runs = 1000)
plot(opt_cut_manual)

I can only set one manual cutpoint, when I'd like to set the cutpoint at 20 for am=0, and 25 for am=1. I've tried to use an ifelse statement:

mtcars
library(cutpointr)
data(mtcars)
opt_cut_manual <- cutpointr(mtcars, mpg, vs, method = oc_manual, 
if (am==0) {
  cutpoint = 20
} else {
  cutpoint =25
}, boot_runs = 1000)
plot(opt_cut_manual)

This is the error I get:

Error: Can't convert a call to a string In addition: Warning message: In if (!(deparse(substitute(subgroup)) == "NULL")) { : the condition has length > 1 and only the first element will be used

Aucun commentaire:

Enregistrer un commentaire