我希望能够获得一个线性模型的自举t值和自举p值。下面是一段代码,基本上是从一篇论文中复制过来的,并且已经可以正常使用。
# First of all you need the following packages
install.packages("car")
install.packages("MASS")
install.packages("boot")
library("car")
library("MASS")
library("boot")
boot.function <- function(data, indices){
data <- data[indices,]
mod <- lm(prestige ~ income + education, data=data) # the liear model
# the first element of the following vector contains the t-value
# and the second element is the p-value
c(summary(mod)[["coefficients"]][2,3], summary(mod)[["coefficients"]][2,4])
}
现在,我计算引导模型,结果如下:
duncan.boot <- boot(Duncan, boot.function, 1999)
duncan.boot
ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = Duncan, statistic = boot.function, R = 1999)
Bootstrap Statistics :
original bias std. error
t1* 5.003310e+00 0.288746545 1.71684664
t2* 1.053184e-05 0.002701685 0.01642399
我有两个问题:
1. 我的理解是,bootstrapped value指的是原始值加上偏差,这意味着bootstrapped t-value和bootstrapped p-value都比原始值大。然而这是不可能的,因为如果t-value升高(也就是更显著),p-value一定会降低,对吧?因此我认为我还没有真正理解boot函数的输出结果(这里是duncan.boot)。那么我该如何计算bootstrapped values?
2. 我不明白boot()是如何工作的。如果你看一下"duncan.boot <- boot(Duncan, boot.function, 1999)",你会发现我没有传递任何参数给函数"boot.function"。我想R设置了"data <- Duncan"。但由于我没有为参数"indices"传递任何内容,我不明白函数"boot.function"中的以下代码如何工作:"data <- data[indices,]"。
希望我的问题表述清晰!
plot(duncan.boot$t[,1],duncan.boot$t[,2])
。但这并不意味着更高的自助估计T值将与更低的偏差估计p值相关联。 - IRTFM