Starting from:

$30.99

STAT823- Homework 13 Solved

Directions
Using R Markdown in R Studio, complete the following questions. Launch RStudio and open a new RMarkdown file or use the class RMarkdown template provided and save it on your working directory as a .Rmd file. At the end of the activity, save your pdf generated from RMarkdown+Knitr and submit your homework on the Blackboard.

If you have questions, please post them on the lesson’s Discussion Board.

All questions are mandatory. R code and output must be clearly shown.

Homework submitted after the due date will attract a penalty of 10 points per day after the due date.

 

1.    Write an R function for computing the value of

f(x) = e−x2



 
 
 

and test it for a vector x = c(0,1,100).

2.    Write an R function to compute the sample excess kurtosis given by

1 Pni=1(xi − x¯)4

 g2 = 1nPn (xi − x¯)22 − 3

i=1 n

for a given vector x = (x1,··· ,xn), where x¯ is the average of the elements of x. Test the function for a vector x = 1:10.

3.    Suppose Jane wishes to take out a mortgage on a house. She wants to know what her periodic payments will be. If P is the initial amount mortgaged, r is the effective interest rate, and n is the length of the mortgage, then the periodic payment R is given by

Pr

R =  

1 − (1 + r)−n

(a)      Construct a function which employs this formular

(b)     Calculate Jane’s monthly payments, if the initial amount is $100,000, the interest rate is 1% and the number of interest conversions periods is 300.

4.    Suppose payments of P dollars are deposited annually into a bank account which earns constant interest r per year. What is the accumulated value of the account at the end

 

Page -1- of 2

Lesson 13: Homework                                                             STAT/BIOS 823: Writing R functions

 

of n years, supposing deposits are made at the end of each year? The total amount at the end of n years is given by the expression (1 + r)n − 1

n−1

                                            Amount = P(1 + r)               + ··· + P(1 + r) + P = P  

r

(a) Write an R function to compute the accumulated amounts after n = 10 years, with periodic payments P = $400 with a vector of interest rates r ranging from

0.01 to 0.2 by increments of 0.01.

(b)     Produce a line plot of the amounts (y-axis) against the interest rates (x-axis)

(c)      Optional question: Write a single function to perfom both parts (a) and (b) above.

 

More products