r - F# RProvider strange behavior in mgcv package -
this works:
// helper evaluates r look allow evals (text:string) = r.eval(r.parse(namedparams ["text", text ])) allow evalv (text:string) = (text |> evals).value //run illustration page 8 of http://cran.r-project.org/web/packages/mgcv/mgcv.pdf evalv(""" library(mgcv) set.seed(0) dat <- gamsim(5,n=200,scale=2) """) allow am1 = evals("b<-gam(y ~ x0 + s(x1) + s(x2) + s(x3),data=dat)") allow gam_anova1 = evals("anova(b)") am1.value
the gam() output
family: gaussian link function: identity
formula: y ~ x0 + s(x1) + s(x2) + s(x3)
estimated degrees of freedom: 1.73 7.07 1.00 total = 13.8
gcv score: 4.578643
and anova() output is
family: gaussian link function: identity
formula: y ~ x0 + s(x1) + s(x2) + s(x3)
parametric terms: df f p-value x0 3 77.42 <2e-16
approximate significance of smooth terms: edf ref.df f p-value s(x1) 1.729 2.158 45.071 <2e-16 s(x2) 7.069 8.120 49.230 <2e-16 s(x3) 1.000 1.000 0.056 0.812
however, if seek phone call function using rprovider (an f# type provider) this:
open rprovider.mgcv r.set_seed(0) allow dat = r.gamsim(5,n=200,scale=2) allow b = r.gam(formula = "y~x0+s(x1)+s(x2)+s(x3)",data=dat) r.anova_gam(b)
the next error generated:
rdotnet.evaluationexception: error in terms.formula(gf, specials = c("s", "te", "ti", "t2")) : argument not valid model
this error happens on gam() line. found offending line in https://svn.r-project.org/r-packages/trunk/mgcv/r/mgcv.r, i'm not sure what's going wrong:
tf <- terms.formula(gf,specials=c("s","te","ti","t2")) # specials attribute indicates terms smooth
however, when combine elements of 2 this:
evalv(""" library(mgcv) """) open rprovider.mgcv r.set_seed(0) allow dat = r.gamsim(5,n=200,scale=2) allow b = r.gam(formula = evals("y~x0+s(x1)+s(x2)+s(x3)"),data=dat) //let b = r.gam(formula = "y~x0+s(x1)+s(x2)+s(x3)",data=dat) r.anova_gam(b)
it runs fine. note there 2 changes. first loading library, rprovider thought supposed you. sec using evals wrap formula. phone call r.lm without doing (i pass in string representing formula), i'm confused why doesn't work same way.
can explain this? bug or undocumented, correct, behavior? running in ifsharp btw (https://github.com/bayardrock/ifsharp)
i'm guessing (have not tried running code), think problem formula
argument of gam
function not string (which how phone call in sec case), symbolic expression.
r has quite fancy parameter passing mechanism function gets source code representation of y~x0+s(x1)+s(x2)+s(x3)
can analysis based on look specify.
when pass through evals
, you're calling r build symbolic expression, pass gam
function - , gets expression rather string. happens in first snippet (where r engine parses whole string).
as having write library(mgcv)
, suspect doing imports of symbols used in symbolic look s(...)
.
r f# type-providers
No comments:
Post a Comment