2. (a) Write a function, called myListFn, which takes a single argument n and implements the following algorithm: 1. Simulate n independent numbers, denoted x = (x1, r2, ..., xn), from the N(0, 1) distribution. 2. Calculate the mean X = =1"j 3. If x > 0, then simulate n independent numbers, denoted y = (yı, y2, ..., Yn), from the exponential density with mean X. If x < 0, then simulate n independent numbers, denoted z = (21, 22, ..., zn), from the exponential density with mean -X. Set y = (yı, Y2, ... Yn) = -z. 4. Calculate k which is the number of j with y;| > ]xj/. 5. Return the list of x, y and k with names xVec, yVec and count respectively. %3D n. (b) Execute the following lines and check the format of the answers: lapply( rep(10,4), myListFn ) sapply( rep(10,4), myListFn ) Note that sapply is effectively lapply followed by simplify2array. If myListFn has no arguments, then similar results can be obtained with replicate(4, myListFn()) and replicate (4, myListFn(), simplify=F). Now for a simulation study. Use lapply to call the function myListFn with n = 10 for 1,000 times. So the output consists of 10,000 values for a denoted {rij: i = 1, 2,..., 1,000;j = 1, 2, ..., 10}; 10,000 values for y denoted {yij: i = 1,2, ..., 1,000; j = 1,2, ..., 10}; and 1,000 values for n denoted n1, n2, ..., n1000- Denote the output by myList. This output is used in the remaining parts of this question. (c) Extract all the vectors with the name yVec. The result should be a list of 1000 vectors. (d) Extract all the vectors with the name yVec. The result should be a 10 x 1000 matrix with one column for each of the vectors yVec. (e) Create a list which is identical to myList but all the components called count have been removed. (f) Pick out those lists in myList which are such that count is greater than 2.
2. (a) Write a function, called myListFn, which takes a single argument n and implements the following algorithm: 1. Simulate n independent numbers, denoted x = (x1, r2, ..., xn), from the N(0, 1) distribution. 2. Calculate the mean X = =1"j 3. If x > 0, then simulate n independent numbers, denoted y = (yı, y2, ..., Yn), from the exponential density with mean X. If x < 0, then simulate n independent numbers, denoted z = (21, 22, ..., zn), from the exponential density with mean -X. Set y = (yı, Y2, ... Yn) = -z. 4. Calculate k which is the number of j with y;| > ]xj/. 5. Return the list of x, y and k with names xVec, yVec and count respectively. %3D n. (b) Execute the following lines and check the format of the answers: lapply( rep(10,4), myListFn ) sapply( rep(10,4), myListFn ) Note that sapply is effectively lapply followed by simplify2array. If myListFn has no arguments, then similar results can be obtained with replicate(4, myListFn()) and replicate (4, myListFn(), simplify=F). Now for a simulation study. Use lapply to call the function myListFn with n = 10 for 1,000 times. So the output consists of 10,000 values for a denoted {rij: i = 1, 2,..., 1,000;j = 1, 2, ..., 10}; 10,000 values for y denoted {yij: i = 1,2, ..., 1,000; j = 1,2, ..., 10}; and 1,000 values for n denoted n1, n2, ..., n1000- Denote the output by myList. This output is used in the remaining parts of this question. (c) Extract all the vectors with the name yVec. The result should be a list of 1000 vectors. (d) Extract all the vectors with the name yVec. The result should be a 10 x 1000 matrix with one column for each of the vectors yVec. (e) Create a list which is identical to myList but all the components called count have been removed. (f) Pick out those lists in myList which are such that count is greater than 2.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY