Here I come again!
The stan code could run perfectly last night, but reported error since today after a small adjustment was made in my model parameter. I am confused what’s wrong with the code. By the way, the code was run via our public server so it’s not ok for me to restart the server!
Here below is my main_code:
run_rl_sp <- function(multiSubj = FALSE) {
# =============================================================================
#### Construct Data ####
# =============================================================================
# clear workspace
library(rstan)
library(ggplot2)
# library(R.matlab)
subID=105
individual_RL<-subset(IGT_data_individual,subNo==subID)
if (multiSubj==FALSE) {
load(‘I:/Xiehanbo/IGT_Data/R/data_individual_RL_dataset.RData’)
sz <- dim(individual_RL)
nTrials <- sz[1]
dataList <- list(nTrials=nTrials,
choice=individual_RL[,13]-10,
reward=individual_RL[,11])
} else {
load(‘I:/Xiehanbo/IGT_Data/R/data_individual_RL_dataset.RData’)
individual_multi_RL<-IGT_data_individual[,c(1,4,11,13)]
a<-matrix(data=individual_multi_RL[,3],nrow=39,ncol=100)
b<-matrix(data=individual_multi_RL[,4],nrow=39,ncol=100)
sz <- dim(a)
nSubjects <- sz[1]
nTrials <- sz[2]
dataList <- list(nSubjects=nSubjects,
nTrials=nTrials,
choice=b-10,
reward=a)
}
# =============================================================================
#### Running Stan ####
# =============================================================================
rstan_options(auto_write = TRUE)
options(mc.cores = 4)
if (multiSubj==FALSE) {
modelFile <- 'I:/Xiehanbo/IGT_Data/R/individual_single_RL_model.stan'
} else {
modelFile <- 'I:/Xiehanbo/IGT_Data/R/PVL_Delta_learning_Model.stan'
}
nIter <- 4000
nChains <- 4
nWarmup <- floor(nIter/2)
nThin <- 1
cat("Estimating", modelFile, "model... \n")
startTime = Sys.time(); print(startTime)
cat("Calling", nChains, "simulations in Stan... \n")
fit_rl4 <- stan(modelFile,
data = dataList,
chains = nChains,
iter = nIter,
warmup = nWarmup,
thin = nThin,
init = "Random",
seed = 1450154626)
control = list(adapt_delta=0.99,
stepszie=1.0,
max_treedepth=20)
cat("Finishing", modelFile, "model simulation ... \n")
endTime = Sys.time(); print(endTime)
cat("It took",as.character.Date(endTime - startTime), "\n")
# =============================================================================
#### Model Summary and Diagnostics ####
# =============================================================================
print(fit_rl4)
plot_trace_excl_warm_up <- stan_trace(fit_rl4, pars = c('lr','c','A','loss_aversion'), inc_warmup = F)
plot_dens <- stan_plot(fit_rl4, pars=c('lr','c','A','loss_aversion'), show_density=T, fill_color = 'skyblue')
return(fit_rl4)
}
It’s like the R told me to add new tools for required source, and I pressed ‘YES’ and it happened like below:
Error in setwd(dirname(libCFile)) : cannot change working directory!
Error in sink(type = “output”) : invalid connection!
Can someone help with that? Thank you in advance!