# Sampling small dataset from large dataset with reference to a given variable

Here is a statistics question which I have been thinking about while working with some of my data. I have a large dataset named "bigbird" (say about a billion rows) and I want to randomly sample a smaller dataset named "smallbird" from it using R. Now, I can easily do this with the following code:

smallbird<-bigbird[sample(1:nrow(bigbird),1000000,replace=FALSE),]


This is great and my theoretical model works to a certain degree. However, I am trying to finetune my model and I realize that I may have hit a theoretical concern as far as the random sampling is concerned. First, imagine that some of the variables inside bigbird are of similar form as follows:

user,observation_no,year
A, 5,1998
B,7,2003
A,6,1998
D,1,2010


Essentially, I have users, a observation number (which references a whole different set of variables) and the year in which they made a certain observation. I have 2 issues that need clarifying as follows:

1. From looking at the overall dataset, it is evident that as my time period progresses (1998-2012), I have more observations and more new users in every year in an exponential fashion. That is, in 2012, there are many, many more new users in the dataset than in year 1998.

2. Similarly, as my time period progresses, it appears that many, many more observations are being made by users in a given year than in previous years. That is, in 2012, user A may have made 50 different observations as opposed to only 1 observation in year 1998.

I was looking for opinions, discussions and solutions to these 2 issues because I think (and please correct me if I am wrong), that simple random sampling will not take care of these 2 issues. Thanks !

• So why do you think that SRS is not the right approach here? I don't see anything wrong with sampling from your pool of records. If, however, you want this to work in any better way for the population of interest (birds in 1998 vs. birds in 2013), then you could consider something different depending on what you want to achieve. Different sampling plans such as unequally allocated stratified designs arise when you minimize the variance of some analytic target, such as a mean, a proportion, or a total. Without such goal, it is difficult to say what a good design could be. – StasK Mar 20 '13 at 18:34
• Note also that I personally would expect strong observer effect, some learning by doing (so that users that have been out there since 1998 are providing better quality data in 2012 than the users who just joined in 2010), with implications for measurement error variance, and probably some effects from year to year due to the natural variability of the underlying ntural processes (e.g., hotter than average summers -- don't forget about the climate change, too). – StasK Mar 20 '13 at 18:35
• It is not clear what is the purpose of sampling in your question. – djhurio Mar 20 '13 at 19:09
• @StasK Thanks for the comments.I understand the point you are trying to make. – Shion Mar 20 '13 at 19:24

Assuming you are looking for say a uniform sized sample from each year couldn't you filter on $year = 1998$ and so on and then use $sample$ on those subsets?
Alternatively, if you presort on year you could use a sampling function that is a reverse exponential? i.e. Sample exponentially more often initially in the $bigbird$ set? That should balance things out?
If you also want to balance out over what $observation_number$ you are sampling on, now that's another matter. More complexity.