From: Steve Roberts <sroberts@PICR.man.ac.uk>
>
> Dumb question of the day?....
>
Not at all. These things are tricky to get right.
> I have a fitting routine with an string argument "method" which calls MS
> with a function whose name I can construct using the string argument
> "method" using paste (func<-paste("something",method,sep=".") I then
> want to use func as a function in the formula argument in the ms call
> (fit<-ms(func(things)...))
That should be ms( ~ func(things)). As far as I know as.formula works,
e.g.
fit <- ms(as.formula(paste("~", "something",method, "(things)",sep="")))
example:
my.function<-function( method, other.things)
{
#build function name
ms(as.formula(paste("~", "root.",method,"(things)",sep="")),
start=c(things=4))
}
#define the real functions
root.a<-function(things) {things^2}
root.b<-function(things) {(things-1)^2}
> my.function("b", 0)
value: 2.910541e-20
parameters:
things
1
formula: ~ root.b(things)
1 observations
call: ms(formula = as.formula(paste("~", "root.", method, "(things)", sep =
"")), start = c(things = 4))
In similar contexts use get on the function name, or as.call.
Brian Ripley
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|