0

I have a standard deviation, mean, and sample size. I'm needing to create a loop that will generate 5000 sample means

How do I go about doing so?

WW93
  • 3
  • 2

1 Answers1

1
set.seed(123)
#Data
mean.val <- 2
sd.val <- 0.5
nsamples <- 5000
#Empty matrix
Mymat <- matrix(0,nrow = nsamples,ncol = nsamples)
#Fill
for(i in 1:nsamples)
{
  Mymat[,i]<-rnorm(nsamples,mean = mean.val,sd=sd.val)
}
#Compute values
vecupper <- apply(Mymat,2,function(x) mean(x)+2.66*sum(abs(diff(x)))/length(x))
veclow <- apply(Mymat,2,function(x) mean(x)-2.66*sum(abs(diff(x)))/length(x))
WW93
  • 3
  • 2
Duck
  • 39,058
  • 13
  • 42
  • 84
  • Ok that worked well, now if I wanted to compute the upper and lower limit of each sample from the 5000 I couldn't just use: 2s = mean(vecmean) + 2.66*sum(abs(diff(vecmean)))/length(vecmean) b/c it gives me only 1 single upper and lower limit – WW93 Nov 18 '20 at 22:38
  • 1
    @WW93 Just a moment, do you want 5000 samples of 5000 values? – Duck Nov 18 '20 at 22:40
  • So I got the 5000 samples, I'm now being asked to compute the upper and lower limit of each of the individual 5000 samples – WW93 Nov 18 '20 at 22:40
  • @WW93 I have added an update, Hoping that helps you! – Duck Nov 18 '20 at 22:50
  • you rock!!!!!!! – WW93 Nov 18 '20 at 22:54
  • @WW93 Great! If this answer solved your issue consider accepting it https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Duck Nov 18 '20 at 22:57
  • @WW93 I have accepted your update, consider potentially accepting the answer if this helped! – Duck Nov 19 '20 at 00:24