如何实现散点图,拟合曲线以及置信线在同一张图里,跪求大神指导接下来的代码如何写呀
boot<-function(x,pr,fboot,B)
{
Tboot=0
for(i in 1:B)
{ Y=sample(x,20,prob=pr,replace=TRUE)
Tboot[i]=fboot(Y)
}
Tboot
}
Data=matrix(0,ncol=20,nrow=10)
Data[1,]=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1)
Data[2,]=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2)
Data[3,]=c(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,3)
Data[4,]=c(0,0,0,0,0,0,0,1,1,1,2,2,2,2,2,3,3,4,4,5)
Data[5,]=c(0,0,0,1,1,2,2,3,3,3,3,3,4,4,4,4,5,6,7,7)
Data[6,]=c(1,2,2,2,3,3,4,4,4,4,4,5,5,5,5,5,6,6,7,8)
Data[7,]=c(3,3,3,5,5,6,6,7,7,7,7,8,8,8,8,9,9,9,12,13)
Data[8,]=c(3,4,6,7,8,8,8,8,9,9,9,10,10,10,11,11,11,12,13,16)
Data[9,]=c(5,6,7,8,8,9,9,9,9,10,10,10,10,11,11,12,12,13,16,16)
Data[10,]=c(5,6,6,7,8,8,9,10,11,11,11,11,12,12,13,13,13,15,16,18)
T=matrix(0,ncol=10000,nrow=10)
for(i in 1:10)
{ x=Data[i,]
pr=c(1/20,1/20,1/20,1/20,1/20,1/20,
1/20,1/20,1/20,1/20,1/20,1/20,
1/20,1/20,1/20,1/20,1/20,1/20,1/20,1/20)
tb=boot(x,pr,mean,10000)
T[i,]=tb
}
A=matrix(0,ncol=10000,nrow=10)
A[1,]=T[1,]/0.5 A[2,]=T[2,]/1 A[3,]=T[3,]/2 A[4,]=T[4,]/4 A[5,]=T[5,]/6 A[6,]=T[6,]/8 A[7,]=T[7,]/10 A[8,]=T[8,]/12 A[9,]=T[9,]/14 A[10,]=T[10,]/16 x<-c(T[1,],T[2,],T[3,],T[4,],T[5,],T[6,],T[7,],T[8,],T[9,],T[10,]) y<-c(A[1,],A[2,],A[3,],A[4,],A[5,],A[6,],A[7,],A[8,],A[9,],A[10,]) fit<-lm(y~x+I(x^2))
|