[R] How to save boot objects?
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu Oct 25 18:49:25 CEST 2001
Hans Gardfjell <hans.gardfjell at eg.umu.se> writes:
> 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)
> ...
>
> > 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?
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).
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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