Fitting glm without explicit declaration of each covariate

1

When I fit a linear model with many predictor variables, I can avoid writing all of them by using . as follows:

model = lm(target_deathrate~., data = full_data)

But for models with higher complexity, I cannot make this work:

x = glm(target_deathrate~poly(., i),data = full_data)

In these cases I have to write all variables.

How to avoid writing all variable names and include all variables in my model?

Ayush Ranjan

Posted 2020-01-16T12:18:48.780

Reputation: 319

Answers

2

This has already been answered in stackoverflow here and here.

The main idea is to create the formula from a string with as.formula:

xnam <- paste("x", 1:25, sep="")
fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+")))

noe

Posted 2020-01-16T12:18:48.780

Reputation: 10 494