Hi there
I want to pass arguments (i.e. the response variable and the subset
argument) in a self-made function to glm.
Here is one way I can do this:
f.myglm - function(y,subfact,subval) {
glm(d.mydata[,y]~d.mydata[,'x1'],family=binomial,subset=d.mydata[,subfact]==subval)
}
str(d.mydata)
f.myglm - function(y=y, subset=x2 == 'yes', data=d.d.mydata)
eval(parse(text=glm(,
deparse(substitute(y)), ~ x1, family=binomial, data=,
deparse(substitute(data)), , subset =,
subset, )))
f.myglm()
---
Jacques VESLOT
CNRS
i forgot a paste():
f.myglm - function(y=y, subset=x2 == 'yes', data=d.d.mydata)
eval(parse(text=paste(glm(,
deparse(substitute(y)), ~ x1, family=binomial, data=,
deparse(substitute(data)), , subset =,
subset, ), sep=)))
---
Jacques
This is the same as glm except that
- formula may be of class character in which case its
regarded as the name of the response variable and
the formula defaults to resp ~ Species for that response
- the data frame defaults to iris
- modify as appropriate for your case
myglm - function