Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

STATS 782 Statistical Computing

Assignment 3(2022.2)

1.  [14 marks]        Consider the following plot illustrating an optical illusion:

 

The plot is composed of squares that are all aligned at the same y coordinate, although our eyes makes us believe that the lines are not straight. Each row is shifted by 1/4 square relative to the adjacent rows, but the direction changes every two steps.

(a) Re-create the plot using R.

(b)  Solve (a) without any implicit or explicit loops.

[6 marks] [2 marks]

(c) Write a function creating the plot taking n as a parameter which determines how many rows of squares there will be. Run it for values of 9, 11 and 15.                          [3 marks]

(d) Enhance the function from (c) by adding an argument cols which is a vector of the two colours to be used to ll the boxes. Call it with f(n=11,  cols=c("red","yellow")) and show the resulting plot. Does the effect still work?                                               [3 marks]

2.  [36 marks]

National Institute of Water and Atmospheric Research  (NIWA, https://niwa.co.nz) is a Crown Research Institute publishing, among other things, climate-related datasets for Aotearoa New Zealand. For this assignment we will be looking at daily rainfall in Auckland.

The file rain-akl .csv contains all available daily rainfall data for Auckland Airport (station code 1962).  It consists of three columns:  Station (integer) designating the source weather

station, Date in YYYYMMDD:HHMM format (UTC) and Amount (numeric, in millimeters). Answer the following questions based on this dataset.

(a) Examine the dataset for any data quality issues, for example: Are there any gaps? What

is the covered date range? Are the values plausible?                                            [4 marks]

(b)  Compute the total yearly rainfall for all available years in the data and plot the resulting

time series. What can you learn by looking at the plot?                                      [6 marks]

(c) You want to visualise the distribution of the yearly rainfall amounts from the previous question.  Select an appropriate plot that will show the distribution of the values.  Make sure that all values you use are meaningfully comparable.  Add visually the values for years 2018-2021 to the plot and explain based on the plot how typical are those values each.      [6 marks]

(d)  Calculate monthly totals (i.e., amount of rain in each month of each year) and draw a box plot of the totals by month. Which month has the highest median rain amount and which the lowest?         [6 marks]

(e) In order to assess the amount of water available throughout the year, it is common to use

line plots that show the number of days since the beginning of the year on the x-axis and the cumulative total for the year on the y-axis.  Draw such plot for the data since 2018, draw each line with a different colour and label each line with the year it represents (do not draw the years by hand, you can use a loop for this).

Comment on the differences between the years that you can see in the plot. Describe whether/how you can see in the plot:

i. whether there are particualry rainy periods

ii. whether a year is particularly dry or wet.                                                       [6 marks]

(f) Re-create the following graphic as closely as possible.  The baseline (dashed blue line) is

computed as the median (over years) of the cumulative daily values (excluding 1962) and the error bounds (light-blue) are the corresponding 20% and 80% quantiles.      [8 marks]