Re: [R] Improving effeciency - better table()?

From: Simon Cullen <cullens_at_tcd.ie>
Date: Wed 07 Jul 2004 - 02:11:38 EST

On Tue, 6 Jul 2004 09:02:26 -0400, Liaw, Andy <andy_liaw@merck.com> wrote:

> Since you didn't provide an example of what z.trun and breaks may look
> like, most people can only guess. Before asking how code can be made
> more
> efficient, it might be more helpful to find out where in the code is
> taking
> time. Try:
>
> Rprof()
> obs <- table(cut2(z.trun, cuts=breaks))
> Rprof(NULL)
> summaryRprof()

Thanks, Andy. That helped to clear up some of my confusion. I have now eliminated the call to cut2 and table and replaced that with hist, as suggested by Roger Peng.

However I had changed much more code than I had initially realised and it seems that the other code is having a larger effect. I've attached the output of an experiment (a power test with 1000 iterations - code included) and it seems that the problem is getting the expected number of observations in each cell. I have to integrate the density that I am working with in order to do this as it isn't standard.

I know that, firstly, using a for() loop is bad but the problem didn't lend itself to vectorisation (I thought). Any help would be appreciated.

-- 
SC

Simon Cullen
Room 3030
Dept. Of Economics
Trinity College Dublin

Ph. (608)3477
Email cullens@tcd.ie

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Received on Wed Jul 07 02:12:23 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:45:35 EST