# Error with my RSTAN Code

**URL:** <https://discourse.mc-stan.org/t/error-with-my-rstan-code/21171>\
**Category:** Modeling\
**Tags:** rstan\
**Created:** [March 8, 2021, 8:38am UTC](https://discourse.mc-stan.org/t/error-with-my-rstan-code/21171 "2021-03-08T08:38:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammed1990](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mohammed1990](https://discourse.mc-stan.org/u/mohammed1990)\
**Post date:** [March 8, 2021, 8:38am UTC](https://discourse.mc-stan.org/t/error-with-my-rstan-code/21171/1 "2021-03-08T08:38:33Z")

</div>

Hi everyone.

I created a stan file in Rstudio and every time I run it or read it I have a long error and I do not know how to fix my code.

the code on the stan file is as follows: (you can tell it is a 2\_PL IRT model)

```stan
data {
int<lower=0>n_student;
int<lower=0>n_item;
int<lower=0,upper=1>Y[n_student,n_item];
}
parameters {
real theta[n_student]; // theta
real<lower=0>alpha[n_item]; //a
real beta[n_item]; //b
real mu_beta; // mean of b
real<lower=0>sigma_beta; //sd of b
}

model {
theta ~ normal(0,1);
alpha ~ lognormal(0,1);
beta ~ normal(mu_beta,sigma_beta);
mu_beta ~ normal(0,5);
sigma_beta ~ cauchy(0,5);

for (i in 1:n_student){
for (j in 1:n_item){Y[i,j] ~ bernoulli_logit(alpha[j]*(theta[i]-beta[j]));
}}
}

```

After I saved the stan file as “2\_PL” I use the following code to run my data and the Rstan code:

```stan
data1 ← as.matrix(data[1:1000,1:88])
data1

# DATA as a list
res<-data1
I=dim(res)[1]
J=dim(res)[2]
data_DSM=list(n_student =I,n_item=J,Y=res)
data_DSM

library(rstan)
rstan_options(auto_write = TRUE)

IRT<- stan(file = “2_PL.stan”, data = data_DSM, iter = 50, chains = 3)

```

Then when I run the code I end up with the following error :

```stan
make would use
if test “zfile4e2c755e4ee5.o” != “z”; then
if test -e “file4e2c755e4ee5-win.def”; then
echo “C:/RR/rtools40//mingw64/bin/“g++ -shared -s -static-libgcc -o file4e2c755e4ee5.dll file4e2c755e4ee5-win.def file4e2c755e4ee5.o “C:/RR/R-4.0.3/library/rstan/lib/x64/libStanServices.a” -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/RR/R-40~1.3/bin/x64" -lR ;
“C:/RR/rtools40//mingw64/bin/“g++ -shared -s -static-libgcc -o file4e2c755e4ee5.dll file4e2c755e4ee5-win.def file4e2c755e4ee5.o “C:/RR/R-4.0.3/library/rstan/lib/x64/libStanServices.a” -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/RR/R-40~1.3/bin/x64" -lR ;
else
echo EXPORTS > tmp.def;
“C:/RR/rtools40//mingw64/bin/“nm file4e2c755e4ee5.o | sed -n ‘s/^.* [BCDRT] / /p’ | sed -e ‘/[.]refptr[.]/d’ -e ‘/[.]weak[.]/d’ | sed 's/[^][^]*/”&”/g’ >> tmp.def;
echo “C:/RR/rtools40//mingw64/bin/“g++ -shared -s -static-libgcc -o file4e2c755e4ee5.dll tmp.def file4e2c755e4ee5.o “C:/RR/R-4.0.3/library/rstan/lib/x64/libStanServices.a” -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/RR/R-40~1.3/bin/x64" -lR ;
“C:/RR/rtools40//mingw64/bin/“g++ -shared -s -static-libgcc -o file4e2c755e4ee5.dll tmp.def file4e2c755e4ee5.o “C:/RR/R-4.0.3/library/rstan/lib/x64/libStanServices.a” -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/StanHeaders/libs/x64” -lStanHeaders -L"C:/Users/malqa/OneDrive/Documents/R/win-library/4.0/RcppParallel/lib/x64” -ltbb -L"C:/RR/R-40~1.3/bin/x64" -lR ;
rm -f tmp.def;
fi
fi

Error in compileCode(f, code, language = language, verbose = verbose) :
C:/RR/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: C:/RR/R-4.0.3/library/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): multiple definition of boost::math::detail::bessel_j0<long double>(long double)::P1'; file4e2c755e4ee5.o:file4e2c755e4ee5.cpp:(.data$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2P1]+0x0): first defined hereC:/RR/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/RR/R-4.0.3/library/rstan/lib/x64/libStanServices.a(stan_fit.o):stan_fit.cpp:(.rdata$_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QC[_ZZN5boost4math6detail9bessel_j0IeEET_S3_E2QC]+0x0): multiple definition of boost::math::detail::bessel_j0(long double)::QC’; file4e2c755e4ee5.o:file4e2c755e4ee5.cpp:(.data$ZZN5boost4math6detai
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
'C:/RR/rtools40/usr/mingw/bin/g++’ not found
Error in sink(type = “output”) : invalid connection

```

does anyone know what is the problem in my code? thank you so much your time.

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [March 8, 2021, 9:08am UTC](https://discourse.mc-stan.org/t/error-with-my-rstan-code/21171/2 "2021-03-08T09:08:59Z")

</div>

You just need to restart R and then reinstall rstan and Stanheaders from source:

```
# Compile packages using all cores
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

install.packages(c("StanHeaders","rstan"),type="source")

```

---

<div class="post-metadata">

**Author:** ![mohammed1990](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mohammed1990](https://discourse.mc-stan.org/u/mohammed1990)\
**Post date:** [March 9, 2021, 9:03am UTC](https://discourse.mc-stan.org/t/error-with-my-rstan-code/21171/3 "2021-03-09T09:03:20Z")

</div>

thanks buddy, it worked (:
