08. Probabilistic sampling
Module items¶
R Script file code¶
-
[[Copy the code]] below ➜ Paste into [[RStudio console]] ➜ Hit Enter
-
source(url("https://raw.githubusercontent.com/ttezcann/ssric-reg/refs/heads/main/docs/assets/attachments/data/0-packages-data.R")); (function(f="08-sampling.R"){if(!file.exists(f)){download.file("https://raw.githubusercontent.com/ttezcann/ssric-reg/refs/heads/main/docs/assets/attachments/modules/08.-probabilistic-sampling/08-sampling.R",f,mode="wb");file.edit(f)}else{download.file("https://raw.githubusercontent.com/ttezcann/ssric-reg/refs/heads/main/docs/assets/attachments/modules/08.-probabilistic-sampling/08-sampling.R",gsub(".R","-original.R",f),mode="wb");file.edit(gsub(".R","-original.R",f))}})()- When this R script file opens in a new tab, [[Save R script file|save your previous R script file(s)]], and
- Close the previous tabs (R Script files), which you can find later in the [[Files tab]].
- When this R script file opens in a new tab, [[Save R script file|save your previous R script file(s)]], and
-
Assignment¶
- Sampling
- See: [[How to submit an assignment]]
Sample assignment¶
Suggested reading¶
Learning outcomes¶
- Learn how to choose and create dataset using
- Non-random sample
- Simple random sample
- Systematic random sample
- Evaluate a sampling method's representativeness by comparing the sample mean to the population mean against a threshold
- Identify advantages and disadvantages of different sampling methods
The mission¶
- We will generate four samples and choose one variable.
- Our variable is family income,
coninc.- If the mean family income difference between population (GSS data) and samples diverge a lot, if the mean difference is more than $3,000 (the threshold), we can say that sampling method does not represent the population.
- Our variable is family income,
-
[[Search]] the variable name,
conrinc, in Variables in GSS page.-
Variable name Variable label Variable type Question wording and response categories conincRespondents' family income Continuous What is your family income in dollars?
(Min: $281.5; Max, $139,024.4)- First, let's create a descriptive table of family income,
coninc.
- First, let's create a descriptive table of family income,
-
[[Descriptive table]] #code¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We put
coninchere ➜variable_here.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to generate the output shown below, which will appear in the [[viewer tab]] of RStudio.
- Now, [[find this working code in the R script file]], and
- Line 1: We put
-
[[Descriptive table]] #output¶
-
Basic descriptive statistics
-
variable variable label n NA.prc mean sd coninc Respondents' family income 3563 10.61 47738.65 41328.35
-
[[Descriptive table]] #interpretation¶
-
Descriptive table interpretation sample
The respondents' family income variable shows that the average family income of the respondents is $47,738, with standard deviation $41,328.
-
Descriptive table interpretation template
The [[variable label]] variable shows the average variable label of the respondents is mean, with standard deviation sd.
-
Interpretation explanation
- After the variable label, we add the word of "variable" in our interpretation:
- "The respondents' education in years variable shows that..."
- Depending on the variable, we need to tweak some parts of the interpretation.
- For example, "the average years of education is...", "the average weeks of working is..." etc.
- We use the mean (mean column) and standard deviation (sd column) in our interpretation.
- After the variable label, we add the word of "variable" in our interpretation:
The range¶
-
So then, if the different samples fall in 50,738 - 44,738 dollars range, we'll assume our sampling methods work.
-
flowchart LR A["$44,738"] --- B["$47,738"] --- C["$50,738"] style A fill:stroke:#333,stroke-width:1px style B fill:stroke:#333,stroke-width:5px style C fill:stroke:#333,stroke-width:1px
-
-
These are the sampling methods we'll use:
-
flowchart TD A("GSS data<br/>3,986 respondents") B("40% <br/>Non-random sampling<br/>1,594 respondents") C("30% <br/>Simple random sampling<br/>1,196 respondents") D("20% <br/>Systematic random sampling<br/>798 respondents") A --> B A --> C A --> D
-
[[Non-random sampling]]¶
GSS example 1: 40% non-random sampling¶
- We'll choose 40% of the GSS respondents, but not in a random way. Instead we'll choose the first 40% of them in the dataset in the order they appear, and create a new dataset for them.
- First, create a new dataset for the first 40% of the GSS respondents.
[[Data creation]] #code for 40% non-random sampling¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We will put
gssfirst40perhere ➜new_data_name_here.gssfirst40peris the name of the new dataset, which will appear undergssin Data Environment;headis the order of the selection for the first respondents (tailis for the last);0.40is 40%.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to create a new data,
gssfirst40per.
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to create a new data,
- Now, [[find this working code in the R script file]], and
- If the codes are correct, the [[viewer tab]] will provide confirmation:
- Line 1: We will put
-
[[Descriptive table]] #code for 40% non-random sampling¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We put
coninchere ➜variable_here. Note that we usegssfirst40perinstead ofgss.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to generate the output shown below, which will appear in the [[viewer tab]] of RStudio.
- Now, [[find this working code in the R script file]], and
- Line 1: We put
-
[[Descriptive table]] #output for 40% non-random sampling¶
-
Basic descriptive statistics
-
variable variable label n NA.prc mean sd coninc Respondents' family income 1415 11.23 53688.98 44151.37
-
[[Descriptive table]] #interpretation for 40% non-random sampling¶
-
Non-random sampling descriptive table interpretation sample
The overall respondents' family income mean among GSS respondents is $47,738, while the family income mean with a 40% non-random sample is $53,688.
In this case since the mean family incomes differ by more than $3,000, we can conclude that these mean family incomes are substantially different.
-
Is a non-random sample preferable method for obtaining generalizable results?
- It is not preferable; samples that are non-random cannot represent a whole population because all the individuals in the population do not receive equal chances of being selected.
- Substantially different results were obtained about the family income means because non-random samples are not capable of representing the population as a whole.
-
-
Non-random sampling descriptive table interpretation template
The overall [[variable label]] mean among GSS respondents is [mean], while the variable label mean with a name of the sampling method name is [mean].
In this case since the mean variable label differ by more than [threshold], we can conclude that these mean variable label are substantially different.
OR
In this case since the variable label do not differ by more than [threshold], we can conclude that these mean variable label are not substantially different.
[[Simple random sampling]]¶
GSS example 2: 30% simple random sampling¶
- We'll choose 30% of the GSS respondents in a random way.
- First, create a new dataset for the 30% of the GSS respondents that will be chosen randomly.
[[Data creation]] #code for 30% simple random sampling¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We will put
gssrandom30perhere ➜new_data_name_here.gssrandom30peris the name of the new dataset, which will appear undergssin Data Environment;0.30is 30%.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to create a new data,
gssrandom30per.
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to create a new data,
- Now, [[find this working code in the R script file]], and
- If the codes are correct, the [[viewer tab]] will provide confirmation:
- Line 1: We will put
-
[[Descriptive table]] #code for 30% simple random sampling¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We put
coninchere ➜variable_here. Note that we usegssrandom30perinstead ofgss.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to generate the output shown below, which will appear in the [[viewer tab]] of RStudio.
- Now, [[find this working code in the R script file]], and
- Line 1: We put
-
[[Descriptive table]] #output for 30% simple random sampling¶
-
Basic descriptive statistics
-
variable variable label n NA.prc mean sd coninc Respondents' family income 1067 10.79 46641.97 40957.59
-
[[Descriptive table]] #interpretation for 30% simple random sampling¶
-
The overall respondents' family income mean among GSS respondents is 47,738 dollars, and we found 46,641 dollars. This is close! However, when you run those codes, you found a different mean. Also...
-
Here's the issue
- If you run the data creation code and the descriptive table code again, you will find different results.
- It's because every single time the data creation code is run, RStudio chooses different 30% of the GSS respondents.
- There's an inconsistency issue.
- It's because every single time the data creation code is run, RStudio chooses different 30% of the GSS respondents.
- If you run the data creation code and the descriptive table code again, you will find different results.
-
30% simple random sampling descriptive table interpretation sample
The overall family income mean among GSS respondents is $47,738, while the family income mean with a 30% simple random sample is $46,641.
In this case since the mean family incomes differ by more than $3,000, we can conclude that these mean family incomes are substantially different. In this case since the mean family incomes do not differ by more than $3,000, we can conclude that these mean family incomes are not substantially different.
-
Is a 30% simple random sample preferable to a non-random sample?
- It is preferable; 30% simple random sampling is better than and superior to non-random sampling as there is a random selection. However, with each time the code is run, there is a different result.
- Even though this method is better than non-random sampling, there is still inconsistency, as a different 30% of the data is selected each time.
-
-
30% simple random sampling descriptive table interpretation template
The overall [[variable label]] mean among GSS respondents is [mean], while the variable label mean with a name of the sampling method is [mean].
In this case since the mean variable label differ by more than [threshold], we can conclude that these mean variable label are substantially different.
OR
In this case since the variable label do not differ by more than [threshold], we can conclude that these variable label are not substantially different.
-
[[Systematic random sampling]]¶
GSS example: 20% Systematic random sampling¶
- We'll choose 20% of the GSS respondents in a random way, with assigning the starting point and the choosing interval.
- First, create a new dataset for the 20% of the GSS respondents that will be chosen randomly and systematically.
[[Data creation]] #code for 20% Systematic random sampling¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We will put
gss20persystematichere ➜new_data_name_here.gss20persystematicis the name of the new dataset, which will appear undergssin Data Environment;4is the starting point, so the sample begins with the 4th respondent;5means every fifth respondent is selected after that. Because 1 out of every 5 cases is chosen, the sample includes about 20% of the dataset.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to create a new data,
gss20persystematic.
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to create a new data,
- Now, [[find this working code in the R script file]], and
- If the codes are correct, the [[viewer tab]] will provide confirmation:
- Line 1: We will put
-
[[Descriptive table]] #code for 20% Systematic random sampling¶
-
[[Model code]]
-
-
[[Working code]]
-
- Line 1: We put
coninchere ➜variable_here. Note that we usegss20persystematicinstead ofgss.- Now, [[find this working code in the R script file]], and
- [[Highlighting and running|Highlight and run]] the working code in this module's R script file to generate the output shown below, which will appear in the [[viewer tab]] of RStudio.
- Now, [[find this working code in the R script file]], and
- Line 1: We put
-
[[Descriptive table]] #output for 20% Systematic random sampling¶
-
Basic descriptive statistics
-
variable variable label n NA.prc mean sd coninc Respondents' family income 706 11.42 47838.77 41591.10
-
[[Descriptive table]] #interpretation for 20% Systematic random sampling¶
-
The overall respondents' family income mean among GSS respondents is 47,738 dollars, and we found 47,838 dollars. This is extremely close!
-
20% systematic random sampling descriptive table interpretation sample
The overall family income mean among GSS respondents is $47,738, while the family income mean with a 20% systematic random sample is $47.838.
In this case since the mean family incomes do not differ by more than $3,000, we can conclude that these mean family incomes are not substantially different.
-
Is a 20% systematic random sample preferable to a 30% simple random sample?
-
It is preferable; systematic random sampling method provides consistency, and even if there were fewer people used in this sampling, this is better than 30% simple random sampling.
-
Sampling is less about the size of the sample and more about the representativeness of the sample selected.
-
-
-
20% systematic random sampling descriptive table interpretation template
The overall [[variable label]] mean among GSS respondents is [mean], while the variable label mean with a name of the sampling method is [mean].
In this case since the mean variable label differ by more than [threshold], we can conclude that these mean variable label are substantially different.
OR
In this case since the variable label do not differ by more than [threshold], we can conclude that these variable label are not substantially different.
-


