我想拟合一条穿过共享图上采样分布平均值的线。这段代码创建了一个与我正在使用的数据集相似的数据集。它创建一个抽样分布并将分布绘制在相同的图表上。然后,我画一条穿过分布平均值的线。但是,我想要一条适合所有分布均值的线。我在想像这张图在这里找到的东西。
means<-c(NULL)
sample<-rnorm(1000,-0.2,0.1)
A<-hist(sample,plot=FALSE)
means<-c(means,mean(sample))
sample<-rnorm(1000,-0.1,0.1)
B<-hist(sample,plot=FALSE)
means<-c(means,mean(sample))
sample<-rnorm(1000,0,0.1)
C<-hist(sample,plot=FALSE)
means<-c(means,mean(sample))
sample<-rnorm(1000,0.1,0.1)
D<-hist(sample,plot=FALSE)
means<-c(means,mean(sample))
sample<-rnorm(1000,0.2,0.1)
E<-hist(sample,plot=FALSE)
means<-c(means,mean(sample))
plot(NULL,type="n",
xlim=c(0,1250),
ylim=c(min(A$breaks,B$breaks,C$breaks,D$breaks,E$breaks),
max(A$breaks,B$breaks,C$breaks,D$breaks,E$breaks)),
xaxt="n",
xlab="Mean",
ylab="Sampling Distribution of The Mean")
labels<-c("-0.2","-0.1","0","0.1","0.2")
y.coord<-0
rect(y.coord, A$breaks[1:(length(A$breaks) - 1)], A$counts, A$breaks[2:length(A$breaks)])
axis(side=1,at=y.coord,labels=labels[1],las=3)
y.coord<-max(A$counts)+50
rect(y.coord, B$breaks[1:(length(B$breaks) - 1)], y.coord+B$counts, B$breaks[2:length(B$breaks)])
axis(side=1,at=y.coord,labels=labels[2],las=3)
y.coord<-y.coord+max(B$counts)+50
rect(y.coord, C$breaks[1:(length(C$breaks) - 1)], y.coord+C$counts, C$breaks[2:length(C$breaks)])
axis(side=1,at=y.coord,labels=labels[3],las=3)
y.coord<-y.coord+max(C$counts)+50
rect(y.coord, D$breaks[1:(length(D$breaks) - 1)], y.coord+D$counts, D$breaks[2:length(D$breaks)])
axis(side=1,at=y.coord,labels=labels[4],las=3)
y.coord<-y.coord+max(D$counts)+50
rect(y.coord, E$breaks[1:(length(E$breaks) - 1)], y.coord+E$counts, E$breaks[2:length(E$breaks)])
axis(side=1,at=y.coord,labels=labels[5],las=3)
abline(a=means[1],b=0,col="red")
abline(a=means[2],b=0,col="red")
abline(a=means[3],b=0,col="red")
abline(a=means[4],b=0,col="red")
abline(a=means[5],b=0,col="red")
这个问题是我的问题here的后续。如您所见,我创建了一个变通方法来绘制所有小倍数。但是,我仍然在拟合线方面遇到问题。
感谢您考虑这个问题。