Re: [R] Python and R

2009-02-21 Thread Douglas Bates
Different methods of performing least squares calculations in R are discussed in @Article{Rnews:Bates:2004, author = {Douglas Bates}, title= {Least Squares Calculations in {R}}, journal = {R News}, year = 2004, volume = 4, number = 1, pages

Re: [R] Python and R

2009-02-20 Thread Gabor Grothendieck
Note that using solve can be numerically unstable for certain problems. On Fri, Feb 20, 2009 at 6:50 AM, Kenn Konstabel wrote: > Decyphering formulas seems to be the most time consuming part of lm: > > mylm1 <- function(formula, data) { > # not perfect but works > F <- model.frame(formula

Re: [R] Python and R

2009-02-20 Thread Kenn Konstabel
Decyphering formulas seems to be the most time consuming part of lm: mylm1 <- function(formula, data) { # not perfect but works F <- model.frame(formula,data) y <- model.response(F) mt <- attr(F, "terms") x <- model.matrix(mt,F) coefs <- solve(crossprod(x), crossprod(x,y))

Re: [R] Python and R

2009-02-19 Thread Gabor Grothendieck
On Thu, Feb 19, 2009 at 8:30 AM, Esmail Bonakdarian wrote: > Hi Kenn, > > Thanks for the suggestions, I'll have to see if I can figure out how to > convert the relatively simple call to lm with an equation and the data file > to the functions you mention (or if that's even feasible). X <- model.m

Re: [R] Python and R

2009-02-19 Thread Esmail Bonakdarian
Hi Kenn, Thanks for the suggestions, I'll have to see if I can figure out how to convert the relatively simple call to lm with an equation and the data file to the functions you mention (or if that's even feasible). Not an expert in statistics myself, I am mostly concentrating on the programming

Re: [R] Python and R

2009-02-19 Thread Esmail Bonakdarian
Doran, Harold wrote: lm(y ~ x-1) solve(crossprod(x), t(x))%*%y# probably this can be done more efficiently You could do crossprod(x,y) instead of t(x))%*%y that certainly looks more readable (and less error prone) to an R newbie like myself :-)

Re: [R] Python and R

2009-02-19 Thread Esmail Bonakdarian
Gabor Grothendieck wrote: On Wed, Feb 18, 2009 at 7:27 AM, Esmail Bonakdarian wrote: Gabor Grothendieck wrote: See ?Rprof for profiling your R code. If lm is the culprit, rewriting your lm calls using lm.fit might help. Yes, based on my informal benchmarking, lm is the main "bottleneck", th

Re: [R] Python and R

2009-02-18 Thread Doran, Harold
> lm(y ~ x-1) > solve(crossprod(x), t(x))%*%y# probably this can be done more > efficiently You could do crossprod(x,y) instead of t(x))%*%y __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posti

Re: [R] Python and R

2009-02-18 Thread Kenn Konstabel
lm does lots of computations, some of which you may never need. If speed really matters, you might want to compute only those things you will really use. If you only need coefficients, then using %*%, solve and crossprod will be remarkably faster than lm # repeating someone else's example # lm(DAX

Re: [R] Python and R

2009-02-18 Thread Gabor Grothendieck
On Wed, Feb 18, 2009 at 7:27 AM, Esmail Bonakdarian wrote: > Gabor Grothendieck wrote: >> >> >> See ?Rprof for profiling your R code. >> >> If lm is the culprit, rewriting your lm calls using lm.fit might help. > > Yes, based on my informal benchmarking, lm is the main "bottleneck", the > rest > o

Re: [R] Python and R

2009-02-18 Thread Esmail Bonakdarian
Barry Rowlingson wrote: - and the bulk of the time in the regression calls will be taken up by C code in the underlying linear algebra libraries (lapack, blas, atlas and friends). ah, good point. Your best bet for optimisation in this case would be making sure you have the best libraries

Re: [R] Python and R

2009-02-18 Thread Esmail Bonakdarian
Gabor Grothendieck wrote: See ?Rprof for profiling your R code. If lm is the culprit, rewriting your lm calls using lm.fit might help. Yes, based on my informal benchmarking, lm is the main "bottleneck", the rest of the code consists mostly of vector manipulations and control structures. I

Re: [R] Python and R

2009-02-18 Thread Barry Rowlingson
2009/2/17 Esmail Bonakdarian : > Well, I have a program written in R which already takes quite a while > to run. I was > just wondering if I were to rewrite most of the logic in Python - the > main thing I use > in R are its regression facilities - if it would speed things up. I > suspect not sinc

Re: [R] Python and R

2009-02-18 Thread Gabor Grothendieck
On Tue, Feb 17, 2009 at 6:59 PM, Esmail Bonakdarian wrote: > Well, I have a program written in R which already takes quite a while > to run. I was > just wondering if I were to rewrite most of the logic in Python - the > main thing I use > in R are its regression facilities - if it would speed thi

Re: [R] Python and R

2009-02-17 Thread Esmail Bonakdarian
On Tue, Feb 17, 2009 at 6:05 PM, Barry Rowlingson wrote: > 2009/2/17 Esmail Bonakdarian : > When I need to use the two together, it's easiest with 'rpy'. This > lets you call R functions from python, so you can do: > > from rpy import r > r.hist(z) wow .. that is pretty straight forward, I'll

Re: [R] Python and R

2009-02-17 Thread Esmail Bonakdarian
Hello! On Tue, Feb 17, 2009 at 5:58 PM, Warren Young wrote: > > Esmail Bonakdarian wrote: >> >> I am just wondering if any of you are doing most of your scripting >> with Python instead of R's programming language and then calling >> the relevant R functions as needed? > > No, but if I wanted to

Re: [R] Python and R

2009-02-17 Thread Barry Rowlingson
2009/2/17 Esmail Bonakdarian : > Hello all, > > I am just wondering if any of you are doing most of your scripting > with Python instead of R's programming language and then calling > the relevant R functions as needed? I tend to use R in its native form for data analysis and modelling, and pytho

Re: [R] Python and R

2009-02-17 Thread Warren Young
Esmail Bonakdarian wrote: I am just wondering if any of you are doing most of your scripting with Python instead of R's programming language and then calling the relevant R functions as needed? No, but if I wanted to do such a thing, I'd look at Sage: http://sagemath.org/ It'll give you acc

[R] Python and R

2009-02-17 Thread Esmail Bonakdarian
Hello all, I am just wondering if any of you are doing most of your scripting with Python instead of R's programming language and then calling the relevant R functions as needed? And if so, what is your experience with this and what sort of software/library do you use in combination with Python