John Smith
John Smith

Reputation: 110

getting regression function from formula in R

I am just trying to write an R function which gives me the regression function from this expression: y~(k,l,m,n). These letters represent parameters in a nonlinear function. This R function is supposed to extract the regression function from the model when I write the model in closed form(y~()). It can be any nonlinear function with two or more parameters. Can anyone help me how to do that?

Upvotes: 0

Views: 243

Answers (1)

mnel
mnel

Reputation: 115505

I think your sticking point is getting a formula that will parse

you can't just have y~(a,b,d), you need some function name, ie y ~ f(a, b, d)

Then you can use all.vars to extract the variable names and create model matrices and write your fitting function

eg

all.vars(y ~ f(a,b,d))

## [1] "y" "a" "b" "d"

# get the response

as.character(y ~ f(a,b,d))[2]
## [1] "y"

You can use these to extract the objects from the search path

Upvotes: 1

Related Questions