Re: [R] bootstrap for confidence intervals of the mean

2008-04-22 Thread Gavin Simpson
On Tue, 2008-04-22 at 12:59 -0400, stephen sefick wrote:
 d = c(0L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0L, 0L, 7375L,
 NA, NA, 17092L, 0L, 0L, 32390L, 2326L, 22672L, 13550L, 18285L)
 
 boot.out -boot(d, mean, R=1000, sim=permutation)
 
 Error in mean.default(data, original, ...) :
   'trim' must be numeric of length one
 
 I know that I am missing something but I can't figure it out.

You aren't reading the documentation closely enough. ?boot informs us
that for all sim other than parametric, 'statistic' must be a function
that takes two arguments. The second argument to mean.default is trim,
and boot is passing to mean a vector of indices as argument 'trim' which
it is not expecting and quite rightly throws a wobbly.

Write a wrapper to mean, that accepts two arguments, one the data vector
and one the permuted indices, then use these to form a call to mean ---
here mean.fun does this (note we turn on removing NA's by default
otherwise it wouldn't work)

 mean.fun - function(dat, idx) mean(dat[idx], na.rm = TRUE)
 boot.out - boot(d, mean.fun, R=1000, sim=ordinary)
 boot.out

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = d, statistic = mean.fun, R = 1000, sim = ordinary)


Bootstrap Statistics :
originalbiasstd. error
t1* 9474.167 -3.3734223110.968

There doesn't seem to be much point in permuting the data here, the mean
will be the same, regardless of what permutation you take. The above
does an ordinary bootstrap instead.

HTH

G

 thanks
 
 stephen
 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] bootstrap for confidence intervals of the mean

2008-04-22 Thread Robert A LaBudde
See the help for boot().

The function in the 2nd argument has to be of a special form.

You need to define such a form, as in:

fmean- function (x, i) mean(x[i]) #use data x[] and indices i

and then

boot.out- boot(d, fmean, R=1000, sim='permutation')

At 12:59 PM 4/22/2008, stephen sefick wrote:
d = c(0L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0L, 0L, 7375L,
NA, NA, 17092L, 0L, 0L, 32390L, 2326L, 22672L, 13550L, 18285L)

boot.out -boot(d, mean, R=1000, sim=permutation)

Error in mean.default(data, original, ...) :
   'trim' must be numeric of length one

I know that I am missing something but I can't figure it out.
thanks

stephen

--
Let's not spend our time and resources thinking about things that are so
little or so large that all they really do for us is puff us up and make us
feel like gods. We are mammals, and have not exhausted the annoying little
problems of being mammals.

-K. Mullis

 [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

Vere scire est per causas scire

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.