3

I am struggling to create a stratified sample of size 100 using stratified random sampling with 3078 observations. The conditions the stratified random sampling have to meet are : FARMS92<100, between 100 and 300, between 300 and 600, and FARMS92>600 as strata, and by using proportional allocation.

I do not understand how to proceed when i follow the stratified function : https://gist.github.com/mrdwab/6424112

Here is my dataset:

        COUNTY   STATE  ACRES92 ACRES87 FARMS92
    1   ALEUTIAN  AK    683533  726596  764514
    2   ANCHORAGE AK    47146   59297   256709
    3   FAIRBANKS AK    141338  154913  204568
    4   JUNEAU    AK    210     214     127
    5   KENAI     AK    50810   85712   98035
    6   AUTAUGA   AL    107259  116050  145044
    7   BALDWIN   AL    167832  192082  223502
    8   BARBOUR   AL    177189  207906  222066
    9   BIBB      AL    48022   50818   49630
    10  BLOUNT    AL    137426  140107  163638
    11  BULLOCK   AL    144799  156332  185304
    12  BUTLER    AL    96427   99997   124491
    13  CALHOUN   AL    73841   90474   93248
    14  CHAMBERS  AL    109555  102153  121101
    15  CHEROKEE  AL    121504  119956  143656 

Could you please explain me the steps on how to proceed?

1 Answers1

6

You could first separate into bins e.g. <100, between 100 and 300, etc using the cut function.

data$cut <- cut(data$FARMS92, breaks = c(0,100,300,600, 1E7), labels = c("A","B","C", "D"), right = TRUE)

Then use the stratify function (https://gist.github.com/mrdwab/6424112).

stratified(data, "cut", size = c(2,2,2,2))

For this particular example I used size = c(2,2,2,2) that will return 2 from each bin. Since you want a sample size = 100 then adjust the size accordingly. For instance, for proportional allocation you could use for your original dataset something like: size = round(100 * prop.table(table(data$cut)), 0).

Output:

     COUNTY STATE ACRES92 ACRES87 FARMS92 cut
7   BALDWIN    AL  167832  192082      22   A
6   AUTAUGA    AL  107259  116050      14   A
4    JUNEAU    AK     210     214     127   B
12   BUTLER    AL   96427   99997     124   B
11  BULLOCK    AL  144799  156332     385   C
15 CHEROKEE    AL  121504  119956     436   C
9      BIBB    AL   48022   50818   49630   D
8   BARBOUR    AL  177189  207906  222066   D

I modified your dataset to produce a better working example. Data:

data <- read.table(text= "COUNTY   STATE  ACRES92 ACRES87 FARMS92
1   ALEUTIAN  AK    683533  726596  76
2   ANCHORAGE AK    47146   59297   2
3   FAIRBANKS AK    141338  154913  204
4   JUNEAU    AK    210     214     127
5   KENAI     AK    50810   85712   480
6   AUTAUGA   AL    107259  116050  14
7   BALDWIN   AL    167832  192082  22
8   BARBOUR   AL    177189  207906  222066
9   BIBB      AL    48022   50818   49630
10  BLOUNT    AL    137426  140107  163638
11  BULLOCK   AL    144799  156332  385
12  BUTLER    AL    96427   99997   124
13  CALHOUN   AL    73841   90474   93248
14  CHAMBERS  AL    109555  102153  121
15  CHEROKEE  AL    121504  119956  436 ", stringsAsFactors=FALSE, header = TRUE)   
Edgar Santos
  • 3,426
  • 2
  • 17
  • 29
  • The solution to cut the dataset into several bins works perfectly. I did not manage to create a stratified function which would make the following code to work `stratified(data, group=cut, size = round(100 * prop.table(table(data$cut)), 0)) ` Could you please explain me? – Lorenna Van Munnecom May 03 '17 at 07:30
  • Using stratified(data, "cut", size = c(25,25,25,25)) will select randomly 25 rows from every group (A,B,C,D) being in total 100. Because you want proportional allocation using round(100 * prop.table(table(data$cut)), 0) will determine how many per group will be selected e.g. (35, 25, 25, 15) . If round(100 * prop.table(table(data$cut)), 0) works the stratified function should work . – Edgar Santos May 03 '17 at 21:27
  • 2
    Found a way to draw a stratified sample thanks to your advice : `sample_sizes <- as.numeric(round(100 * prop.table(table(data$cut)), 0)) data_new <- c() for (i in 1:4) { data_new <- c(data_new, sample(data[which(data$cut == i),]$ACRES92, sample_sizes[i])) }` – Lorenna Van Munnecom May 06 '17 at 19:58