Home > Back-end >  How to efficiently run negative binomial regression with many variables in R
How to efficiently run negative binomial regression with many variables in R

Time:10-29

My dataset shows negative binomial distribution, therefore, I want to use negative binomial regression to analyze it.

I followed the instruction described in this web site; https://stats.idre.ucla.edu/r/dae/negative-binomial-regression/

Actually, it worked well, I was able to analyze my data. However, I have many variable to analyze and I do not want to write a script as

linear <- glm(V1 ~ V2 V3 V4 V5 V6 V7 V8 V9 V10 ... V100, data = df1)

Let's say if I have 100 variables to analyze, how can I write an efficient code for regression to save my time? Although it works if I simply added everything like V2 V3 V4.... till the end, I really do not want to.

Any comments should be helpful. Thank you.

CodePudding user response:

as.formula and paste to the rescue

> Vmax=10
> as.formula(paste0("V1~",paste0("V",2:(Vmax-1),sep=" ",collapse=""),"V",Vmax,collapse=""))

V1 ~ V2   V3   V4   V5   V6   V7   V8   V9   V10
  • Related