rmcelreath / rethinking

Statistical Rethinking course and book package
2.1k stars 596 forks source link

Comparison length > 1 in `cv_data_slice`. #406

Open broesler opened 11 months ago

broesler commented 11 months ago

While working through the 2nd book edition, I went to run R code 7.17 in the Overthinking box n p 210 (Chapter 7). The book code runs as is, but I was interested in computing the LOOCV value to replicate Figure 7.10, so I ran r <- sim_train_test( N=N, k=k, LOOCV=TRUE). I got an error which I traced back to the following line of cv_data_slice:

if (class(dlo[[vname]]) == "numeric") link to source

The call class(dlo[["mm"]]) returns "matrix" "array", so the comparison to "numeric" returns FALSE FALSE, which has length > 1, causing the error. I'm not sure the best way to correct this multiple class type issue, but will work on a PR unless someone beats me to it.