[R] sapply and loop

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 19 08:29:54 CEST 2004


On Tue, 19 Oct 2004, Zhen Pang wrote:

> I tried to use Rprof(). As an example, I consider the following code (from 
> Venables & Ripley, 1999).

I believe you parroted that from `Writing R Extensions', but failed to 
give proper credit!

>      library(MASS); library(boot); library(nls)
>      data(stormer)
>      storm.fm <- nls(Time ~ b*Viscosity/(Wt - c), stormer,
>                      start = c(b=29.401, c=2.2183))
>      st <- cbind(stormer, fit=fitted(storm.fm))
>      storm.bf <- function(rs, i) {
>          st$Time <-  st$fit + rs[i]
>          tmp <- nls(Time ~ (b * Viscosity)/(Wt - c), st,
>                     start = coef(storm.fm))
>          tmp$m$getAllPars()
>      }
>      rs <- scale(resid(storm.fm), scale = FALSE) # remove the mean
>      Rprof("boot.out")
>      storm.boot <- boot(rs, storm.bf, R = 4999) # pretty slow
>      Rprof(NULL)

At this point your unacknowledged copying went adrift.

> summaryRprof()
> Error in summaryRprof() : no events were recorded
> 
> I am using R1.8.1 in windows. Why can't I get the results?

Because you didn't do your homework, and didn't even follow your source.  
The 'file' arguments of Rprof and summaryProf have to agree: see their 
help pages (as the posting guide asks).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list