# 2005 年 06 月 07 日作成 # number of repeated sample no.rep<-1000 # sample size no.sample<-5 # population of mixed normals x1<-round(rnorm(700,70,7)) x2<-round(rnorm(300,40,8)) x<-c(x1,x2) x<-c(x1,x2) # parameter of population distribution mean(x);median(x);sd(x);var(x) xbar<-rep(0,no.rep) xmedian<-rep(0,no.rep) for(i in 1:no.rep){ r<-trunc(runif(no.sample)*1000)+1 xbar[i]<-mean(x[r]) xmedian[i]<-median(x[r]) } # plotting population density plot(density(x),xlim=c(0,100),ylim=c(0,0.1)) par(new=T) # plotting sample distribution of sample mean plot(density(xbar),xlim=c(0,100),ylim=c(0,0.1)) par(new=T) # plotting sample distribution of sample median plot(density(xmedian),xlim=c(0,100),ylim=c(0,0.1))