Re: [R] trouble with boot ()

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Thu 01 Jun 2006 - 05:53:00 EST

Rogério Rosa da Silva wrote:
> Dear members,
>
>
> I am trying to use boot () to compute the distributions of a statistic
> of a data set. The statistic is defined in the following code:
>
> eds<-function(x) {
> r<-cor(x)
> paren<-1-abs(r)/2
> denom<-sum(sum(paren)+0.5)
> desvio<-sd(x)
> media<-mean(x)
> a<-desvio/media
> nom<-sum(a*(sum(paren)+0.5))
> eds_abs<-nom/denom
> print(eds_abs)
> }
>
> I need to calculate the nonparametric bootstrap confidence intervals for
> "eds_abs", but I am confuse about how I should call the second argument
> for statistic function (). What I don't understand is where the index
> should be set.
>
> I think I need to reproduce in boot () the following
> loop:
>
> eds_null <- numeric(1000)
> for (i in 1:1000) eds_null[i] <- eds (sample(x,replace=T)),
>
> where "x" is a data matrix (n-by-m) with n rows corresponding to
> individual samples, and m-columns corresponding to the different
> attributes. For example:
>
> x<-data.frame(var1=c(23,657,67,89,23,657,67,89),var2=c(23,45,67,12,23,657,67,89),
> var3=c(25,2009,89,223,23,45,67,12),
> var4=c(1299,456,789,2, 23,45,67,12))
>

>>eds(x)
>>[1] 6.738244

>
>
> Thanks for your time,
>
> Rogério
>

Have you read the help page for ?boot (which is part of package:boot)? If not, please do so as the posting guide suggests. Here's a quick fix for you:

eds <- function(x, rows) {

   x <- x[rows, , drop = FALSE]
   r <- cor(x)
   paren <- 1 - abs(r)/2
   denom <- sum(sum(paren) + 0.5)
   desvio <- sd(x)
   media <- mean(x)
   a <- desvio/media
   nom <- sum(a*(sum(paren) + 0.5))
   eds_abs <- nom/denom
   eds_abs
}

x <- data.frame(var1 = c(23, 657, 67, 89, 23, 657, 67, 89),

                 var2 = c(23, 45, 67, 12, 23, 657, 67, 89),
                 var3 = c(25, 2009, 89, 223, 23, 45, 67, 12),
                 var4 = c(1299, 456, 789, 2,  23, 45, 67, 12))

library(boot)
boot_eds <- boot(x, eds, R = 1000)
plot(boot_eds)
boot_eds



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 01 07:15:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 01 Jun 2006 - 08:10:37 EST.

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