Hi there,
New Stan user here and am struggling, and hoping someone can find time to help.
I have setup Stan and rtools43 according to instructions here:
All seems to run fine and I can load the rstan library into RStudio.
I’m now trying to use the flipMaxDiff package from here GitHub - pelishk/flipMaxDiff to run a Hierarchical Bayes model using the example datasets from here: How to analyze max-diff data in R | R-bloggers
Data and design seem to import perfectly, but am receiving the error messages below when I try to run the FitMaxDiff function from the flipMaxDiff package.
My code is reproduced below the error messages.
ERROR MESSAGES:
Error in file(fname, "rt") : cannot open the connection
In addition: Warning messages:
1: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="exec/hb.stan": The system cannot find the path specified
2: In file(fname, "rt") :
cannot open file 'C:\Users\SEJE\OneDrive - CompanyName\Desktop\R Development Playground\exec\hb.stan': No such file or directory
Error in get_model_strcode(file, model_code) :
cannot open model file "C:\Users\SEJW\OneDrive - CompanyName\Desktop\R Development Playground\exec\hb.stan"
MY CODE:
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1) # only necessary for Linux without the nodejs library / headers
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
example(stan_model, package = "rstan", run.dontrun = TRUE, verbose = TRUE)
library("rstan") # observe startup messages
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
library("StanHeaders")
library("flipMaxDiff")
# Import the design
tech.design = read.csv("Technology_MaxDiff_Design.csv")
View(tech.design)
# Import the full dataset
tech.data = foreign::read.spss("Technology_2017.sav", to.data.frame = TRUE)
View(tech.data)
# Create two new *vectors* which pull in the best and worst variables
best = tech.data[, c("Q5a_left", "Q5b_left", "Q5c_left",
"Q5d_left", "Q5e_left", "Q5f_left")]
worst = tech.data[, c("Q5a_right", "Q5b_right", "Q5c_right",
"Q5d_right", "Q5e_right", "Q5f_right")]
# Name the alternatives in the design
alt.names <- c("Apple", "Microsoft", "IBM", "Google", "Intel",
"Samsung", "Sony", "Dell", "Yahoo", "Nokia")
result.hb = FitMaxDiff(design = tech.design,
version = rep(1, nrow(best)), # IN THIS EXAMPLE THERE IS ONLY ONE VERSION SO THIS IS CREATING A VECTOR OF ALL 1S FOR AS MANY RO2WS AS THERE ARE 'BEST' RESPONSES
best = best,
worst = worst,
alternative.names = alt.names,
algorithm = "HB",
hb.iterations = 100,
hb.chains = 8,
hb.max.tree.depth = 10)
print(result.hb)
[edit: escaped code]