Starting from:

$30.99

STAT823- Homework 4 Solved

Directions

The aim of this exercise is to make you get used to using R and learn how to write a dynamic report. Explore the basic functionalities of R and include enough documentation with annotated comments.

Use R-Markdown and knit your solution document to pdf. To do so, go to File, New File, then click on R Markdown. A template will open up. Save this with an .Rmd extension, e.g. hw4.Rmd. Use this as your template or any other more developed template to answer the questions.


Show all your work/code. Late submission will attract a penalty of 10 points per day after the due date.

If you have any questions, please post them on the lesson discussion board.

 

1. A total of 30 Masters students in a Statistics course were asked to state how long they take to finish their weekly homework.

The following is the reported time in hours:

2,3,1.5,3.5,4,3,1,3,2,3.5,4,3,2.5,2.5,2,2,1.5,2,2,3,3,

3,1,1,1,1.5,2,2.5,2.5,3

(a) Write your own R code (function) to calculate the sample mean without using the mean() R function then confirm

your answer using the mean() function

1 Xn

x¯ =    xi n i=1

(b) Write your own R code (function) to calculate the sample variance without using the sd() and var() R functions. You can use the mean() and sum() functions, then confirm your answer using the var() function

                                                                                                        1  n                             

2                                                    X 2          2
s =       xi − nx¯  n − 1 i=1

2. Caleb wishes to take P = $10,000 loan from a bank. The bank offers the loan at a monthly interest rate r = 3% for a period of n = 24 months. Calculate the monthly instalments m that Caleb will have to remit to the bank given that the principal is calculated as

1 − (1 + r)−n

                                                                            P = m    

r

(Hint: First, make m the subject of the formula. That is, re-write the expression to obtain m = (.) then solve for m)

r

m = P ∗ 

1 − (1 + r)−n

 

Proof: Not reqired

                                                          2                                  1 Xn                         2

S                      =           (xi − x¯)  n − 1 i=1

                                                                                                         1 Xn          2                             2 

=   (xi − 2xix¯ + ¯x ) n − 1 i=1

                                                                                                         1 Xn         2                Xn                     2

=   xi − 2x¯ xi + nx¯  n − 1 i=1 i=1

                 Notice that    ¯         =               1 Xn Xi ⇒ Xn Xi = nX¯

X n i=1                i=1

                                                                                                          1  n                                               

                                                                    ∴ S2 =         X x                                 

n − 1 i=1

                                                                                                          1 Xn                                              

=           x       n − 1 i=1



 =            n − 1 i=1

More products