cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
WetlandWoman
Level II

How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?

Hi,

I am attempting to assign a list of video clips to a list of reviewers. Both the reviewers and the video clips have unique IDs. For increased accuracy, I would like three different reviewers to view the same video clip. And each reviewer must review 6 different video clips. The list of reviewer IDs and Video Clip IDs are in separate JMP files. I am currently using JMP v.16.2.0, and I have attached a JMP table illustrating the assignment process for two video clips and 6 reviewers.

Thank you in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?

Here is a rough attempt at what you are asking for.  I think it will work.  I assume, others in the Community will have a better idea  It uses 2 sample data tables, and assigns the clips to review from them

Names Default To Here( 1 );

dtRev = New Table( "Reviewers",
	New Column( "Reviewer", character, values( {"400180174", "400197965", "400241556", "400244169", "400247301", "400258583"} ) )
);
dtClp = New Table( "Clips",
	New Column( "Clip",
		character,
		values(
			{"GI2C328162023S24", "SQBC107132043S11", "SQBC107132023S11", "GI2C318162023S24", 
			"GI2C308162023S24", "SQBC107133023S11","GI2C308162022S25", "SQBC107132022S12", 
			"SQBC107132022S13", "GI2C309162032S24", "GI2C308162022S27", "SQBC107132022S16"}
		)
	)
);

// Create a new reviewers data table with each reviewer having 6 entries
dtRev6 = dtRev << concatenate( dtRev, dtRev, dtRev,dtRev,dtRev );
// Randomize the order of reviewer
dtRev6 << New Column( "random", set each value( Random Uniform( 1, 1000000 ) ) );
dtRev6 << Sort( By( :random ), Replace Table, Order( Ascending ) );
dtRev6 << delete columns( random );
// Scan through data table making sure the same name does not appear within 3 of the previous 
// time it appeared
For( i = 6, i <= N Rows( dtRev6 ), i++,
	If( :Reviewer[i] == :Reviewer[i - 1] | Try( :Reviewer[i] == :Reviewer[i - 2], 0 ),
		For( k = i + 1, k <= N Rows( dtRev6 ), k++,
			If( :Reviewer[k] != :Reviewer[i] & :Reviewer[k] != :Reviewer[i - 1] & Try( :Reviewer[k] != :Reviewer[i - 1], 1 ),
				hold = :Reviewer[i];
				:Reviewer[i] = :Reviewer[k];
				:Reviewer[k] = hold;
				Break();
			)
		)
	)
);

// Assign clips
dtRev6 << New Column( "Clip", character );
For( i = 1, i <= nrows(dtClp), i++,
	If( (i-1) * 3 +1 <= N Rows( dtRev6 ),
		For( k = (i-1) * 3 +1, k <= (i-1) * 3 +3, k++,
			dtRev6:Clip[k] = dtClp:Clip[i];
		)
	)
);

// Sort the table so reviewer's clips are listed together
dtRev6 << Sort(
	By( :Reviewer ),
	Replace Table,
	Order( Ascending )
);
Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?

Here is a rough attempt at what you are asking for.  I think it will work.  I assume, others in the Community will have a better idea  It uses 2 sample data tables, and assigns the clips to review from them

Names Default To Here( 1 );

dtRev = New Table( "Reviewers",
	New Column( "Reviewer", character, values( {"400180174", "400197965", "400241556", "400244169", "400247301", "400258583"} ) )
);
dtClp = New Table( "Clips",
	New Column( "Clip",
		character,
		values(
			{"GI2C328162023S24", "SQBC107132043S11", "SQBC107132023S11", "GI2C318162023S24", 
			"GI2C308162023S24", "SQBC107133023S11","GI2C308162022S25", "SQBC107132022S12", 
			"SQBC107132022S13", "GI2C309162032S24", "GI2C308162022S27", "SQBC107132022S16"}
		)
	)
);

// Create a new reviewers data table with each reviewer having 6 entries
dtRev6 = dtRev << concatenate( dtRev, dtRev, dtRev,dtRev,dtRev );
// Randomize the order of reviewer
dtRev6 << New Column( "random", set each value( Random Uniform( 1, 1000000 ) ) );
dtRev6 << Sort( By( :random ), Replace Table, Order( Ascending ) );
dtRev6 << delete columns( random );
// Scan through data table making sure the same name does not appear within 3 of the previous 
// time it appeared
For( i = 6, i <= N Rows( dtRev6 ), i++,
	If( :Reviewer[i] == :Reviewer[i - 1] | Try( :Reviewer[i] == :Reviewer[i - 2], 0 ),
		For( k = i + 1, k <= N Rows( dtRev6 ), k++,
			If( :Reviewer[k] != :Reviewer[i] & :Reviewer[k] != :Reviewer[i - 1] & Try( :Reviewer[k] != :Reviewer[i - 1], 1 ),
				hold = :Reviewer[i];
				:Reviewer[i] = :Reviewer[k];
				:Reviewer[k] = hold;
				Break();
			)
		)
	)
);

// Assign clips
dtRev6 << New Column( "Clip", character );
For( i = 1, i <= nrows(dtClp), i++,
	If( (i-1) * 3 +1 <= N Rows( dtRev6 ),
		For( k = (i-1) * 3 +1, k <= (i-1) * 3 +3, k++,
			dtRev6:Clip[k] = dtClp:Clip[i];
		)
	)
);

// Sort the table so reviewer's clips are listed together
dtRev6 << Sort(
	By( :Reviewer ),
	Replace Table,
	Order( Ascending )
);
Jim
WetlandWoman
Level II

Re: How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?

Hi Jim, Thank you for this! It worked like a dream.

Cheers!

Re: How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?

I used a Custom Design. I defined a categorical factor Clip with 12 levels. I created a fixed blocking factor Reviewer with 6 runs per block. (You can assign the reviewer ID with the Value Labels column property.) The definitions look like this:

 

custom.PNG

 

I chose 36 runs to achieve all combinations with random assignment using D-optimality. I checked and the design is balanced, which ensures that every reviewer gets 6 clips and every clip gets 3 reviews.

 

dist.PNG

WetlandWoman
Level II

Re: How to randomly assign one value to three unique IDs, while having each ID assigned 6 unique values?

Hi Mark,

Thank you for this. I have never used Custom Design so I stuck with what I knew, but this could come in handy for the future