Skip to content

List arguments from data frame columns in formula

3 messages · npobedina, Gabor Grothendieck

#
Hi!
I'm trying to run logistic regression on a dataset which is contained in
dataframe "data" ("y" is in the first col, and 28 parameters for the model).
How can I write formula for function `glm` without listing explicitly all 28
paramaters?
`glm(data[,1]~data[,2]+data[,3]+data[,4]+...,family=binomial)`

As an option I can use `glm.fit(data[,-1],data[,1],family =
binomial(link=logit))`. But the obtained object cannot be used in function
`predict.glm`.

Thanks,
Natalia
#
Try this:

glm(y ~ ., family = binomial, data = data, ...)
On Tue, Jan 12, 2010 at 9:45 AM, npobedina <npobedina at gmail.com> wrote:
#
Thanks a lot for help! :)
I've invented a more complicated way to make it work: 
f <- as.formula(paste("data.y~", paste( names(data.x), collapse = "+")))
fml<-glm(f, data=data.x,family=binomial)


Try this:

glm(y ~ ., family = binomial, data = data, ...)