MonteCarlo test with selective sampling


I am performing a MonteCarlo Test for a set of more than 1 million values. Is time consuming to make it run for every single value so I decided to go for a sample size of 10000, 20000, 30000 etc. But, I am having problems re arreging the SaSi.

SaSi<- c(flux)
for(j in 1:SaSi)

run<-100 # run 1000 times (the more often you run, the smoother the output curve becomes, but the longer it takes)
for (i in 1:run) #loop
a<-sample(as.numeric(flux), j, replace=TRUE, prob=NULL) #draw random sample from flux, sample size j
b<-mean(a) #mean value of sample
y[i]<-b # write mean value into empty vector
cv<-sd(y)/mean(y)*100 #calculate Coefficiant of variance for respective sample size
plot(SS, CV, type="l", ylab="CV (%)", xlab= "sample size")

I did it manually like SaSi<-c(100000, 200000, ...), but it does not work. I got this error> Warning message:
In 1:SaSi : numerical expression has 2 elements: only the first used

Any suggestion is very welcome.

It sounds like you want to do some iteration, I.e. run a function multiple times, with differing parameters for these runs?

Yes thats what I want, the idea is that for every selected sample, starting from 10000 and proportionally incresing to 1million, to run the code 100 times or more for each one. So at the end I get something like this image

I mostly use the purrr function for iteration in R.
21 Iteration | R for Data Science (

Thank you,
I will take a look on that function!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.