rmcelreath / stat_rethinking_2023

Statistical Rethinking Course for Jan-Mar 2023
Creative Commons Zero v1.0 Universal
2.2k stars 248 forks source link

week07_solutions - sim( ) maybe broken of behaving unexpected #8

Open Jailos opened 1 year ago

Jailos commented 1 year ago

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