R 平均分布图CLT

R 平均分布图CLT,r,ggplot2,histogram,R,Ggplot2,Histogram,我想画一个平均分布的CLT 对于样本量为30和100的$\theta=0.5$和$\theta$=0.7。我想在柱状图上画出分布图 $$ \hat{\theta}(Y)\equiv\hat{\theta}=\bar{Y}=\frac{1}{n}\sum{i=1}^{n}Y{i} $$ i、 例如,$\hat{\theta}$等于样本平均值,然后,根据我们的估计满足的CLT $$ \hat{\theta}\stackrel{d}{\rightarrow}\mathcal{N}(\theta,v(\

我想画一个平均分布的CLT

对于样本量为30和100的$\theta=0.5$和$\theta$=0.7。我想在柱状图上画出分布图

$$ \hat{\theta}(Y)\equiv\hat{\theta}=\bar{Y}=\frac{1}{n}\sum{i=1}^{n}Y{i} $$ i、 例如,$\hat{\theta}$等于样本平均值,然后,根据我们的估计满足的CLT $$ \hat{\theta}\stackrel{d}{\rightarrow}\mathcal{N}(\theta,v(\theta)/N) $$

对于上述理论,我开发了以下代码:

Simulation <- function(n, theta, simulation){
    mean = theta
    var = (theta*theta - theta)/n
    a = rnorm(simulation,mean,var)
    dens <- density(a)
    hist(clt_test, freq=F, xlab = n)
    lines(dens,col ='blue')
}

Theta <- c(0.5, 0.7)
N <- c(30,100)
set.seed(1)
for(theta in Theta){
    for(n in N){
                Simulation(n, theta, simulation)
    }
}
模拟