0

I'm trying to run a Linear Regression Bayesian Anaylysis. I'm trying to source a file Jags.R but I keep encountering errors that I'm unable to solve.

Here is the main code

myData = read.csv(file="HeightWeightData.csv" )
xName = "height" ; yName = "weight"
source("Jags.R")

# Run the MCMC process:
mcmcCoda = genMCMC( data=myData , xName=xName , yName=yName )

# Display posterior distribution:
plotMCMC( mcmcCoda , data=myData , xName=xName , yName=yName ,
compValBeta1=0.0 , ropeBeta1=c(-0.5,0.5) ,
pairsPlot=TRUE )

The source file Jags.R is as follows:

 model{
 for (i in 1:Ntotal) 
  {
  zy[i] ~ dt( zbeta0 + zbeta1 * zx[i] , 1/zsigma^2 , nu )
  } 
  zbeta0 ~ dnorm( 0 , 1/(20)^2 )
  zbeta1 ~ dnorm( 0 , 1/(20)^2 )
  zsigma ~ dunif( 1.0E-4 , 1.0E+4 )
  nu ~ dexp(1/40)
  }

I keep running into three errors in the source Jags.R file.

Error: unexpected '{' in "model{"
Error in Ntotal : object 'Ntotal' not found
Error: unexpected '}' in "}"
Rspacer
  • 2,369
  • 1
  • 14
  • 40
  • This is not valid R code: `model{...}`. Did you mean to define a function: `model <- function() {...}`? Also, when you `source` an R script you are actually running it. Hence, why `Ntotal` errs out as not being found. – Parfait Apr 06 '20 at 21:19
  • I tried writing it as a function but it fails to read it in. I've been trying to follow code from the doing bayesian data analysis book but it doesnt appear to work. I've never sourced filed before. So I'm wondering if I'm doing something wrong – Rspacer Apr 08 '20 at 23:29

0 Answers0