首页 > > 详细

讲解MEC r设计、r语言程序辅导留学生、辅导r语言程序

MEC 537 Fall 2018: Assignment 1
Siddhartha Chib
September 24, 2018
Instructions
1. This is an individual assignment. No collaboration with anyone is permitted.
2. Answer the questions in a R-Markodown file (use the inclass1.rmd file as template).
Submit your rmd file on canvas when you are done.
3. Due: 5 pm, September 30, 2018
Questions
1. [12 points] How would do the following tasks in R?
a. Generate a numeric sequence x1 that starts from -1.25 and goes to 1.25 in
increments of .01. Then show how you would find the length of x1, its class
and attributes.
b. Generate a random sequence x2 of 1000 draws from the standard normal
distribution with the seed for the sequence set to 25.
c. Create a character vector x3 consisting of the names of five of your favorite
consumer brands.
d. Creat a matrix X4 from x2 consisting of 200 rows and 5 columns.
e. Creat a data.frame. object called datdf in which the first column has the name
dts consisting of dates from 2001-01-01 by month, followed by four columns of
the data in X4 with column names var1, var2, var3, var4.
f. Create a list object myls containing the objects in questions a-e.
2. [8 points] Additional R questions.
a. How is the function attr() used to add meta-data to an R-object? Give
an example by adding some meta-data of your choosing to the object x3 in
question 1.
b. How would you extract the last ten rows of the matrix X4 in question 1?
c. How would you extract the first column of datdf by its column name?
d. How could you save datdf to disk, remove it from the global environment, and
then load it back into your session?
3. [10 points] Write a function named matmultiply that takes matrices X and Y and
returns the matrix product. In the function body, how would you include a check
that the inputs are matrices and conformable for matrix multiplication?
4. [20 points] Consider the following model (data generating process)
y = β0 +β1x+σε
1
where
ε∼N(0,1)
and (β0,β1,σ) are parameters. Suppose that you had a value of x given to you, and
you also had a matrix (call it) outm with m rows and 3 columns of possible values
of the parameters. How could you use Monte Carlo simulation to take outm and
x as inputs (and perhaps a third input which is the seed for the simulation) and
output a m times 1 matrix of possible values of y. Write a function to do this job.
2

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!