In this assignment, you will use R to analyze data for Pacific North America (PNA) index during the winter months of December, January and February (DJF) from 1951-2021. Specifically, you will examine whether there are differences in the PNA index distribution between El Niño and La Niña winters.
Follow the directions below to run the provided R code and generate the .html file you will need to turn in. You will also refer to the figures you create and calculations you perform in this markdown file to answer the questions for Assignment 2 on Canvas.
Before running any of the code below, remember to set your working directory! To run the code below, R needs to access some data in the file assignment2data.RData. Setting your working directory tells R where to look for this file.
First, make sure assignment2data.RData and this markdown file Assignment2.Rmd are both saved in the same folder on your computer (preferably your designated folder for this class).
Then, at the top of this window, go to the Session drop down menu, mouse over Set Working Directory and select To Source File Location.
To run the code in a given chunk, click the green arrow in the top right corner of that chunk. You can also run all the chunks at once by finding the Run drop down menu in the top right of this window (white box with green arrow), and selecting Run all
-A dataset containing PNA index data from all years from 1951-2021 called pna_all_wtr
-A dataset containing PNA index data from El Niño winters only called pna_el_wtr
-A dataset containing PNA index data from La Niña winters only called pna_la_wtr
# Read the data
load("assignment2data.RData")
# Plot PDF of winter only data from all years
dT<-0.5
hist(pna_all_wtr,seq(-2.5,2.5,dT),freq=FALSE,
main="1. PDF of DJF PNA Index, All Years",
xlab="PNA Index",density=20,ylim=c(0,0.6),col="black")
# Plot PDF for Niño winters only
hist(pna_el_wtr,seq(-2.5,2.5,dT),freq=FALSE,
main="2. PDF of DJF PNA Index, El Niño Years",
xlab="PNA Index",density=20,ylim=c(0,1),col="black")
# Plot PDF for Niña winters only
hist(pna_la_wtr,seq(-2.5,2.5,dT),freq=FALSE,
main="3. PDF of DJF PNA Index, La Niña Years",
xlab="PNA Index",density=20,ylim=c(0,0.6),col="black")
# Plot CDF for Niño winters only
plot(ecdf(pna_el_wtr),xlab="PNA Index",
ylab="Cumulative probability",
main="4. CDF of DJF PNA Index: El Nino Winters",
do.points=FALSE,verticals=TRUE,col="black")
#add grid to plot
grid(nx = NULL, ny = NULL, col = "black", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
# Plot CDF for Niña winters only
plot(ecdf(pna_la_wtr),xlab="PNA Index",
ylab="Cumulative probability",
main="5. CDF of DJF PNA Index: La Nina Winters",
do.points=FALSE,verticals=TRUE)
#add grid to plot
grid(nx = NULL, ny = NULL, col = "black", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
To calculate the mean for all winters: mean(pna_all_wtr)
To calculate the mean for El Niño winters: mean(pna_el_wtr)
To calculate the mean for La Niña winters: mean(pna_la_wtr)
When you run the code chunk, the answers will appear below the code chunk in the order you enter them.
# insert your calculations below:
mean(pna_all_wtr)
## [1] 0.1135681
mean(pna_el_wtr)
## [1] 0.6680263
mean(pna_la_wtr)
## [1] -0.4901471
Check that your name is set as an author of this document (at the very top after ‘author:’), so we can see who ran the code.
Then find the “File” dropdown menu on the top left corner of the screen. Hit File>Save to save the changes you made to this file.
Using the File dropdown menu again, select File>Knit Document to save the contents of this R markdown file as a .html. It will be saved in your course folder as Assignment2.html. You will submit this .html file on Canvas to show your work.