title: Error in (function (Xi, Y, X_1, X_2, X_s, beta, beta_s, beta_Xi, delta, : argument "X_1" is missing, with no default
body: <p>I am writing a code to implement a bayesian model with a data augmentation approach.
  So I wrote a function that allows me to calculate the posterior of the parameter of interest.</p>
  <p>I add the posterior function:</p>
  <pre><code>log_post_xi &lt;- function(Xi,Y,X_1,X_2,X_s,beta,beta_s,beta_Xi,delta,delta_Xi,c){ 
  
  phi_1 &lt;-  X_1%*%beta + X_s%*%beta_s + Xi*beta_Xi 
  p&lt;- exp(c-phi_1)/(1+exp(c-phi_1))
  lik_1 &lt;- sum(log(dbern(Y, prob = p)))
  phi_2 &lt;- X_2%*%delta + Xi*delta_Xi 
  lambda&lt;- exp(phi_2) 
  lik_2 &lt;- sum(log(dpois(0:10, lambda = lambda)))
  prior &lt;- log(dbern(Xi, prob = pxi)) 
  return(lik_1 + lik_2 + prior)
  }
  </code></pre>
  <p>And to draw the parameter Xi, I wrote a function of Metropolis-Hasting Sampler inspire from <em>Bayesian Survival Analysis with Data Augmentation</em>. This function is:</p>
  <pre><code>metrop_hastings&lt;-function(x_0, iter=1, log_post_density,
                        proposal_dist = function(x_0, prop_sigma){ 
                          MASS::mvrnorm(1, mu = x_0, Sigma = prop_sigma )
                        }, 
                        lower=-Inf, upper=Inf, prop_sigma,
                        ... ){
  
  for(i in 1:iter){
  # draw from proposal distribution
  x_star &lt;- proposal_dist(x_0, prop_sigma)
  # calculate prob of conditional posterior densities
  r_num &lt;- R.utils::doCall(log_post_density, c(list(x_star), list(...)) )
  r_denom &lt;- R.utils::doCall(log_post_density, c(list(x_0), list(...)) )
  r &lt;- exp(r_num - r_denom)
  rmin&lt;-min(r,1)
  if(is.na(rmin)) browser()
  # accept / reject proposal
  if(rbinom(1,1,rmin)==1){ 
    x_0&lt;-x_star
  }
  } res&lt;-list(x_0 = x_0, accept_prob = rmin )
  return(res)}
  </code></pre>
  <p>I keep in R.utils::doCall, list(...), because I want to use that function for many log_post_density which are different arguments. But when I run the code, I have this message error:</p>
  <p><strong>Error in (function (Xi, Y, X_1, X_2, X_s, beta, beta_s, beta_Xi, delta,  :
  argument &quot;X_1&quot; is missing, with no default</strong></p>
  <p>I try to add a argument in the list(...) in the metropolis function (<code>r_num &lt;- R.utils::doCall(log_post_density, c(list(x_star), list(Y,X_1,X_2,X_s,beta,beta_s,beta_Xi,delta,delta_Xi,c)))</code>), but I have another error message:</p>
  <p><strong>Error in doCall.default(log_post_density, c(list(x_star), list(Y, X_1,  :
  object 'beta_s' not found</strong></p>
  <p>Please, can you help me to fixe this error?</p>
  <p>Thanks !</p>