You want to test the effect of two different feeds, A and B on the fur quality of rabbits.
You have access to 120 laboratory rabbits: 60 white rabbits and 60 brown rabbits. In the lab, all white rabbits have odd numbers between 1 and 120, while all brown rabbits have even numbers between 1 and 120.
Your first task will be to assign a feed treatment to each rabbit. Each rabbit is an individual and therefore will create variation in the data due to differences between individual rabbits. You will have assign rabbits to treatments (the feeds) randomly, to counteract this.
Note
In this context, randomly means that you do not allocate the first 30 white rabbits to the first feed treatment and the next 30 white rabbits for the second feed treatment. You also do not merely assign the first feed treatment to every second rabbit in a numeric order, and the second feed treatment to all the other rabbits in the sample. No, you do this completely random without bias. You will learn more about this concept later in your education when you are taught experimental design.
As the fur colour may also explain some variation in the data created later during the experiment, you will also need to make sure than an equal number of each colour rabbits are assigned each treatment; meaning the first feed treatment is assigned to exactly 30 white rabbits and 30 brown rabbits, and the same is the case for the second feed treatment.
NoteQuestion
In your groups, discuss what steps would you need to take to complete the achieve the random assignment of rabbits to test the two feeds?
At this stage, think about the general things you will need to do, not the specific R code you will use to complete the steps.
TipSolution
You will need the following steps:
Create a vector with all numbers of the white rabbits
Take a random sample of 30 rabbits from the vector of white rabbits, and assign this random sample to an object with a name indicating that this is the white rabbits on the first feed treatment
Create a new vector with the rabbits on the second feed treatment by excluding the random sample from the original vector of white rabbits
Repeat the above for the brown rabbits.
NoteExercise
Do the above steps that we just decided on together. The last step will be more obvious to you after you read Chapter 12 (in r4ds) on logical vectors.
CautionTip
Think about using the functions you have learned and used today including e.g., seq() and sample(), the concept of indexing/subsetting a vector and the boolean operators.
TipSolution - white rabbits
Remember: As we are working with random samples, we need to set a seed to make sure our samples are reproducible.
# Create a vector with all numbers of the white rabbitswhite <-seq(from =1, to =120, by =1)white <- white[white %%2==1]white
Notice that we have exactly 30 rabbits, and the numbers are between 1 and 120, but otherwise no specific pattern can be seen — it is indeed random.
# Create a new vector with the rabbits on the second feed treatment# By excluding the random sample from the original vector of white rabbitswhite_b <- white[!white %in% white_a]white_b