10.8 Bootstrap with regression

本文介绍了一种替代方法来估计回归参数的置信区间,即使用自助法(bootstrapping)。文中提供了两种自助法实现方式:一种是对样本进行放回抽样;另一种是通过回归残差的随机化来实现。此外,还给出了具体的R语言代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

An alternative to estimating confidence intervals on the regression parameters from the pooled error variance
in the ANOVA table (p. 459) is to use bootstrapping. There are two ways of doing this:
sample cases with replacement, so that some points are left off the graph while others appear more than
once in the dataframe;
calculate the residuals from the fitted regression model, and randomize which fitted y values get which

residuals

regdat <- read.table("c:\\temp\\regdat.txt",header=T)
attach(regdat)

names(regdat)

plot(explanatory,response,pch=21,col="green",bg="red")
model <- lm(response~explanatory)

abline(model,col="blue")

model

b.boot <- numeric(10000)
for (i in 1:10000){
indices <- sample(1:35,replace=T)
xv <- explanatory[indices]
yv <- response[indices]
model <- lm(yv~xv)
b.boot[i] <- coef(model)[2]
}

hist(b.boot,main="",col="green")

quantile(b.boot,c(0.025,0.975))


library(boot)

reg.boot <- function(regdat, index){
xv <- explanatory[index]
yv <- response[index]
model <- lm(yv~xv)
coef(model)

}

reg.model <- boot(regdat,reg.boot,R=10000)

boot.ci(reg.model,index=2)


model <- lm(response~explanatory)
fit <- fitted(model)

res <- resid(model)


residual.boot <- function(res, index){
y <- fit+res[index]
model <- lm(y~explanatory)

coef(model) }


res.model <- boot(res,residual.boot,R=10000)

boot.ci(res.model,index=2)







评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值