Dear all,
I am running gretl 2016b on Linux Mint Debian 2.
I would like to sample from a known discrete distribution.
In particular, given a vector of probabilities p = (p_1,p_2...p_n)
(where n can change) with associated natural numbers i = (1,2...n), I
would like to make a draw from this distribution.
So, my first question is: is there in gretl a built-in function to do
this?
Of course I can write down some code to accomplish the task, but in R
the function "sample" can directly do it.
So, in R the simple function:
sampleDist = function(p) {
sample(seq(1,length(p)),1,replace=T,p)
}
works as expected, where p is a vector of probabilities.
Example:
p <- c(0.1, 0.4, 0.2, 0.3, 0.0)
sampleDist(p)
Therefore, I tried to use R shared libraries and to define functions in
R in a foreign block in gretl
set R_functions on
foreign language=R
sampleDist = function(p) {
sample(seq(1,length(p)),1,replace=T,p)
}
end foreign
The code is executed in gretl and returns no error, but, when I recall
the function, gretl returns an error of "unknown function"
? matrix p = {0.1,0.1,0.5,0.3,0}
Generated matrix p
? scalar c = R.sampleDist(p)
c = R.sampleDist(
The symbol 'R.sampleDist' is
undefined
Error executing script: halting
This is an issue that I encounter also when I try to use some simple
built-in R function from gretl.
For instance, this code (taken from the guide) does not work:
? set R_functions on
? scalar b=R.choose(10,4)
b=R.choose(
The symbol 'R.choose' is undefined
Error executing script: halting
My R version is 3.1.1 and has been built with the shared library enabled
(this is the default option in the Debian package for R) and I checked
that gretl has correctly detected the path to R library libR.so in my
pc.
Is this a problem with the R version and I should upgrade/downgrade R?
Any idea or suggestion?
Best,
Giuseppe
--
Giuseppe Vittucci Marzetti
Assistant Professor, PhD
Department of Sociology and Social Research
University of Milano-Bicocca
Via Bicocca degli Arcimboldi 8 - Building U7 - Floor III - Room 330
20126 Milan, Italy
Phone: +39 0461 882162
Fax: +39 0461 882222
E-mail: giuseppe.vittucci(a)unimib.it