Responses inline.
On 3/18/13 12:33 PM, Bill Harris wrote:
> Bob,
>
> I can't make your model run on my Windows box the way you sent it, and I'm not near a Linux box right now to test it there.
There shouldn't be a difference between the
way RStan runs under Windows or under Linux other
than the paths you use to refer to files.
From the stan() doc in R:
file
A character string file name or a connection that R supports
containing the text of a model specification in the Stan modeling
language; a model may also be specified directly as a character
string using parameter model_code or through a previous fit using
parameter fit. When fit is specified, parameter file is ignored.
model_code
A character string either containing the model definition
or the name of a character string object in the workspace.
This parameter is used only if parameter file is not specified.
When fit is specified, the model compiled previously is used so
specifying model_code is ignored.
So its' file=model_file or model_code=model_string.
You need version 3 or 6, which correctly specify the
model and the data.
(Sorry if I said "model" at some point -- I keep doing
that in my own code and having to go back and look at the
doc.)
I think this might be easier if it were overloaded, where
we just say model=blah_blah_blah and RStan first sees
if that referes to a file, and if not interprets it
as a string.
> --------------------------------------------------------------------------------------------------------------------
>
> If I run it as you sent it, using the first stan() call, I get
>
> > source("normal_mixture_k.R")
> Error in stan(model = "normal_mixture_k.stan", iter = 500, chains = 1, (from normal_mixture_k.R#40) :
> argument 1 matches multiple formal arguments
Right -- "model" isn't a defined key.
Apparently R lets you use prefixes of argument
names, which is why this error comes up.
> If I run the second stan() call (the one that references the model code rather than the model file), I get
>
> > source("normal_mixture_k.R")
>
> TRANSLATING MODEL 'bobcmodel' FROM Stan CODE TO C++ CODE NOW.
> COMPILING THE C++ CODE FOR MODEL 'bobcmodel' NOW.
> cygwin warning:
> MS-DOS style path detected: c:/R/R-215~1.3/etc/x64/Makeconf
> Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.3/etc/x64/Makeconf
> CYGWIN environment variable option "nodosfilewarning" turns off this warning.
> Consult the user's guide for more details about POSIX paths:
>
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
> C:/R/library/rstan/include//stansrc/stan/agrad/agrad.hpp:2190:17: warning: 'void stan::agrad::free_memory()' defined but
> not used [-Wunused-function]
> Error in eval(expr, envir, enclos) :
> variable does not exist; processing stage=data initialization; variable name=K; base type=int
> failed to create the sampler; sampling not done
This also shouldn't run because you haven't specified the
data. You either need an array of variable names to read
from the environment, or a list of variable definitions.
> > K
> [1] 3
>
> If I run it with the third stan() call, it works:
>
> > source("normal_mixture_k.R")
>
> TRANSLATING MODEL 'bobcmodel' FROM Stan CODE TO C++ CODE NOW.
> COMPILING THE C++ CODE FOR MODEL 'bobcmodel' NOW.
> cygwin warning:
> MS-DOS style path detected: c:/R/R-215~1.3/etc/x64/Makeconf
> Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.3/etc/x64/Makeconf
> CYGWIN environment variable option "nodosfilewarning" turns off this warning.
> Consult the user's guide for more details about POSIX paths:
>
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
> C:/R/library/rstan/include//stansrc/stan/agrad/agrad.hpp:2190:17: warning: 'void stan::agrad::free_memory()' defined but
> not used [-Wunused-function]
> SAMPLING FOR MODEL 'bobcmodel' NOW (CHAIN 1).
> Iteration: 1 / 500 [ 0%] (Adapting)
> Iteration: 50 / 500 [ 10%] (Adapting)
>
> If I try the fourth stan() model, I get
>
> > source("normal_mixture_k.R")
> Error in stan(model = "normal_mixture_k.stan", data = list(K = K, N = N, (from normal_mixture_k.R#46) :
> argument 1 matches multiple formal arguments
Same problem as 1.
> The fifth fails, too:
>
> > source("normal_mixture_k.R")
> TRANSLATING MODEL 'normal_mixture_k' FROM Stan CODE TO C++ CODE NOW.
> COMPILING THE C++ CODE FOR MODEL 'normal_mixture_k' NOW.
> cygwin warning:
> MS-DOS style path detected: c:/R/R-215~1.3/etc/x64/Makeconf
> Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.3/etc/x64/Makeconf
> CYGWIN environment variable option "nodosfilewarning" turns off this warning.
> Consult the user's guide for more details about POSIX paths:
>
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
> C:/R/library/rstan/include//stansrc/stan/agrad/agrad.hpp:2190:17: warning: 'void stan::agrad::free_memory()' defined but
> not used [-Wunused-function]
> Error in eval(expr, envir, enclos) :
> variable does not exist; processing stage=data initialization; variable name=K; base type=int
> failed to create the sampler; sampling not done
You need the data here.
> The sixth version works:
>
> > source("normal_mixture_k.R")
>
> TRANSLATING MODEL 'normal_mixture_k' FROM Stan CODE TO C++ CODE NOW.
> COMPILING THE C++ CODE FOR MODEL 'normal_mixture_k' NOW.
> cygwin warning:
> MS-DOS style path detected: c:/R/R-215~1.3/etc/x64/Makeconf
> Preferred POSIX equivalent is: /cygdrive/c/R/R-215~1.3/etc/x64/Makeconf
> CYGWIN environment variable option "nodosfilewarning" turns off this warning.
> Consult the user's guide for more details about POSIX paths:
>
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
> C:/R/library/rstan/include//stansrc/stan/agrad/agrad.hpp:2190:17: warning: 'void stan::agrad::free_memory()' defined but
> not used [-Wunused-function]
> SAMPLING FOR MODEL 'normal_mixture_k' NOW (CHAIN 1).
> Iteration: 1 / 500 [ 0%] (Adapting)
> Iteration: 50 / 500 [ 10%] (Adapting)
>
> In other words, I seem to need to pass in the data as an explicit list, not as globals, as you seemed to be able to do.
If the variables are defined in the global environment, you
should be able to pass in data using the argument
data=c("K","N","y")
You can't just use c(K,N,y), because we need the names of
the variables as well as the data itself.
> Furthermore, the argument of the file name on my Windows box is called "file", not "model".
That's true everywhere -- sorry if I said "model" at some point.
> I don't know if those are
> differences between Windows and other OSes or not. The error message (especially the "argument 1 matches multiple
> formal arguments") weren't clear to me for a while.
No.
> Thanks for this, though. Now I've got something that might help me with my inference challenge.
You're welcome. Let us know if you have other issues.
- Bob