Skip to content

How to save boot objects?

3 messages · Hans Gardfjell, Peter Dalgaard, Douglas Bates

#
Hi,

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)
...
+ sum(d$x * w)/sum(d$u * w)
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)...
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



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hans Gardfjell <hans.gardfjell at eg.umu.se> writes:
You could use save/load instead.

The cause for the trouble seems to be that the dumped data end up with

1.52199762187872, 1.4321608040201, 1.32309746328438, 1.47077922077922, 
1.66085578446910, 1.78693181818182), .Dim = c(999, 1)), R = 999, 
    data = structure(list(u = c(138, 93, 61, 179, 48, 37, 29, 
    23, 30, 2), x = c(143, 104, 69, 260, 75, 63, 50, 48, 111, 
    50)), .Names = c("u", "x"), row.names = c("1", "2", "3", 
    "4", "5", "6", "7", "8", "9", "10"), class = "data.frame"), 
    seed = c(1, 1433911782, 1092627872), statistic = function (d, w) 
    sum(d$x * w)/sum(d$u * w), sim = "ordinary", call = boot(data = city, 
        statistic = ratio, R = 999, stype = "w"), stype = "w", 
    strata = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), weights = c(0.1, 
    0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1)), .Names = c("t0", 
"t", "R", "data", "seed", "statistic", "sim", "call", "stype", 
"strata", "weights"), class = "boot")

with the culprit being the

call = boot(data = city, statistic = ratio, R = 999, stype = "w")

We might need to put a quote() around language objects when deparsing
lists. 

Same thing happens with lm objects, and S-PLUS has the same problem
with those, so at least we're bug-compatible...

Fundamentally, the problem is that R/S objects aren't always
deparseable (and even when they are, parse and reparse are not unique
inverses).
#
Hans Gardfjell <hans.gardfjell at eg.umu.se> writes:
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
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.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._