Вопрос

I want to get the bootstrap statistics by group for a long data.

Is there an easy way to extract the bootstrap statistics (mean and standard error) from the output in form of a table given below?

    data <- data.frame(list(value = runif(300), group = factor(letters[1:4])))
    stat <- function(x, i)  c(m1 = mean(x$value[i]))
    library(plyr);library(boot)
    aa=dlply( data, .(group), function( dat ) boot(dat, stat, R=10) )


group| mean| std.error
a    |0.51 |0.035
b    |0.56 |0.046
c    |0.52 |0.034
d    |0.61 |0.017

Thanks,

Это было полезно?

Решение

Have a look at the object returned by boot str(aa[[1]]), then you'll see how to extract the relevant statistics.

ldply(aa, .fun=function(x) data.frame(mean = mean(x$t), 
                                      std.err = sd(x$t)))
  group      mean     std.err
1     a 0.5309598 0.04168062
2     b 0.5194311 0.02583568
3     c 0.5064817 0.02791644
4     d 0.4512118 0.03417612
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top