library("ggplot2");
run <- function(n_trials,n){
data = NULL;
for(i in 1:n_trials){
new_data = rexp(n,0.2);
std = sd(new_data);
#print(std);
mu = mean(new_data);
data = c(data,mu);
#print(i);
}
ans_std=sd(data);
ans_mu=mean(data);
print("ans_std:");
print(ans_std);
print("ans_mu:");
print(ans_mu);
data;
}
plot_data = run(1000,40);
## [1] "ans_std:"
## [1] 0.8103587
## [1] "ans_mu:"
## [1] 4.960514
qplot(plot_data,geom = c("histogram"),binwidth = 0.1);
This distribution is a normal distribution. The center(mean) is printed above. So does standard deviation. The theoretical value for both is 5. The real value of mean is very close to the real ones. However the real value of standard deviation is deviated heaily from the theoretical value.
qplot(rexp(1000,0.2));
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
As you see , it’s not a bell-shape plot.