0

I'm a newby in r programming, somone can help me to fixe this error: expected right parenthesis error pos 169.

library(R2OpenBUGS)

lineModel <- function() {
  
  # I: nbre of measures (Spheres)
  # J: nbre of energy bins
  
  # The likelihood function
  for (i in 1:I) {                                                              
    
    Meas[i] ~ dnorm(Meas_bar[i], Sig.Meas[i])
    Meas_bar[i] <- sum(M)   
    M <- Resp * Phi   
    Phi <- a_th[i] * (En/T0^2) * exp(-En/T0)    
  }
  
  # The prior distributions   
  for (i in 1:I) {     
    a_th[i] ~ dunif(0, 1) 
  }
}

lineData <- list(I = 5, J = 21, T0 = 0.025, 
                 En = c(1.0000E-09, 1.2589E-09, 1.5849E-09, 1.9953E-09, 
                        2.5119E-09, 3.1623E-09, 3.9811E-09, 5.0119E-09, 
                        6.3096E-09, 7.9433E-09, 1.0000E-08, 1.2589E-08, 
                        1.5849E-08, 1.9953E-08, 2.5119E-08, 3.1623E-08, 
                        3.9811E-08, 5.0119E-08, 6.3096E-08, 7.9433E-08, 
                        1.0000E-07), 
                 
                 Meas = c(31, 84, 100, 95, 75), 
                 Sig.Meas = c(0.4, 0.4, 0.6, 0.8, 0.8),
                 
                 Resp = c(7.156E+00,6.971E+00,6.761E+00,6.527E+00,6.271E+00, 5.996E+00,
5.705E+00,5.402E+00,5.092E+00,4.777E+00,4.464E+00,4.153E+00,3.850E+00,3.555E+00,
3.273E+00,3.003E+00,2.749E+00,2.508E+00,2.284E+00,2.074E+00,1.882E+00))

lineInits <- function() {
  list(a_th = runif(1, -1, 1))
}

# run in Openbugs
lineout <- bugs (lineData, 
             lineInits,
             parameters.to.save = c("a_th"),
             lineModel,
             #model.file = "PR_model.txt",
             n.burnin = 1500,
             n.chains = 1, 
             n.iter = 10000,
             #codaPkg=T, # for coda package
             #DIC = T,
             #debug = T,
             working.directory = "F:/AAA_PROJECTs/Projet_DPR/Code_Scripts/Bayesian_Code/R_Codes/Proj02")

I found this error when i'm trying to run the attached model using the package R2OpenBugs in R. The log file contains other erorrs beside the one attached before. Also, I found other type of errors at each times I make change in the model

  • Can you make your post [fully reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? Right now, your function by itself looks fine, but we need more context (e.g., `Meas`). – jrcalabrese Jan 31 '23 at 17:32
  • Sorry for the unclear post, it is my first one here. So, by this code I look for the neutron spectrum in the thermal region by using the Maxwell-Boltzman distribution, in the model I mentioned it by **Phi**. the measures used in this inference are collected by using BSS (Bonner Sphere Spectrometry) declared in the model by **Meas[7]**. Constant used in the model are: - The mean energy of thermal neutrojns **T0**=0.025 eV - **Meas_bar[7]**: the mean count rate (**Meas_bar[i]=sum(Resp[i,j]*Phi[j]**) – Zazo Babor Feb 01 '23 at 08:33
  • When I said context, I didn't mean the science that this function is used with. Can you provide some fake data that this function is supposed to be used with and any relevant `library()` calls? [See here how to make a post reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – jrcalabrese Feb 01 '23 at 18:05
  • Thank you @jrcalabrese for the prompt respond, so in order to make everythings more clear, I replace the first post by the entire script. Best regards. – Zazo Babor Feb 02 '23 at 11:23

0 Answers0