Using Gaussian copula to generate a 

synthetic population

Yijun Wei

NISS, USDA-NASS

Yijun.Wei@nass.usda.gov

Luca Sartore

NISS, USDA-NASS

Luca.Sartore@nass.usda.gov

Nell Sedransk

NISS

NSedransk@niss.org

1
Disclaimer

2

The Findings and Conclusions in This Preliminary 

Presentation Have Not Been Formally Disseminated by the 

U.S. Department of Agriculture and Should Not Be 

Construed to Represent Any Agency Determination or 

Policy
Outline

3

• Purpose of research

• Census of Agriculture

• Gaussian copula

• R package dplyr and ggplot2

• Comparing dplyr and ggplot2 with base R

• Generating synthetic population using dplyr and ggplot2

• Conclusion
Purpose of presentation

• Generating a complex synthetic population

• To protect confidential information provided by responders

• To maintain pairwise statistical relationships among variables

• To handle continuous variable and categorical variable 

simultaneously

• Introducing statistical R packages ggplot2, dplyr that are used for 

visualization, data processing respectively

4
Census of Agriculture

• Every five years, USDA's National Agricultural Statistics Service 

(NASS) conducts the Census of Agriculture

• The Census provides a detailed picture of U.S. farms, ranches and the 

people who operate them

• It is the only source of uniform, comprehensive agricultural data for 

every state and county in the United States

• NASS also obtains information on most commodities from 

administrative sources or surveys of non-farm populations (e.g. cotton 

ginning data)

5
Census of Agriculture data overview

• Generate a synthetic population based on a subset of the 

Census of Agriculture data

• The subset contains 25 predictors

• For example, principal operator’s race, principal operator’s sex, etc..., but they are 

relabeled as X1, ..., X25 

• There are continuous and categorical variables

• The total number of observations in the subset is 800,000

• No missing value

6


R packages introduction

• A Grammar of Data Manipulation (dplyr)

• R-package used for data processing

• Transform and summarize tabular data with rows and columns. 

• Contain a set of functions (or “verbs”) that perform common data 

manipulation operations

• Create Elegant Data Visualizations Using the Grammar of 

Graphics (ggplot2)

• R-package used for data visualization

• Consistent underlying grammar of graphics (a graphic version of dplyr)

• Plot specification at a high level of abstraction

• Very flexible and elegant

9
R packages introduction - dplyr

• Commonly used command:

• mutate() adds new variables that are functions of existing variables

• select() picks variables based on their names

• filter() picks cases based on their values

• summarise() reduces multiple values down to a single summary

• arrange() changes the ordering of the rows

• group_by() allows for group operations in the “split-apply-combine” 

concept

10
R packages Introduction – dplyr - Continue

• Base R:

• Create new dataset: 

• Select Variable:

• Filter variable:

• Sort by variable value:

11
R packages Introduction – dplyr - Continue

• dplyr

• This can be done with one function using dplyr:

12
R packages introduction – ggplot2

• Graphic version of dplyr (using ‘+’ to replace ‘%>%’)

• Building blocks of a graph include:

• data

• aesthetic mapping

• geometric object

• statistical transformations

• scales

• coordinate system

• position adjustments

• faceting

13
R packages introduction – ggplot2 - Continue

• base R

14
R packages Introduction – dplyr - Continue

• ggplot2

15
R packages Introduction – ggplot2 - Continue

• More advanced features

16

Step by step R function - Continue

18
Step by step R function - Continue

19
Step by step R function - Continue

20
Pairwise correlation comparison

21
Summary

• This study 

• Generating synthetic population by Gaussian copula

• Adopting two R packages dplyr and ggplot2 simplifed the tasks for this study

• dplyr and ggplot2 are two useful R packages 

• More convenient to manage

• Easy to read

• Decrease the workload

• My personal preference to use over base R

22
References 

Nelsen, R. B. (2007). An introduction to copulas. Springer Science & Business Media.

Wickham, H., Francois, R., Henry, L., & Müller, K. (2015). dplyr: A grammar of data 

manipulation. R package version 0.4, 3.

Wickham, H. (2016). ggplot2: elegant graphics for data analysis. Springer.

23
Any Questions?

Thank you!

24