Professional Documents
Culture Documents
###############
library(boot)
get.r=function(data,indices){
## order rows of data by 'indices':
data=data[indices,]
## Calculate r:
r=cor(data$LSAT,data$GPA)
return(r)
}
boot.out=boot(law,get.r,R=1000)
boot.ci(boot.out,conf=0.90,type="perc")
###############
library(car)
attach(Anscombe)
head(Anscombe)
plot(income,education)
lm.out=lm(education ~ income)
par(mfrow=c(1,2))
plot(lm.out$fitted.values,lm.out$residuals,pch=16)
abline(h=0)
qqnorm(lm.out$residuals,pch=16)
qqline(lm.out$residuals)
get.coeffic=function(data,indices){
data=data[indices,]
lm.out=lm(education ~ income,data=data)
return(lm.out$coefficients)
}
n=nrow(Anscombe)
get.coeffic(Anscombe,1:n)
boot.out=boot(Anscombe,get.coeffic,R=1000)
boot.out$t
boot.ci(boot.out,index=2,conf=0.95,type="perc")
boot.ci(boot.out,index=1,type="perc",conf=0.95)
plot(c(-.01,0.09),c(-100,125),type="n",xlab="slope",
ylab="intercept")
points(boot.out$t[,2],boot.out$t[,1],col=2)
dataEllipse(boot.out$t[,2],boot.out$t[,1],levels=c(.5,.95,.99),add=TRUE,plo
t.points=FALSE,col=1)
abline(h=0,lwd=2)
abline(v=0,lwd=2)
apply(boot.out$t,2,mean)