Learning Objectives
Following this assignment students should be able to:
- use joins to combine tables in SQL
- understand the basic rules of tidy data
- implement quality control for data entry in spreadsheets
Reading
Lecture Notes
Exercises
-- Basic Join --
Write a query that returns the
[click here for output]year
,month
, andday
for each individual captured as well as it’sgenus
andspecies
names. This can be accomplished by joining thespecies
table to thesurveys
table using thespecies_id
column in both tables. Save this query asspecies_captures_by_data
.-- Multi-table Join --
The
plots
table in the Portal database can be joined to thesurveys
table by joiningplot_id
toplot_id
and thespecies
table can be joined to thesurveys
table by joiningspecies_id
tospecies_id
.The Portal mammal data include data from a number of different experimental manipulations. You want to do a time-series analysis of the population dynamics of all of the species at the site, taking into account the different experimental manipulations. Write a query that returns the
[click here for output]year
,month
,day
,genus
andspecies
of every individual as well as theplot_id
andplot_type
of the plot they are captured on. Save this query asspecies_plot_data
.-- Filtered Join --
You are curious about what other kinds of animals get caught in the Sherman traps used to census the rodents. Write a query that returns a list of the
[click here for output]genus
,species
, andtaxa
(from thespecies
table) for non-rodent individuals that are caught on theControl
plots. Non-rodents are indicated in thetaxa
column of thespecies
table. You are only interested in which species are captured, so make this list unique (only one line for each species). Save this query asnon_rodents_on_controls
.-- Detailed Join --
We want to do an analysis comparing the size of individuals on the
[click here for output]Control
plots to theLong-term Krat Exclosures
. Write a query that returns theyear
,genus
,species
,weight
and theplot_type
for all cases where the plot type is eitherControl
orLong-term Krat Exclosure
. Be sure to choose only rodents and exclude individuals that have not been identified to species. Remove any records where theweight
is missing. Save this query assize_comparison_controls_vs_krat_exclosures
.-- Aggregated Join --
Write a query that displays the total number of rodent individuals sampled on each
[click here for output]plot_type
. Save this query asindividuals_per_plot_type
.-- Improving Messy Data --
A lot of real data isn’t very tidy, mostly because most scientists aren’t taught about how to structure their data in a way that is easy to analyze.
Download a messy version of some of the Portal Project data. Note that there are multiple tabs in this spreadsheet.
Think about what could be improved about this data. In a text file (to be turned in as part of the assignment):
1-5. Describe five things about this data that are not tidy and how you could fix each of those issues.
6. Could this data easily be imported into a database in its current form?
7. Do you think it’s a good idea to enter the data like this and clean it up later, or to have a good data structure for analysis by the time data is being entered? Why?
-- Data entry validation in Excel --
You’re starting a new study of small mammals at the NEON site at Ordway-Swisher. Create a spreadsheet in Excel for data entry. It should have four columns: Year, Site, Species, and Mass.
Set the following data validation criteria to prevent any obviously wrong data from getting entered:
- Year must be an integer between 2015 and 2025.
- Site should be one of the following
A1
,A2
,B1
,B2
. - Species should be one of the following
Dipodomys spectabilis
,Dipodomys ordii
,Dipodomys merriami
. - Mass should be a decimal greater than or equal to zero but less than or equal to 500 since mass is measured in grams in this study and nothing bigger than half a kilogram will possibly fit into your Sherman traps. Change the error message on this validation criteria to explain why data is invalid and what the valid values are.
Save this file as
yourname_ordway_mammal_data.xlsx
.