I am trying to create a list of all possible permuations of 14 things with 7
things chosen at a time. Example: Variables: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 Output: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 <-- case 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 <-- case 2 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 <-- case 3 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ... 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 What I want to do is treat case 2 and case 3 above as the same case. That is, I don't want more than 1 instance of all 1's and one 2 in the output. I have looked through the archive and adjusted what I have found. Note> I know the line: loop throw = 1 to 2000000. does not cover the permutations. At this point I am just trying to refine to get the output I want. * this program creates all possible permutations of 3 "dice" variables . new file. set seed = 20081031. input program. loop i = 1 to 14. loop j = 1 to 14. loop k = 1 to 14. loop l = 1 to 14. loop m = 1 to 14. loop n = 1 to 14. loop o = 1 to 14. leave i j k, l, m, n, o. end case. end loop. end loop. end loop. end loop. end loop. end loop. end loop. end file. end input program. formats i,j,k,l,m,n,o (f1). list. * this program "throws three dice" . set seed = 5743269. input program. vector die (7,f1). loop throw = 1 to 2000000. loop #k = 1 to 7. compute die(#k) = rnd(rv.uniform(1,14)). end loop. end case. end loop. end file. end input program. formats throw (f3) die1 to die3 (f1). list. Again, I adjusted code from the archive that I found in an attempt to reach my desired result. The best analogy I can think of is using 14 decks of cards to play 7 card stud. I can have 7 aces in my hand. But, if I have 6 aces and 1 king it doesn't matter there the 1 king is in the hand. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
it seems you want combinations not permutations.
try something like this loop i = 1 to 14. loop j = 1 to i. loop k = 1 to j. check the count of cases against factorial(14) / factorial(7). ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
Right - and complete if you want 3 draws, like the dice example. (Confusing Original post. Like, the first example says "7 draws" but shows 14.)
To do 7 draws with 14 choices, there will be 7 loops, like the
(i, j, k, l, m, n, o) example, but with maximums of (j, k, ..., o)
instead of "14".
-- Rich Ulrich
From: SPSSX(r) Discussion <[hidden email]> on behalf of Art Kendall <[hidden email]>
Sent: Monday, July 30, 2018 1:10:19 PM To: [hidden email] Subject: Re: permuation list with repetition and order doesn't matter it seems you want combinations not permutations.
try something like this loop i = 1 to 14. loop j = 1 to i. loop k = 1 to j. check the count of cases against factorial(14) / factorial(7). ----- Art Kendall Social Research Consultants -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
In reply to this post by Charles
Below is a python program to do this. Takes about a minute and produces
77,520 rows. *************************************************************************. DATASET DECLARE Combo. BEGIN PROGRAM Python. import itertools, spss #Function to import data into SPSS #See https://andrewpwheeler.wordpress.com/2014/09/19/turning-data-from-python-into-spss-data/ def SPSSData(data,vars,types,name=None): VarDict = zip(vars,types) #combining variables and #formats into tuples spss.StartDataStep() datasetObj = spss.Dataset(name=name) #if you give a name, #needs to be declared #appending variables to dataset for i in VarDict: datasetObj.varlist.append(i[0],i[1]) #now the data for j in data: datasetObj.cases.append(list(j)) spss.EndDataStep() #Now creating the combinations you want YourSet = range(1,14+1) YourLen = 7 x = itertools.combinations_with_replacement(YourSet,YourLen) v = ['X' + str(i+1) for i in range(YourLen)] t = [0]*YourLen SPSSData(data=x,vars=v,types=t,name='Combo') END PROGRAM. DATASET ACTIVATE Combo. *************************************************************************. ----- Andy W [hidden email] http://andrewpwheeler.wordpress.com/ -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
Here is a pure SPSS implementation I had for a different project awhile ago
as well. Don't look too closely at the macro, you might go mad. ******************************************************************. DATASET CLOSE ALL. OUTPUT CLOSE ALL. *This macro takes a number of crimes, n, in a given number of bins. *And generates all of the possible permutations. DEFINE !CombBins (N = !TOKENS(1) /Bins = !TOKENS(1) ) INPUT PROGRAM. VECTOR Bin(!Bins,!CONCAT("F",!LENGTH(!N),".0")). !LET !Min = !CONCAT("#",1) !LET !DoR = !Min LOOP !Min = !N to 0 BY -1. !DO !L = 2 !TO !Bins !LET !Ind = !CONCAT("#",!L) LOOP !Ind = (!N - SUM(!Min)) to 0 BY -1. !LET !Min = !CONCAT(!Min,",",!Ind) !LET !DoR = !CONCAT(!DoR," ",!Ind) !DOEND DO REPEAT Bin = Bin1 to !CONCAT("Bin",!Bins) /#i = !DoR. COMPUTE Bin = #i. END REPEAT. COMPUTE #c = SUM(Bin1 to !CONCAT("Bin",!Bins)). END CASE. END LOOP IF #c = !N. !DO !L = 2 !TO !Bins END LOOP. !DOEND END FILE. END INPUT PROGRAM. EXECUTE. DATASET NAME !CONCAT("Comb",!Bins,"Bins",!N,"N") !ENDDEFINE. ****************************. *Example Use. !CombBins N = 7 Bins = 14. *Now creating dataset for individual cards in each row. VECTOR X(7,F1.0). COMPUTE #Ord = 0. DO REPEAT B = Bin1 TO Bin14 /#i = 1 TO 14. DO IF B > 0. LOOP #j = 1 TO B. COMPUTE #Ord = #Ord + 1. COMPUTE X(#Ord) = #i. END LOOP. END IF. END REPEAT. EXECUTE. SHOW N. ****************************. ******************************************************************. ----- Andy W [hidden email] http://andrewpwheeler.wordpress.com/ -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 |
In reply to this post by Charles
I can't understand the task. What are all those 1,1,1,... or
14,1,4,14,... is it "pemutations" that you duplicate an element?
30.07.2018 19:34, Charles пишет:
I am trying to create a list of all possible permuations of 14 things with 7 things chosen at a time. Example: Variables: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 Output: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 <-- case 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 <-- case 2 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 <-- case 3 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 ... 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 What I want to do is treat case 2 and case 3 above as the same case. That is, I don't want more than 1 instance of all 1's and one 2 in the output. I have looked through the archive and adjusted what I have found. Note> I know the line: loop throw = 1 to 2000000. does not cover the permutations. At this point I am just trying to refine to get the output I want. * this program creates all possible permutations of 3 "dice" variables . new file. set seed = 20081031. input program. loop i = 1 to 14. loop j = 1 to 14. loop k = 1 to 14. loop l = 1 to 14. loop m = 1 to 14. loop n = 1 to 14. loop o = 1 to 14. leave i j k, l, m, n, o. end case. end loop. end loop. end loop. end loop. end loop. end loop. end loop. end file. end input program. formats i,j,k,l,m,n,o (f1). list. * this program "throws three dice" . set seed = 5743269. input program. vector die (7,f1). loop throw = 1 to 2000000. loop #k = 1 to 7. compute die(#k) = rnd(rv.uniform(1,14)). end loop. end case. end loop. end file. end input program. formats throw (f3) die1 to die3 (f1). list. Again, I adjusted code from the archive that I found in an attempt to reach my desired result. The best analogy I can think of is using 14 decks of cards to play 7 card stud. I can have 7 aces in my hand. But, if I have 6 aces and 1 king it doesn't matter there the 1 king is in the hand. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== 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 ===================== 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 |
In reply to this post by Charles
--> The best analogy I can think of is using 14 decks of cards to
play 7 card
stud. I can have 7 aces in my hand. But, if I have 6 aces and 1 king it doesn't matter there [where?] the 1 king is in the hand. Can that be understood such that you have 14 sets of elements, and you want to get all combinations (not permutations) by 7 elements from different sets, no more than 1 element from each set. ? Is that what are're after? ===================== 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 |