0, then simulate n independent numbers, denoted y (y1, y2,.. ., Yn), from the exponentialdensity with mean X.If x ]xj\.5. Return the list of x, y and k with names xVec, yVec and count...


2. (a) Write a function, called myListFn, which takes a single argument n and implements the following<br>algorithm:<br>1. Simulate n independent numbers, denoted x = (x1, x2,..., xn), from the N(0, 1) distribution.<br>2. Calculate the mean X = E- Ti<br>n.<br>3. If x > 0, then simulate n independent numbers, denoted y (y1, y2,.. ., Yn), from the exponential<br>density with mean X.<br>If x < 0, then simulate n independent numbers, denoted z = (21, 2, ..., zn), from the exponential<br>density with mean -x. Set y = (y1, Y2, ..., Yn) = -z.<br>4. Calculate k which is the number of j with yj| > ]xj\.<br>5. Return the list of x, y and k with names xVec, yVec and count respectively.<br>(b) Execute the following lines and check the format of the answers:<br>lapply( rep(10,4), myListFn )<br>sapply( rep(10,4), myListFn )<br>Note that sapply is effectively lapply followed by simplify2array.<br>If myListFn has no arguments, then similar results can be obtained with replicate (4, myListFn())<br>and replicate(4, myListFn(), simplify=F).<br>Now for a simulation study. Use lapply to call the function myListFn with n = 10 for 1,000 times. So the<br>output consists of<br>10,000 values for x denoted {rij: i = 1,2,..., 1,000; j = 1, 2, ..., 10};<br>10,000 values for y denoted {y;jii = 1, 2, ..., 1,000; j = 1, 2,..., 10};<br>and 1,000 values for n denoted n1, n2,... , n1000-<br>Denote the output by myList. This output is used in the remaining parts of this question.<br>(c) Extract all the vectors with the name yVec. The result should be a list of 1000 vectors.<br>(d) Extract all the vectors with the name yVec. The result should be a 10 x 1000 matrix with one column<br>for each of the vectors yVec.<br>(e) Create a list which is identical to myList but all the components called count have been removed.<br>(f) Pick out those lists in myList which are such that count is greater than 2.<br>

Extracted text: 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, x2,..., xn), from the N(0, 1) distribution. 2. Calculate the mean X = E- Ti n. 3. If x > 0, then simulate n independent numbers, denoted y (y1, y2,.. ., Yn), from the exponential density with mean X. If x < 0,="" then="" simulate="" n="" independent="" numbers,="" denoted="" z="(21," 2,="" ...,="" zn),="" from="" the="" exponential="" density="" with="" mean="" -x.="" set="" y="(y1," y2,="" ...,="" yn)="-z." 4.="" calculate="" k="" which="" is="" the="" number="" of="" j="" with="" yj|=""> ]xj\. 5. Return the list of x, y and k with names xVec, yVec and count respectively. (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 x denoted {rij: i = 1,2,..., 1,000; j = 1, 2, ..., 10}; 10,000 values for y denoted {y;jii = 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.
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here