loop in r until value converges and stores all the outputs -
I would like to repeat this process until there is no condition to censor results.
Here is a simple matter, where I know the number of cycles in order to perform a loop:
# Example of figures Speplus & lt; - rnorm (100,50,50) encyclopedia and lt; - 1000 outcomes & lt; - Matrix (Enro = Encyclix, Nackel = 1) Repeat the process of # N chakras
for (i (sample (SMPLS, 50) ) 1 / NCK () (Output) (SMPLS, 50)) P> But my case is different in that sense I do not know the nosy. I want to continue sampling until the samples get very little variance or convergence (I think this is "while" loop. For example, unless vsd is less than 1 in the following case. vsd & lt; - (SMD, 50)) while (vs> 1) {outm [i] & lt; - Mean (sample (SMPLS, 50)) vsd & lt; - SD
Edit: - rnorm (100,50,50) ITER & lt; - 0 # Maximum Travel Itermax & LT; - 1000 outm & lt; - Representative (NA, itermax) vsd & lt; - 2, while ((vsd> 1) & amp; (ITER's & lt; itermax)} {outm [ITER] & lt; - Mean (sample (smpls, 50)) vsd & lt; - SD (outm) ITER & lt; Error in late ITER + 1} ((vsd> 1) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp & amp; amp; amp; amp; amp; amp & amp; amp · amp; amp · amp; amp;;; The main idea of reaching convergence is to save it, though with the above example only the mean function is fast, in my original function it requires important timing to be reiterated e and I I want to stop it when it is converged.
Here's a solution:
data set.seed (123) # so that you will repeat what I have done; & Gt; - rnorm (1005050) I think you need some initial cycles (minimum iterations) so that you can get false convergence because you have very few samples Run some specimens - say Ministers You need a maximum trend so that your loops are not wild - say maxter
Earthcovers tolerance) {ITER & lt; - miniter + 1 sdout & lt; - Representative (NA, maxiter), while ((vsd> Tolerance) & amp; amp; (ITER's & lt; maxiter)) {ITER & lt; - ITER + 1 outm [ITER] & lt; - Mean (sample (smpls, 50)) vsd & lt; - SD (outm, na.rm = TRUE) sdout [iter] & lt; - vsd} Out & lt; - List (outm, sdout) returns (outside)} and {return (outm)}} & lt; - meanconverge (= ([2]), pp = ".", col = "red") img src = "https: //i.stack.imgur .com / zUabJ.jpg "alt =" Enter image details here ">
plot (uplist (outside [1]), pp =". ", col =" red ") < / code>
< / html>
Comments
Post a Comment