The Mauna Loa data provide an opportunity to gain experience applying basic exploratory data analysis.
Activities today
- Continue basics for computing in R
- Explore data on CO2 and climate
- A few more R fundaments from Jim
- Group discussion for problems in Intro to R
- Group analysis of Mauna Loa data, including questions posted to Sakai
For next class
Based on your first day with the Mauna Loa vignette, provide a short summary for the following:
- What time of year is CO2 highest/lowest and why?
- At the current rate of CO2 increase in the atmosphere, how many years of change in the mean is equal to the seasonal change in CO2.
- The Mauna Loa CO2 series is an example of passive surveillance data that became one of the important debates of modern times. List three ways that this data set bears on the litigation issues we discussed on big oil.
- The ice-core data tell us that CO2 has been fluctuating for a long time. How does that perspective inform the interpretation of contemporary increases? Specifically, does it bear on the question of responsibility for the societal cost of climate change?
Post your answers to Sakai.
Recall basics in R
The Mauna Loa data analysis can be completed by cutting and pasting code. The Intro to R explains and provides practice on using them.
These basic objects came up last time:
- storage modes
- arrays, indices
forloop- vectorization
- functions
list,data.framewhich,match,apply,tapply
Some common questions:
- What colors are available on R? Can you use hex numbers to create colors?
Yes, I like this site.
- What should you do if a package fails to load?
No single answer for this, but always consider the following: i) restart, ii) update Rstudio, iii) google the error message. Also, bring these issues to class.
- Why do we have to use
%>%?
This operator is a function that is explained, among other places, in the package magrittr. As with many things in R, there can be multiple routes to the same result.
- How do you save the progress you made in the console?
You can use the function save(), which saves everying to
a .Rdata file. However, better still is to save the code as
you write it in a .r file, so you can recreate it.
- Is there a more efficient way to input data than assigning it to a variable or vector one by one?
We can discuss loading multiple objects with
load(filename) along with other ways to read and write
objects.
CO2 at Mauna Loa
Here are a few thoughts as you work with R.
what type of an object is
mauna_loa_weekly?there is a problem with Halverson’s interpretation of the uncertainty in the trend. I illustrate with a simple experiment, let’s decrease the data to 10 observations.
mauna_loa_weekly <- read.table('ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_weekly_mlo.txt')- Explore the object created by
read.table
Where did this object come from?
Use the
function modeto determine the storage mode.Use the
function sapplyto determine the storage mode of each column.Use the
function colnamesto find the column names ofmauna_loa_weeklycreate a
vectorto extract columns 1, 2, 3, and 5extract these columns from
mauna_loa_weekly; use thedim functionto determine its size.the new names for these columns will be ‘year’, ‘month’, ‘day’, ‘co2ppm’. Use the
colnames functionto assign these names tomauna_loa_weekly
- Dates have functions to handle year, month, and day.
first, use
pasteto combine (as characters) theyear,month, anddaycolumns separated by the string'-'.use
asDatewithformat = '%Y-%m-%d'to generate adatecolumn inmauna_loa_weekly.use
whichto locate values ofco2ppm == -999.99and replace them withNA.use
lmto regress the variableco2ppmagainstdate. Interpret the fitted coefficients.
- Generate a plot of
co2ppmagainstdateusingplot; add labels for x and y axes.
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.174447e+02 1.532608e-01 2071.2711 0
## mauna_loa_weekly$date 4.991952e-03 1.310012e-05 381.0615 0
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.202189e+02 2.025843697 158.06695 2.870707e-15
## x 4.668642e-03 0.000258499 18.06058 9.067222e-08
What is the difference in these two fits, and how should it affect our uncertainty about rising CO2? How does this relate to the differences in regressions using monthly and annual data?
How does he use the
diff function?Why might sea-surface temperatures NOT look like atmospheric CO2 concentrations?
What are the wiggles in the composite ice-core record?