I am getting the following warning when trying to run the code below:
In go.IA[i] <- ifelse(orr.IA >= gorule.IA, 1, 0) :
number of items to replace is not a multiple of replacement length
I've seen a number of discussions on this warning and so understand why I am getting it, but not how to solve it when it appears in an ifelse statement. Would appreciate any help!
op_char_IA <- function(truth, n, stoprule, gorule, truth.IA, n.IA, stoprule.IA, gorule.IA){
stop <- consider <- go <- NULL
stop.IA <- consider.IA <- go.IA <- NULL
nsim <- 10000
for(i in 1:nsim){
set.seed(1+i)
orr <- rbinom(1, n, truth)
orr.IA <- orr[1:n.IA]
go.IA[i] <- ifelse(orr.IA>=gorule.IA, 1, 0)
consider.IA[i] <- ifelse(orr.IA<gorule.IA & orr.IA>stoprule.IA,1,0)
stop.IA[i] <- ifelse(orr.IA<=stoprule.IA,1,0)
go[i] <- ifelse(orr>=gorule & go.IA[i]==1, 1, 0)
consider[i] <- ifelse(orr<gorule & orr>stoprule,1,0)
stop[i] <- ifelse(orr<=stoprule | stop.IA[i]==1 ,1,0)
}
meango <- mean(go)
meanstop <- mean(stop)
meancons <- mean(consider)
out <- c(meango, meanstop, meancons)
names(out) <- c("Go", "Stop", "Consider")
return(out)
}
op_char_IA(truth=.40, n=35,stoprule=16, gorule=17 ,truth.IA=.40, n.IA=17, stoprule.IA=5, gorule.IA=6)