|
Is it possible to generate uniform random numbers in a specific range in matrix mode? For example, if I want to create a vector (i=100, j=1) of random numbers between 3 and 10, there doesn't seem to be a solution. If n=100 and I use compute x=trunc(uniform(100,1)*n), I get numbers between 1 and 10. If I use x=trunc(uniform(100,1)*n+2), I get numbers between 3 and 12. So in one case I get the desired top of the range, and in the other I get the desired bottom of the range. Any assistance is appreciated. Thanks.
Brian
|
|
Below is an example of syntax for generating 10,000 throws of a pair of
dice. (each die is considered a random number from 1 to 6).
There is a client at the door so I don't have time to see how it works in matrix mode, but this may give you a start. *THROW 2 DICE. SET SEED=20090515. NEW FILE. INPUT PROGRAM . LOOP id=1 to 10000. COMPUTE die1=RND(RV.UNIFORM(.5,6.5)). COMPUTE die2=RND(RV.UNIFORM(.5,6.5)). END CASE. END LOOP. END FILE. END INPUT PROGRAM. FORMATS DIE1 DIE2 (F1). CROSSTAB TABLES= DIE1 BY DIE2 /CELLS=ALL. Art Kendall Social Research Consultants On 3/6/2010 8:51 AM, Dates, Brian wrote: ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants |
|
Hi Brian:
On 3/6/2010 8:51 AM, Dates, Brian wrote: > Is it possible to generate uniform random numbers in a specific range > in matrix mode? For example, if I want to create a vector (i=100, > j=1) of random numbers between 3 and 10, there doesn't seem to be a > solution. If n=100 and I use compute x=trunc(uniform(100,1)*n), I get > numbers between 1 and 10. If I use x=trunc(uniform(100,1)*n+2), I get > numbers between 3 and 12. So in one case I get the desired top of the > range, and in the other I get the desired bottom of the range. This gives the expected Min and Max values for X vector: MATRIX. COMPUTE X=3+TRUNC(8*UNIFORM(100,1)). COMPUTE MinX=MMIN(X). COMPUTE MaxX=MMAX(X). PRINT {MinX,MaxX} /FORMAT='F8' /TITLE='Min & Max values'. END MATRIX. HTH, Marta GG -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
| Free forum by Nabble | Edit this page |
