MAT013 Class Test 2019

Instructions:

Once you have finished the test:

  1. Call the file for the SAS code: STUDENTNUMBER-SAS-lastname (eg. 123456-SAS-Evans) and call the file for the R code: STUDENTNUMBER-R-lastname (eg. 123456-R-Evans).
  2. Email both files to Andrey Pepelyshev with ‘MAT013-STUDENTNUMBER-lastname’ as the subject.
  3. The email must be sent before leaving the computer lab.
  4. Show the sent email to the class test invigilator.

The class test contains 4 questions. Each question contains a few tasks.

Questions for the class test:

Question 1

Please, answer this question using R:

  1. Write the R code for generating a vector P that contains all prime numbers between 2 and 100. Please, find prime numbers from their definition and do not use build-in functions. Please, write the elements of P as comments in your R program.

    [5]

  2. Let x be a given real number. Write a function GetPQ which finds p and q such that the ratio p/q is the closest value to x, where p and q belong to the set P which is defined above.

    [10]

  3. Create a table with five rows and three columns with column names x, p and q.
    Elements of the first column are real values 1/pi,pi,exp(-1),exp(1),exp(2) rounded upto 5 digits.
    Fill the second and third columns by the corresponding values of p and q which should be found by the function GetPQ.
    Please, write the table as comments in your R program.

    [10]

Question 2

Please, answer this question using SAS:

  1. Let S be the set containing the odd numbers between 2 and 100.
    Create a table with five rows and three columns with column names x, p and q.
    Elements of the first column are real values 1/pi,pi,exp(-1),exp(1),exp(2).
    Fill the second and third columns by the values of p and q such that the ratio p/q is the closest value to x where p and q belongs to the set S.
    Please, write the table as comments in your SAS program.

    [20]

Question 3

Please, answer this question using both SAS and R:

Download the file globtemp.csv to your PC. This file contains several monthly time series of anomaly temperature for different parts of Earth. The first column is the year and the second column is the month of observations. Other columns correspond to some parts of Earth. The first row contains the column names.

  1. Import the dataset globtemp.csv.
    Add a new column time with real values as a combination of year and month. The new column time should contain equidistant values. Depict the time series of the column Earth versus time.

    [10 R + 10 SAS]

  2. Compute the correlation matrix between 6 columns: NHLand, NHOcean, SHLand, SHOcean, TrpcsLand, TrpcsOcean.
    Identify and write two most correlated columns among 6 columns.
    Depict the scatterplot of these two most correlated columns.
    Estimate the linear model between these two most correlated columns.

    [10 R + 10 SAS]

Question 4

Please, answer this question using R:

  1. For a time series \(x_1,...,x_n\), let us define the function \(P(\lambda)=T_c^2(\lambda)+T_s^2(\lambda)\), \(\lambda\in[0,\pi]\), where \(m\) is the mean of \((x_1,...,x_n)\). The function \(P(\lambda)\) is called a periodogram.

    Write a function GetPeriodogram for computing and depicting the periodogram and exporting the graph to the pdf-file with filename containing the name of time series.

    Apply the function GetPeriodogram to the 4 following time series Earth, NoPol, SoPol, USA48 from the file globtemp.csv. These time series are located in the columns Earth, NoPol, SoPol, USA48.

    [15]