[R] Sample mean in R
dilian
dilian.s at gmail.com
Sun Oct 5 22:00:00 CEST 2008
I am having issues with the following:
(muhat = 1/n^2(sum of all the xi's) )
essentially if xbar = the sample mean, muhat = sample mean but square the n.
Question:
Use R to run a Monte Carlo simulation which compares the finite-sample
performance of xbar and muhat. Specifically generate 1000 samples n=30 from
a standard normal distribution. For each sample calculate xbar and muhat. I
have no problem calculating the mean of the xbar's - however I cannot figure
out how to set up the muhat variable and find the means. My code is as
follows:
# R code starts here
rm(list=ls())
set.seed(100)
n<-30
s<-1000
xbar<-rep(0,s)
muhat<-rep(0,s)
for (i in 1:s) {
x<-rnorm(0,n=10)
xbar[i]<-mean(x)
muhat[i]<-mean(x^(-1/2))
}
cat("Estimated mean of xbar:",mean(xbar),"\n")
cat("Estimated mean of muhat:",mean(muhat),"\n")
Any help would be greatly appreciated.
--
View this message in context: http://www.nabble.com/Sample-mean-in-R-tp19828546p19828546.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list