2

I try to run multiple linear regressions on large data sets. Basically biglm works fine. Now I try to find a convenient way to create my formula automatically, using a vector, containing my dependent variables and a string, containing the rest of my formula. Both strings together are my formula. This works fine for lm() but leads to an error using biglm()

reproduceable example:

library(biglm)

data<-data.frame(av=c(1,2,3,4,5,6,5,4,5,5),
              uv1=c(1,2,5,5,4,56,3,4,5,6),
              uv2=c(4,5,8,3,2,7,6,2,4,6),
              weight=c(1.2,1,1,1,1,1,1,1,0,0))

dependent<-c('av')

independent<-'~ uv1 + uv2 -1'

formula<-paste(dependent[1],independent)

#this works fine
lm_standard<-lm(formula,data=data,weights=weight)

#and this works fine
lm_big1<-biglm(av~uv1+uv2-1,data=data,weights=~weight)

#and here comes the error
lm_big<-biglm(formula,data=data,weights=~weight)

Error: $ operator is invalid for atomic vectors

I don't use as.formula(), because I don't know how to add the -1 to the as.formula() object. My workaround for the as.formula() problem leads to the error message. Is it possible to a) use as.formula() with a missing intercept or b) paste the formula in a way, biglm() can understand?

Hein
  • 23
  • 5
  • 1
    Similar solution [here](http://stackoverflow.com/questions/18067519/using-r-to-do-a-regression-with-multiple-dependent-and-multiple-independent-vari/18069211#18069211) – Metrics Aug 06 '13 at 14:27
  • Hi, welcome to SO. Since you are quite new here, you might want to read the [**about**](http://stackoverflow.com/about) and [**FAQ**](http://stackoverflow.com/faq) sections of the website to help you get the most out of it. If an answer does solve your problem you may want to *consider* upvoting and/or marking it as accepted to show the question has been answered, by ticking the little green check mark next to the suitable answer. You are **not** obliged to do this, but it helps keep the site clean of unanswered questions and rewards those who take the time to solve your problem. – Simon O'Hanlon Aug 13 '13 at 08:48

1 Answers1

3

lm automatically coerces suitable objects to a formula object, whilst biglm does not. Just do it yourself....

lm_big<-biglm( as.formula( formula ) ,data=data,weights=~weight)
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184