stat_rethinking_2023
stat_rethinking_2023 copied to clipboard
week07_solutions - sim( ) maybe broken of behaving unexpected
The code chunk below gives an error that may be pointing to the in bold below. When run, it breaks and gives the error listed later.
pU0 <- sapply( 1:61 , function(dist) sim(m4,vars=c("Ks","C"),data=list(A=Asim,U=rep(1,n),D=rep(dist,n)))$C )
Error in if (left == var) { : the condition has length > 1
When I tried to debug it, the error may be coming from the sim() function in the line in bold below... I might be wrong, but not able to fix it either. Or maybe I missed the whole point, actually.
sim_vars <- list() for (var in vars) { f <- fit@formula[[1]] for (i in 1:length(fit@formula)) { f <- fit@formula[[i]] left <- as.character(f[[2]]) if (left == var) { if (debug == TRUE) print(f) break