[edit: added brms tag]
Start with a short summary of your inquiry.
I am running a simulation and out2 is where I want my data to go. I want to use update function using brms package to avoid compilation every time. I have added the dataset and the code being used
This is where I want the values to be in:
library(brms)
nsim = 5
out2 <- data.frame(Sim=NA, sample= NA,beta0.bay=NA, beta1.bay=NA, beta2.bay=NA, sd0.bay=NA, sd1.bay=NA, sd2.bay=NA, Lbeta0=NA, Lbeta1=NA,Lbeta2=NA,
Ubeta0=NA, Ubeta1=NA, Ubeta2=NA)
This is the first model for compilation.
baylogit <- brm(formula = y ~ x1 + x2, prior = c(set_prior("normal(0,1000)", class ="b")), chains=3,
iter=5000,warmup=1000, thin=200,cores=3, data = dat, family = bernoulli(link = "logit"),
seed=123, file="fits/baylogit")
This is where I want to do the simulation data analysis.
for(k in 1:nsim){
dat <- mydata1[mydata1$Sim == k,]
baylogi <- try(update(baylogit,chains=3,
iter=2000,warmup=1000, thin=200,cores=3, newdata = dat, family = bernoulli(link = "logit"), seed=123))
if(class(baylogi)[1] == "try-error"){
out2[k,1] <- k
out2[k,3:14] <- NA
} else {
out2[k,1]<- k
out2[k,2]<- nrow(dat)
out2[k,3:5]<- as.numeric((fixef(baylogi)[,1]))
out2[k,6:8]<- as.numeric((fixef(baylogi)[,2]))
out2[k,9:11]<- as.numeric((fixef(baylogi)[,3]))
out2[k,12:14]<- as.numeric((fixef(baylogi)[,4]))
}
}
I am running into the error.
Error in object[[name, exact = TRUE]] : subscript out of bounds
Error in object[[name, exact = TRUE]] : subscript out of bounds
Error in object[[name, exact = TRUE]] : subscript out of bounds
Error in object[[name, exact = TRUE]] : subscript out of bounds
Error in object[[name, exact = TRUE]] : subscript out of bounds
example.csv (19.7 KB)