# Example normal distribution x <- rnorm(mean = 12, n = 150, sd = 5) mean(x) var(x) 1/150 * sum((x - mean(x))^2) 1/149 * sum((x - mean(x))^2) # compare different estimates means <- numeric(1000) sdsnm1 <- numeric(1000) sdsn <- numeric(1000) for(i in 1:1000) { x <- rnorm(mean = 12, n = 50, sd =5) means[i] <- mean(x) sdsnm1[i] <- 1/(length(x) -1) * sum((x - mean(x))^2) sdsn[i] <- 1/(length(x)) * sum((x - mean(x))^2) } mean(means) mean(sdsnm1) mean(sdsn) par(mfrow = c(1,2)) boxplot(means) abline( h = 12, lwd = 2, lty = 2) dev.off() boxplot(cbind(sdsnm1, sdsn), ylim = c(10,40)) abline( h = 25, lwd = 2, lty = 2) boxplot(cbind(sqrt(sdsnm1), sqrt(sdsn))) abline( h = 5, lwd = 2, lty = 2) #------------ # unif-distribution U(0, theta) # estimation of max -> theta t1 <- numeric(1000) t2 <- numeric(1000) for(i in 1:1000) { x <- runif(min = 0, max = 10, n = 100) t1[i] <- mean(x) t2[i] <- ((length(x)+ 1)/length(x) * max(x))/2 } mean(t1) mean(t2) summary(t2) summary(t1) boxplot(cbind(t1, t2)) hist(x, breaks = 50)