2012-08-10 60 views
3

我是R新手,正在尝试对大量频率数据文件的标准错误进行一些自举估计。我的引导程序在单个数据点上工作正常,但我无法弄清楚如何保存输出。理想情况下,我想只将标准错误写入新文件。将引导程序输出写入文件

这是我到目前为止已经试过:

x = c(1,2,3,4,5,6,7,8,9,10) 
samplemean = function(x, d){return(mean(x[d]))} 
b = boot(x, samplemean, R=1000) 
b 
ORDINARY NONPARAMETRIC BOOTSTRAP 

Call: 
boot(data = x, statistic = samplemean, R = 1000) 

Bootstrap Statistics : 
    original bias std. error 
t1*  5.5 -0.0356 0.9145759 

回答

2

你可以计算在boot对象使用t(复制)插槽的标准误差。

require(boot) 

x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 

samplemean <- function(x, d) {return(mean(x[d]))} 

set.seed(123) 
b <- boot(x,samplemean,R=1000) 
b 
## Bootstrap Statistics : 
##  original bias std. error 
## t1*  5.5 -0.0232  0.90887 

## str(b) first... 
apply(b$t, 2, sd) 
##[1] 0.90887 
+0

谢谢。这工作完美。 – Ashley 2012-09-10 01:35:09

+0

有人可以解释为什么你会得到标准错误,虽然你在'apply(b $ t,2,sd)'函数中调用标准偏差吗? – Mikko 2012-11-23 10:45:48

+0

Bootstrapping可用于模拟难以测量多次的参数的误差。自举复制的标准偏差是测量参数的自举(模拟)标准误差。 – Ashley 2013-01-05 02:24:31

1

引导::: print.boot功能使用这个表达式计算出“性病的错误。”这对于普通的自举报道:如果你想将它写入

sqrt(apply(t, 2L, function(t.st) var(t.st[!is.na(t.st)]))) 

文件,那么你可以传递b$t到它,并使用cat

cat(sqrt(apply(b$t, 2L, function(t.st) var(t.st[!is.na(t.st)]))), file="seboot.txt") 

(目前已经在沿着这些线路是取出NA值的函数一些早期处理) :

t <- matrix(boot.out$t[, index], nrow = nrow(boot.out$t)) 
allNA <- apply(t, 2L, function(t) all(is.na(t))) 
t <- matrix(t[, !allNA], nrow = nrow(t))