Open tinoswe opened 9 years ago
By the way: I installed mboost 2.3-0 (latest release is 2.4-1) but even with the version I have everything is working fine in pure R...
I'd be happy to have a look - but could you please try simplifying the example a bit?
Hi Tomas. yes sure. I'll post it here when it's ready. Thanks.
Hi again, so... I am building a linear model of y as a function of x1, x2, x3. These are passed as vectors to my custom function (I called it "r_lm" in the code below).
Everything works fine when I call "R.lm" (line that is commented out in my code). However I would like to use "R.glmboost" instead of "R.lm" and I can't find the right way of passing my dataset and my custom function to the algrithm... It gives me an error I don't understand.
In the first post from top you find a link to R "mboost" package documentation (where the glmboost method that I want to use is defined) in case you need to check what arguments can be passed.
Thanks for looking into this.
#r @"packages\R.NET.Community.1.5.15\lib\net40\RDotNet.dll"
#r @"packages\R.NET.Community.1.5.15\lib\net40\RDotNet.NativeLibrary.dll"
#r @"packages\R.NET.Community.FSharp.0.1.8\lib\net40\RDotNet.FSharp.dll"
#r @"packages\RProvider.1.0.13\lib\net40\RProvider.dll"
#r @"packages\RProvider.1.0.13\lib\net40\RProvider.Runtime.dll"
#r @"packages\RProvider.1.0.13\lib\net40\RProvider.DesignTime.dll"
open System
open System.Data
open RDotNet
open RProvider
open RProvider.``base``
open RProvider.stats
open RProvider.mboost
#I "packages/FSharp.Data.2.0.9/lib/net40"
#r "FSharp.Data.dll"
open FSharp.Data
let y = [|13.47; 13.31; 13.65; 13.41; 13.9; 11.89; 11.41; 11.86 |]
let x1 = [|33.0; 28.0; 28.0; 28.0; 28.0; 31.0; 31.0; 31.0 |]
let x2 = [|0.61; 0.62; 0.55; 0.6; 0.6; 0.6; 0.6; 0.6 |]
let x3 = [|0.34; 0.36; 0.36; 0.36; 0.36; 0.327; 0.327; 0.327 |]
let r_lm(y : float [],
x1 : float [],
x2 : float [],
x3 : float []) =
let dataset = namedParams [ "Y", box y;
"X1", box x1;
"X2", box x2;
"X3", box x3;
] |> R.data_frame
let custom_formula = "Y ~ X1 + X2 + X3"
//let result = R.lm(formula = custom_formula, data = dataset)
let result = R.glmboost(namedParams ["formula", box custom_formula;"dataset", box dataset] )
R.fitted(result).AsNumeric().GetValue<float[]>()
let fitted_values = r_lm(y,x1,x2,x3)
I'm not quite sure how we should fix this in R provider (it seems to be related to #8 - because the glmboost
function is an S3 function and I suspect we are calling it in a wrong way...).
In any case, you can assign the data set to a temporary R variable and call the function directly by passing a string to the R engine:
let dataset =
[ "Y", box y; "X1", box x1; "X2", box x2;
"X3", box x3 ] |> namedParams |> R.data_frame
// Assign the 'dataset' to 'df' variable
R.assign("df", dataset)
// Run the command using 'eval' function
R.eval(R.parse(text="require(mboost)"))
let result = R.eval(R.parse(text="glmboost(Y ~ X1 + X2 + X3, data=df)"))
R.fitted(result).AsNumeric().GetValue<float[]>()
I suspect that the R provider thinks that glmboost
always takes named parameter x
(because one of the S3 overloads does that?) or maybe it somehow explicitly calls a wrong version of the function (?). I guess it should do runtime dispatch based on the type of the first argument - which would be formula. This also requires calling R.formula
, but even then it does not work:
let custom_formula = R.formula("Y ~ X1 + X2 + X3")
let result = R.glmboost(namedParams ["formula", box custom_formula;"data", box dataset] )
So, the above is a workaround, but I'll leave this open as it has some additional info for #8. Thanks for reporting the issue!
Many thanks to you.
Hi all, I can't find the right way of passing arguments to the R.glmboost algorithm in F#. I attach a complete working example that can be run from an .fsx shell for those who have some minutes to look into it.
The call to R.glmboost is done within the body of the "r_ml" function (at the end) that is a function that takes y, x1, x2, x3, x4, x5 vectors as inputs. Basically I am building a model of y as a function of x1, x2, x3, x4, and x5 using the R.glmboost algorithm.
Note that the call to R.lm (one line above the call to R.glmboost, it is commented out in the script below) works fine. As a reference for glmboost input parameters you can refer to this: http://rgm3.lab.nig.ac.jp/RGM/R_rdfile?f=mboost/man/glmboost.Rd&d=R_CC The error I get has to do with a missing "x" argument that is not expected when using the "S3 method for class 'formula'" that is the one I want to use (see the "Usage" section of the link above, top of the page). However the "x" argument must be there when using the "method for class matrix".
It seems to me I am passing args the wrong way and I need some help on this. Thanks.