[R] trouble with boot ()
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Wed May 31 21:53:00 CEST 2006
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
More information about the R-help
mailing list