STAT2005 Programming Languages for Statistics Take Home Test solution

$24.99

Original Work ?

Download Details:

  • Name: Take-Home-Test-a54rij.zip
  • Type: zip
  • Size: 190.85 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (5 votes)

Question 1 (14 marks)
The use of det() function is prohibited in this question.
Let 𝐴 be a n‐by‐n matrix and |𝐴| be its determinant, |𝐴| could be computed using the
following algorithm.
 
11 12 1
21 22 2 1
11 11 12 12 13 13 14 14 1 1
1 2
1
n
n n
n n
n n nn
aa a
aa a
A aA aA aA aA aA
aa a

ο€½ ο€½ ο€­  ο€­  

    

,
where 𝐴௜௝ is a (n‐1)‐by‐(n‐1) matrix that results from deleting row 𝑖 and column 𝑗 of 𝐴. Write
a function named my_det() which takes a square matrix and returns the value of its
determinant. Your function should check if the input matrix is a square matrix and return the
error message β€œInput matrix is not a square matrix.” when necessary.
Question 2 (14 marks)
Secant method is an alternative root‐finding algorithm in numerical analysis to solve f(x) = 0.
Given two initial values x0 and x1, the successive terms are defined recursively as follows.
   
1 2
1 1
1 2
, 2,3, . n n
nn n
n n
x x x x fx n fx fx
ο€­ ο€­
ο€­ ο€­
ο€­ ο€­
ο€­ ο€½ο€­ ο€½ ο€­ 
Implement the Secant method as a R function in the following form
secant <- function(f,x0,x1,n,err) {…} where f is a function to evaluate f(x), x0 and x1 are the values of x0 and x1 respectively, and err is the error tolerance in absolute value of f(x). Try to solve 0.5 1.0 1.5 2.0 3 3 3 103 98.39 yyy y eee e ο€­ο‚΄ ο€­ο‚΄ ο€­ο‚΄ ο€­ο‚΄  ο€½ using your function and compare the number of iterations of the Secant method with the bisection method as discussed in the lecture notes. 2 Use SAS programming language to answer Question 3‐4 and save your answers in a script file named β€œ[Your_Student_ID].sas”, where [Your_Student_ID] is your 10‐ digit student ID. Question 3 (36 marks) We have a data set of four variables on the murder rates (per 100,000 inhabitants) for cities from South, North, and West in USA in 1980 as follows: city state coast rate ---------------------------------------- Denver CO West 9 Los Angeles CA West 23 San Diego CA West 10 Atlanta GA South 14 Dallas TX South 18 Washington DC South 11 Chicago IL North 14 Cleveland OH North 16 Detroit MI North 16 Madison WI North 2 Write SAS programs to read the murder rates data in (a) - (c) as in-stream data. Store the data in a temporary file, called Q3. You can copy and paste the data lines from Q3.txt. β€˜#’ in the data lines are not part of the data. The order of the variables in the file must be CITY, STATE, COAST, and RATE. (a) (12 marks) Denver CO West 9 #### Los Angeles CA West 23 San Diego CA West 10 Atlanta GA South 14 Dallas TX South 18 Washington DC South 11 Chicago IL North 14 Cleveland OH North 16 Detroit MI North 16 Madison WI North 2 3 (b) (12 marks) Denver CO West 9 Los Angeles CA West 23 San Diego CA West 10 Atlanta GA South 14 Dallas TX South 18 Washington DC South 11 Chicago IL North 14 Cleveland OH North 16 Detroit MI North 16 Madison WI North 2 (c) (12 marks) Denver CO ## West 9 #### Los Angeles CA # West 23 San Diego CA ### West 10 Atlanta GA # South 14 Dallas TX # South 18 Washington DC # South 11 Chicago IL ## North 14 Cleveland OH # North 16 Detroit MI # North 16 Madison WI ### North 2 Hint: For part (a), you can use the following template. data Q3; * Your input and/or length statements here; cards; Denver CO West 9 #### Los Angeles CA West 23 San Diego CA West 10 Atlanta GA South 14 Dallas TX South 18 Washington DC South 11 Chicago IL North 14 Cleveland OH North 16 Detroit MI North 16 Madison WI North 2 run; Part (b) and (c) are similar by replacing the in‐stream data between the cards; and run; statements. 4 Question 4 (36 marks) Write a SAS program to read the following information about Tom's Tuesday appointments as in-stream data. Time With Place Subject Length_Meeting Confirmed? ------------------------------------------------------------------------------ 11:00 Li Lan Room 30 Personnel review 45 minutes Yes 13:00 Leung Mei Fai Leung's office Marketing 30 minutes No 15:00 Mak David Lab Test results 20 minutes Yes The SAS data set should be a permanent one locating in D:\ with filename Q4. The data set should contain seven variables: TIME, LAST_NAME, FULL_NAME, PLACE, SUBJECT, LENGTH_MEETING, CONFIRM. TIME and LENGTH_MEETING are numeric and all other variables are character. The data are listed below in (a - (c). You can copy and paste the data lines from Q4.txt. β€˜#’ in the data lines are not part of the data. (a) (12 marks) 11:00 Li Lan Room 30 Personnel review 45 minutes Yes 13:00 Leung Mei Fai Leung's office Marketing 30 minutes No 15:00 Mak David Lab Test results 20 minutes Yes (b) (12 marks) 11:00 Li Lan Room 30 Personnel review 45 Yes# 13:00 Leung Mei Fai Leung's office Marketing 30 No 15:00 Mak David Lab Test results 20 Yes (c) (12 marks) 11:00 Li Lan Room 30 Personnel review 45 minsYes 13:00Leung Mei Fai Leung's office Marketing 30 mins No 15:00 Mak David Lab Test results 20 mins Yes End of Questions