
Does R.NET support "Skew Normal Distribution" such as snorm or others similar functions?


Developer
Mar 24, 2014 at 10:28 PM

It depends what you mean, really; could you be more precise. Do you have a short R code illustrating what you would do in R?
If you can express something in our R statements, you probably can craft an equivalent in R.NET.
If you refer to using directly the C function 'snorm' that is in the R engine, not sure; to start with, it is not exported by the R shared library.



What I need is to create a skewed normal distribution curve that fits a histogram in C# and .NET. In searching the library, I found one in R  the "sn" library.
e.g.
data(mydata, package="sn")
attach(mydata)
// dstart, dend, dbins will be set here from mydata
breaks< c(seq(dstart, dend, by=(denddstart)/dbins))
f < cut(Ht[y=="intensity"], breaks = breaks)
freq < tabulate(f, length(levels(f)))
d1 < sn.mle.grouped(breaks, freq)
d2 < st.mle.grouped(breaks, freq, start=c(d1$end,log(5)))
print(d2$dp)
How can I use this library from .NET? I don't have any experience in R. Could you please show me an example on how to link the sn library and craft an equivalent "d2 < st.mle.grouped(breaks, freq, start=c(d1$end,log(5)))" in R.NET?


Developer
Mar 25, 2014 at 4:38 AM

Using some sample code from the package, the following works:
private static void ReproDiscussion540017(REngine e)
{
e.Evaluate("library(sn)");
e.Evaluate("data(wines, package='sn')");
e.Evaluate("X < model.matrix(~ phenols + wine, data=wines)");
e.Evaluate("fit < msn.mle(x=X, y=cbind(wines$acidity, wines$alcohol), opt.method='BFGS')");
var beta = e.Evaluate("fit$dp$beta").AsNumericMatrix();
var value = beta[0,1];
var betaNames = e.Evaluate("rownames(fit$dp$beta)").AsCharacter().ToArray();
}
It seems that your functions in your versions of sn are substantially different from the version 1.0.0



Your code works! Now I learned how to link the library and call functions in R. I also learned how to pass the results back to .NET.
To make this works in my .NET application, I need to pass the data (double array, or double list) to sn lib as input (not load from a file):
void foo(List<double> myData)
{
var Y = myData;
e.Evaluate("fit < msn.mle(y=Y, opt.method='BFGS')");
var beta = engine.Evaluate("fit$dp$beta").AsNumericMatrix();
......
}
When my data is passed from Y in .NET to y in sn, it causes an following error:
"Error in is.data.frame(frame) : object 'Y' not found
A first chance exception of type 'RDotNet.ParseException' occurred in RDotNet.dll"
Could you please advise me on how to pass the observed data to sn lib?
Thanks


Developer
Mar 26, 2014 at 12:29 AM




thanks



Use fGarch library  snorm and other skewed distributions

