[R] Finding the bootstrapped coefficient of variation and the stderr on the CV(boot)

From: D Cornacchia <cornaclia_at_rogers.com>
Date: Wed, 09 Jun 2010 19:11:53 -0400


Dear R-Helpers,

I am trying to bootstrap the coefficient of variation on a suite of vectors, here I provide an example using one of the vectors in my study. When I ran this script with the vector x <-c(0.625, 0.071428571, 0.133333333, 0.125, 0), it returned CV(boot) [the second one], and stderr(boot) [the second one] without problem. However, when I ran it with the vector in the following example, I received NA for the latter two statistics. I cannot figure out what is missing, why it won't work with this vector, and how I can rectify this situation. Your input would be greatly appreciated!

x <-c(1, 0, 0.153846154, 0, 0.142857143) mean (x)
sample(x,replace=T)
mean(sample(x,replace=T))
boot <-numeric(991)
for (i in 1:991) boot[i] <- mean(sample(x,replace=T)) mean(boot)
var(boot)
sd(boot)
stderr <- function(boot) sqrt(var(boot)/length(boot)) stderr(boot)
median(boot)
min(boot)
max(boot)
range(boot)
IQR(boot)
quantile(boot,0.975)
quantile(boot,0.025)
bias <- mean(boot) - mean(x)

mean(x) - bias
mean(x) - bias - 1.96*sqrt(var(boot))
mean(x) - bias + 1.96*sqrt(var(boot))

CV <- function(x) sqrt(var(x))/mean(x)
CV(x)
CV(boot)
N <- boot
CV(x)
CV(sample(x,replace=T))
boot <-numeric(991)
for (i in 1:991) boot[i] <- CV(sample(x,replace=T)) CV(boot)
stderr(boot)
P <- boot
hist(N)
t.test (x, N)
ks.test(x, N)

Many thanks,
D.

p.s. I am very new to R.

        [[alternative HTML version deleted]]



R-help_at_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. Received on Wed 09 Jun 2010 - 23:16:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jun 2010 - 00:50:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive