Re: [R] Simulating mid-points from a defined range

2025-06-06 Thread Bert Gunter
Richard O'Keefe pointed out that I was wrong; the distributions are in fact different. One (now!) "obvious" reason why is that for the order statistics, the distribution of the max is clearly skewed. For my cumsum method, the max is clearly uniform (on [0,55] for the specific example). Context ma

Re: [R] Simulating mid-points from a defined range

2025-06-05 Thread Bert Gunter
... and here is a a simple 2-liner without a sort that I think is linear in time and space (but please correct if this is wrong): x <- cumsum(runif(10)) x/x[10] * runif(1, 0, 55) + seq.int(0, 45,5) Question: Does this give the same distribution as Peter's method using the order statistics? I bel

Re: [R] Simulating mid-points from a defined range

2025-06-05 Thread Bert Gunter
Richard: "The "use an upper bound of 100 - (n+1)*5" and then "add back cumsum(rep(5,n)) at the end" (or equivalent) trick ensures the gaps are right but does nothing about the distribution.." If I understand you correctly, I think the above is wrong. Here is a one-line version of Peter's code for

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Richard O'Keefe
The Bentley and Saxe paper answers the questions (1) How can I draw a sample of n numbers in the range 0..1 such that the numbers are returned in increasing order WITHOUT sorting and so that all such sequences are equally likely in LINEAR time. That's the code I showed in R. (2) How can I do this

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Bert Gunter
In Peter's solution, just sample without replacement from integers instead of generating random uniforms. See ?sample. -- Bert On Wed, Jun 4, 2025 at 5:23 AM Brian Smith wrote: > Hi, > > I dont see from the solution pov they are different. > > One followup Q though, how can I extend this to dr

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Bert Gunter
To answer my own question, yes they are different. Peter's code can generate the solution 1 20 26 32 38 44 50 56 62 68. Mine cannot. So, again, context? -- Bert On Wed, Jun 4, 2025 at 4:43 AM Bert Gunter wrote: > Is Peter's solution different then: > > diffs <- cumsum(runif(9, 5, 100/9)) > x

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Sergei Ko
Hi! It's possible I'm wrong. But for me it looks like: n_sample <- 300 v <- round(runif(n_sample, 0, 100), 2) m <- matrix(v, ncol = 10) m_s <- t(apply(m, 1, sort)) m_d <- t(apply(m_s, 1, diff)) m_5 <- m_d>=5 f <- rowSums(m_5) == 9 sum(f) res <- m_s[f, ] Regards, Sergiy On Wed, Jun 4, 2025 at 1

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Brian Smith
Okay, I think I found the reason. This is due to accumulation of nine 5s in the cumsum. Thanks again for the elegant solution. But I wonder, if the solution is simple then what is the significance of the Research paper by Bentley and Saxe naming “Generating sorted lists of random numbers” which Ri

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Brian Smith
Hi Peter, Could you please help me to understand what is the basis of choosing 55 in runif(10,0,55))? Thank you! On Wed, 4 Jun 2025 at 02:45, peter dalgaard wrote: > > Can't you just generate 10 values in (0,55), sort them, generate the > distances, add 5 and cumulate? > > > x <- sort(runif(10

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Brian Smith
Hi, I dont see from the solution pov they are different. One followup Q though, how can I extend this to draw only integer mid-point between 0-100 while maintaining minimum difference as 5? Also, are all generated points are equally likely? Thanks for your time and suggestions. Thanks and rega

Re: [R] Simulating mid-points from a defined range

2025-06-04 Thread Bert Gunter
Is Peter's solution different then: diffs <- cumsum(runif(9, 5, 100/9)) x <-runif(1,0,100-diffs[9]) c(x, x+diffs) I ask because: 1. If yes, this is why more context is needed; 2. If no, the above avoids a sort. Cheers, Bert On Tue, Jun 3, 2025 at 2:15 PM peter dalgaard wrote: > Can't you j

Re: [R] Simulating mid-points from a defined range

2025-06-03 Thread peter dalgaard
Can't you just generate 10 values in (0,55), sort them, generate the distances, add 5 and cumulate? > x <- sort(runif(10,0,55)) > d <- diff(x)+5 > cumsum(c(x[1],d)) [1] 12.27815 21.21060 26.37856 36.03812 41.97237 57.02945 67.86113 [8] 75.74085 81.28533 98.30792 > On 3 Jun 2025, at 09.21, Br

Re: [R] Simulating mid-points from a defined range

2025-06-03 Thread Brian Smith
Hi Richard, Thanks for your insight. As I mentioned in one of my earlier emails to the group, I imposed a constraint of accuracy up to two decimal places in order to obtain a finite set of possible values. For instance, if I were to round values to zero decimal places, the number of unique sequen

Re: [R] Simulating mid-points from a defined range

2025-06-03 Thread Brian Smith
Hi JRG, It is not a homwork, but a practical problem. I was unsure about the theritical framework to generate such sequence. I introduced the condition that accuracy up to second decimal number, so that we would get a finite number of possible values. Otherwise I thought there could be infinite p

Re: [R] Simulating mid-points from a defined range

2025-05-31 Thread JRG via R-help
On Saturday, May 31st, 2025 at 7:44 PM, Bert Gunter wrote: > JRG: > > I don't think your specification is correct -- perhaps just a thinko. I think > a 10-tuple of "reals" (scare quotes because of computer precision) with your > specifications is what is wanted. > > Bert > > "An educated perso

Re: [R] Simulating mid-points from a defined range

2025-05-31 Thread Bert Gunter
JRG: I don't think your specification is correct -- perhaps just a thinko. I think a 10-tuple of "reals" (scare quotes because of computer precision) with your specifications is what is wanted. Bert "An educated person is one who can entertain new ideas, entertain others, and entertain herself."

Re: [R] Simulating mid-points from a defined range

2025-05-31 Thread JRG via R-help
I'll second Bert's comments, also assuming this is not homework. In addition: Your use of "mid-point" is not a standard one (in my world), nor perhaps is that of "simulate". Let me attempt to re-state your problem: You wish to choose 10-tuples of integers 0 <= k <= 100 satisfying 1) 0 <= k_i

Re: [R] Simulating mid-points from a defined range

2025-05-31 Thread Bert Gunter
If this is a real problem and not homework, can you tell us the context? It is not at all clear (to me) what you mean by "simulate", i.e. what your target distribution is, which may depend on/be defined by the context. Bert "An educated person is one who can entertain new ideas, entertain others,

Re: [R] Simulating mid-points from a defined range

2025-05-31 Thread Jeff Newmiller via R-help
Your description is not clear at the point where you "project it to the original space." Anyway, this sounds like homework, as the solution to this particular example is trivial when considered from the right point of view. On May 31, 2025 12:06:49 PM PDT, Sergei Ko wrote: >Hi! >Just an idea.

Re: [R] Simulating mid-points from a defined range

2025-05-31 Thread Sergei Ko
Hi! Just an idea. You randomly select the first point. Cut +/- 5 from the original space [0;100]. Select second point. Project it to the original space. Cut again. Repeat. Simplified method without cutting: every time mark +/- 5 as a bad space and select point again if it is in forbidden area. Hope

[R] Simulating mid-points from a defined range

2025-05-31 Thread Brian Smith
Hi, Let say I have a range [0, 100] Now I need to simulate 1000 10 mid-points within the range with accuracy upto second decimal number. Let say, one simulated set is X1, X2, ..., X10 Ofcourrse X1 < X2 < ... https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https:/