Error: The following variables are missing in 'data': 'c1', 'c2'

Hi,

I am using brm function but met an error as the title of this post shows: Error: The following variables are missing in ‘data’: ‘c1’, ‘c2’

I don’t get this error because I already included c1 and c2 in my data argument. It seems the entry in trials() is just not recognized. Did I miss something? Thank you in advance!

data<-cbind(dist,c1,c2)
model2 <- brm(c1|trials(c1+c2) ~ dist, save_mevars=TRUE,
data = data, save_model=NULL,
family = binomial(link=“logit”),
prior = c(set_prior(“normal(0.5,5)”,class=“b”)),
chains=3, iter=2000, warmup=1000, control=list(adapt_delta=0.99, max_treedepth=15))

Maybe this is a type thing. The data argument to brms should be a dataframe. Can you post a full working example? It might be that the variable data just needs a little extra cleanup before it can get passed in.

Thanks for your reply. When I used: data<-data.frame(cbind(dist,c1,c2)), it still has the same error.
Full example:
b0 <- 1
b1 <- 0.1
#predictor: dist:
dist <- runif(10000,0,50)
n<-sample(seq(100,200),10000, replace=T)
p <- 1/(1+exp(-b0-b1*dist))
#response: renum:
renum <- rbinom(10000, n, p)
failure<-n-renum
c1<-array(renum,c(10000,1))
c2<-array(failure,c(10000,1))
#bayesian fit
library(rstan)
library(brms)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
data<-cbind(dist,c1,c2)
model2 <- brm(c1|trials(c1+c2) ~ dist, save_mevars=TRUE,
data = data, save_model=NULL,
family = binomial(link=“logit”),
prior = c(set_prior(“normal(0.5,5)”,class=“b”)),
chains=3, iter=2000, warmup=1000, control=list(adapt_delta=0.99, max_treedepth=15))

Try:

data<-data.frame(dist = dist, c1 = c1, c2 = c2)

That makes sure things have the right names.

Also you can surround code here with three backticks on either side to get preformatted code (there’s also a button at the top of the text editor). It’s easier to read and avoids the problems with weird characters.

Thank you! I converted dist to an array, and it worked!

1 Like