Tuesday 15 July 2014

lm() for regression in R using for loop -



lm() for regression in R using for loop -

i'm using lm() linear regression using 2 matrices (one info , 1 weights) i'm looping through columns , doing regression using 1 column @ time. info (e) 102 x 200,000 matrix, , looks like:

v1 v2 v3 ... -0.79 -0.79 -0.79 ... -0.93 -0.93 -0.93 ... -0.18 -0.18 -0.18 ...

and weights matrix (weights) equal in dimensions. design matrix (mod.our) 102 x 29 , looks like:

x-intercept gi hematopoietic brain ... 1 0 0 1 1 0 0 0 1 0 1 0

my code is:

lm.i<-c() (i in seq(1,216063,1)){ lm.i<-c(lm.i,lm(formula=e[,i] ~ mod.our, weights=weights[,i])) }

problem it's been running on 24 hours. know how faster? or improve way in general?

you'll want utilize iterative procedure coefficients. believe commonly stochastic gradient descent used.

someone shows annotated illustration here:

http://www.r-bloggers.com/regression-via-gradient-descent-in-r/

also, bundle rsofia contains sgd implementation in r. or google such application in favorite r package.

i've used sgd in python (it general suggestion utilize python big machine learning problems, rather r speed purposes).

r regression lm

No comments:

Post a Comment