[R] How to save boot objects?

Douglas Bates bates at stat.wisc.edu
Thu Oct 25 18:55:38 CEST 2001


Hans Gardfjell <hans.gardfjell at eg.umu.se> writes:

> I have problem with saving and later sourcing boot objects. A short
> familiar example...
> 
> R : Copyright 2001, The R Development Core Team
> Version 1.3.1  (2001-08-31)
> ...
> 
> > library(boot)
> > data(city)
> > ratio <- function(d, w)
> + sum(d$x * w)/sum(d$u * w)
> > boot.res<-boot(city, ratio, R=999, stype="w")
> > dump("boot.res","boot.res.R")
> >
> Save workspace image? [y/n/c]: n
> hans at poa:~/seedtest$ R
> 
> R : Copyright 2001, The R Development Core Team
> Version 1.3.1  (2001-08-31)...
> 
> > source("boot.res.R")
> Error in structure(list(t0 = 1.5203125, t =
> structure(c(1.24632352941176,  :
>         couldn't find function "boot"
> >
> When sourcing the boot object it seems that if R is rerunning the
> bootstrap procedure again.
> 
> My plan was to run  several boot commands from within a battchfile on a
> remote server. "Dumping" them and later pick them up and calculate CI
> etc. Why is dump/source behaving like this on boot objects? Does anyone
> of you have a better suggestion than using dump for saving boot objects?
> 
> Thanks,
> 
> Hans Gardfjell
> Umeå University

Try using save/load instead of dump and source.  The source function
evaluates the expression it is given and the call that generates the
bootstrap sample is probably saved with the sample.

I used

> library(boot)
> data(city)
> ratio <- function(d, w) sum(d$x * w)/sum(d$u * w)
> boot.res <- boot(city, ratio, R=999, stype="w")
> save(boot.res, file = "/tmp/boot.res.rda")
> q("no")

then started a fresh session and was able to load the saved file
without including the boot library.

R : Copyright 2001, The R Development Core Team
...
Type `demo()' for some demos, `help()' for on-line help, or
`help.start()' for a HTML browser interface to help.
Type `q()' to quit R.

> load("boot.res.rda")
> q()
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list