Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a formula for GLM as a sum of columns in R

Tags:

r

I am trying to set the formula for GLM as the ensemble of columns in train - train$1:99:

model <- glm(train$100 ~ train$1:99, data = train, family = "binomial")

Can't figure to find the right way to do it in R...

like image 978
thecheech Avatar asked Mar 21 '23 14:03

thecheech


1 Answers

If you need outcome ~ var1 + var2 + ... + varN, then try this:

# Name of the outcome column
f1 <- colnames(train)[100]

# Other columns seperated by "+"
f2 <- paste(colnames(train)[1:99], collapse = "+")

#glm
model <- glm(formula = as.formula(paste(f1, f2, sep = "~")),
             data = train,
             family = "binomial")
like image 108
zx8754 Avatar answered Mar 23 '23 13:03

zx8754