Entry:

Random Division of a Population Into Two Groups

Posted by Tom on the 11th of July, 2009, at 3:03 pm.

An idea I head while at the YMCA, listening to a lecture on the statistics of psychology:

<?php
$this->db->order_by(rand());
$query = $this->db->get('table');
foreach $query as $row
	$count_total = $this->db->count('table');
	$this->db->where($group, 'group_1');
	$count_1 = $this->db->count('table');
	if ( $count_1 < ( $count_total / 2 ) )
	{
		$insert_data['group'] = 'group_1';
		$this->db->where($id, $this->row->id);
		$this->db->insert($insert_data, 'table');
	}
	else
	{
		$insert_data['group'] = 'group_2';
		$this->db->where($id, $this->row->id);
		$this->db->insert($input_data, 'table');
	}
endforeach
?>

Three possible problems:

  1. Doing only one pass like this will not necessarily be enough.
  2. What about populations with a count() that's not even? Or that is even?
  3. I'm not sure about my order_by( rand() ) and insert( $input_data, 'table' ) lines.
However, it's just a little idea, and, if I were to try it out (which I should, to maximize its practice value), I would iron out those wrinkles.


Login with Facebook

Tom's Picasa Web Albums

Bookmark and Share